Mercurial > p > roundup > code
comparison roundup/mailgw.py @ 5488:52cb53eedf77
reworked random number use
prefer secrets module from Python 3.6+, random.SystemRandom and finally plain random
| author | Christof Meerwald <cmeerw@cmeerw.org> |
|---|---|
| date | Sat, 04 Aug 2018 22:40:16 +0100 |
| parents | 1c9a7310e4f0 |
| children | 725266c03eab |
comparison
equal
deleted
inserted
replaced
| 5487:ce171c81d823 | 5488:52cb53eedf77 |
|---|---|
| 93 explanatory message given in the exception. | 93 explanatory message given in the exception. |
| 94 """ | 94 """ |
| 95 from __future__ import print_function | 95 from __future__ import print_function |
| 96 __docformat__ = 'restructuredtext' | 96 __docformat__ = 'restructuredtext' |
| 97 | 97 |
| 98 import re, os, smtplib, socket, binascii, quopri | 98 import base64, re, os, smtplib, socket, binascii, quopri |
| 99 import time, random, sys, logging | 99 import time, sys, logging |
| 100 import codecs | 100 import codecs |
| 101 import traceback | 101 import traceback |
| 102 import email.utils | 102 import email.utils |
| 103 | 103 |
| 104 from .anypy.email_ import decode_header | 104 from .anypy.email_ import decode_header |
| 106 | 106 |
| 107 from roundup import configuration, hyperdb, date, password, exceptions | 107 from roundup import configuration, hyperdb, date, password, exceptions |
| 108 from roundup.mailer import Mailer, MessageSendError | 108 from roundup.mailer import Mailer, MessageSendError |
| 109 from roundup.i18n import _ | 109 from roundup.i18n import _ |
| 110 from roundup.hyperdb import iter_roles | 110 from roundup.hyperdb import iter_roles |
| 111 from roundup.anypy.strings import StringIO | 111 from roundup.anypy.strings import b2s, StringIO |
| 112 import roundup.anypy.random_ as random_ | |
| 112 | 113 |
| 113 try: | 114 try: |
| 114 import pyme, pyme.core, pyme.constants, pyme.constants.sigsum | 115 import pyme, pyme.core, pyme.constants, pyme.constants.sigsum |
| 115 except ImportError: | 116 except ImportError: |
| 116 pyme = None | 117 pyme = None |
| 1161 # Get the message ids | 1162 # Get the message ids |
| 1162 inreplyto = self.message.getheader('in-reply-to') or '' | 1163 inreplyto = self.message.getheader('in-reply-to') or '' |
| 1163 messageid = self.message.getheader('message-id') | 1164 messageid = self.message.getheader('message-id') |
| 1164 # generate a messageid if there isn't one | 1165 # generate a messageid if there isn't one |
| 1165 if not messageid: | 1166 if not messageid: |
| 1166 messageid = "<%s.%s.%s%s@%s>"%(time.time(), random.random(), | 1167 messageid = "<%s.%s.%s%s@%s>"%(time.time(), |
| 1168 b2s(base64.b32encode(random_.token_bytes(10))), | |
| 1167 self.classname, self.nodeid, self.config['MAIL_DOMAIN']) | 1169 self.classname, self.nodeid, self.config['MAIL_DOMAIN']) |
| 1168 | 1170 |
| 1169 if self.content is None: | 1171 if self.content is None: |
| 1170 raise MailUsageError(_(""" | 1172 raise MailUsageError(_(""" |
| 1171 Roundup requires the submission to be plain text. The message parser could | 1173 Roundup requires the submission to be plain text. The message parser could |
