Advertisement
Guest User

Untitled

a guest
Nov 12th, 2018
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 5.03 KB | None | 0 0
  1. diff --git a/mailpile/config/defaults.py b/mailpile/config/defaults.py
  2. index 8de28a1..e4e54a1 100644
  3. --- a/mailpile/config/defaults.py
  4. +++ b/mailpile/config/defaults.py
  5. @@ -154,6 +154,7 @@ CONFIG_RULES = {
  6.          'rescan_command':  (_('Command run before rescanning'), str,       ''),
  7.          'default_email':   (_('Default outgoing e-mail address'), 'email', ''),
  8.          'default_route':   (_('Default outgoing mail route'), str, ''),
  9. +        'msgid_domain':    (_('Default outgoing message-id domain'), str, 'mailpile'),
  10.          'line_length':     (_('Target line length, <40 disables reflow'),
  11.                              int, 65),
  12.          'always_bcc_self': (_('Always BCC self on outgoing mail'), bool, True),
  13. diff --git a/mailpile/mailutils/emails.py b/mailpile/mailutils/emails.py
  14. index 379781e..cb773d0 100644
  15. --- a/mailpile/mailutils/emails.py
  16. +++ b/mailpile/mailutils/emails.py
  17. @@ -58,12 +58,15 @@ def MakeBoundary():
  18.      return '==%s==' % okay_random(30)
  19.  
  20.  
  21. -def MakeMessageID():
  22. +def MakeMessageID(config):
  23.      # We generate a message-ID which is almost entirely random; we
  24.      # include an element of the local time (give-or-take 36 hours)
  25.      # to further reduce the odds of any collision.
  26. -    return '<%s%x@mailpile>' % (
  27. -        okay_random(40), time.time() // (3600*48))
  28. +
  29. +    domain = config.prefs.get('msgid_domain') or 'mailpile'
  30. +
  31. +    return '<%s%x@%s>' % (
  32. +        okay_random(40), time.time() // (3600*48), domain)
  33.  
  34.  
  35.  def MakeMessageDate(ts=None):
  36. @@ -407,7 +410,7 @@ class Email(object):
  37.              msg['From'] = cls.encoded_hdr(None, 'from', value=msg_from)
  38.  
  39.          msg['Date'] = MakeMessageDate(msg_ts)
  40. -        msg['Message-Id'] = msg_id or MakeMessageID()
  41. +        msg['Message-Id'] = msg_id or MakeMessageID(idx.config)
  42.          msg_subj = (msg_subject or '')
  43.          msg['Subject'] = cls.encoded_hdr(None, 'subject', value=msg_subj)
  44.  
  45. diff --git a/mailpile/plugins/compose.py b/mailpile/plugins/compose.py
  46. index 95cd53d..45fab14 100644
  47. --- a/mailpile/plugins/compose.py
  48. +++ b/mailpile/plugins/compose.py
  49. @@ -113,7 +113,7 @@ def AddComposeMethods(cls):
  50.              etype, etarg, msgid = msgid.split('-', 2)
  51.              if etarg not in ('all', 'att'):
  52.                  msgid = etarg + '-' + msgid
  53. -            msgid = '<%s>' % msgid.replace('_', '@')
  54. +            msgid = '<%s>' % self._deesc_msgid(msgid)
  55.              etype = etype.lower()
  56.  
  57.              enc_msgid = idx._encode_msg_id(msgid)
  58. @@ -142,6 +142,24 @@ def AddComposeMethods(cls):
  59.  
  60.              return Email(idx, e.msg_idx_pos)
  61.  
  62. +        def _new_msgid(self):
  63. +            return MakeMessageID(self.session.config)
  64. +
  65. +        @classmethod
  66. +        # Make a Message-ID safe for CSS/JS, escape @ and .,
  67. +        # and also _ so we can use as an escape character
  68. +        def _esc_msgid(cls, msgid):
  69. +            return (msgid.replace('_', '_0')
  70. +                    .replace('@', '_1')
  71. +                    .replace('.', '_2'))
  72. +
  73. +        @classmethod
  74. +        # Un-escape a Message-ID
  75. +        def _deesc_msgid(cls, msgid):
  76. +            return (msgid.replace('_2', '.')
  77. +                    .replace('_1', '@')
  78. +                    .replace('_0', '_'))
  79. +
  80.      return newcls
  81.  
  82.  
  83. @@ -164,11 +182,6 @@ class CompositionCommand(AddComposeMethods(Search)):
  84.      UPDATE_HEADERS = ('Subject', 'From', 'To', 'Cc', 'Bcc', 'Encryption',
  85.                        'Attach-PGP-Pubkey')
  86.  
  87. -    def _new_msgid(self):
  88. -        msgid = (MakeMessageID()
  89. -                 .replace('.', '-')   # Dots may bother JS/CSS
  90. -                 .replace('_', '-'))  # We use _ to encode the @ later on
  91. -        return msgid
  92.  
  93.      def _get_email_updates(self, idx, create=False, noneok=False, emails=None):
  94.          # Split the argument list into files and message IDs
  95. @@ -337,7 +350,7 @@ class Compose(CompositionCommand):
  96.              local_id, lmbox = session.config.open_local_mailbox(session)
  97.          else:
  98.              local_id, lmbox = -1, None
  99. -            ephemeral = ['new-E-%s-mail' % msgid[1:-1].replace('@', '_')]
  100. +            ephemeral = ['new-E-%s-mail' % cls._esc_msgid(msgid[1:-1])]
  101.          profiles = session.config.vcards.find_vcards([], kinds=['profile'])
  102.          return (Email.Create(idx, local_id, lmbox,
  103.                               save=(not ephemeral),
  104. @@ -509,7 +522,7 @@ class Reply(RelativeCompose):
  105.          else:
  106.              local_id, lmbox = -1, None
  107.              fmt = 'reply-all-%s-%s' if reply_all else 'reply-%s-%s'
  108. -            ephemeral = [fmt % (msgid[1:-1].replace('@', '_'),
  109. +            ephemeral = [fmt % (cls._esc_msgid(msgid[1:-1]),
  110.                                  refs[0].msg_mid())]
  111.  
  112.          if 'cc' in headers:
  113. @@ -635,7 +648,7 @@ class Forward(RelativeCompose):
  114.          else:
  115.              local_id, lmbox = -1, None
  116.              fmt = 'forward-att-%s-%s' if msg_atts else 'forward-%s-%s'
  117. -            ephemeral = [fmt % (msgid[1:-1].replace('@', '_'),
  118. +            ephemeral = [fmt % (cls._esc_msgid(msgid[1:-1]),
  119.                                  refs[0].msg_mid())]
  120.  
  121.          if cid:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement