本文整理汇总了Python中email.Utils.make_msgid方法的典型用法代码示例。如果您正苦于以下问题:Python Utils.make_msgid方法的具体用法?Python Utils.make_msgid怎么用?Python Utils.make_msgid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类email.Utils
的用法示例。
在下文中一共展示了Utils.make_msgid方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from email import Utils [as 别名]
# 或者: from email.Utils import make_msgid [as 别名]
def __init__(self, environment, refname, short_refname, old, new, rev):
Change.__init__(self, environment)
self.change_type = {
(False, True): "create",
(True, True): "update",
(True, False): "delete",
}[bool(old), bool(new)]
self.refname = refname
self.short_refname = short_refname
self.old = old
self.new = new
self.rev = rev
self.msgid = make_msgid()
self.diffopts = environment.diffopts
self.graphopts = environment.graphopts
self.logopts = environment.logopts
self.commitlogopts = environment.commitlogopts
self.showgraph = environment.refchange_showgraph
self.showlog = environment.refchange_showlog
self.header_template = REFCHANGE_HEADER_TEMPLATE
self.intro_template = REFCHANGE_INTRO_TEMPLATE
self.footer_template = FOOTER_TEMPLATE
示例2: test_make_msgid_collisions
# 需要导入模块: from email import Utils [as 别名]
# 或者: from email.Utils import make_msgid [as 别名]
def test_make_msgid_collisions(self):
# Test make_msgid uniqueness, even with multiple threads
class MsgidsThread(Thread):
def run(self):
# generate msgids for 3 seconds
self.msgids = []
append = self.msgids.append
make_msgid = Utils.make_msgid
clock = time.time
tfin = clock() + 3.0
while clock() < tfin:
append(make_msgid())
threads = [MsgidsThread() for i in range(5)]
with start_threads(threads):
pass
all_ids = sum([t.msgids for t in threads], [])
self.assertEqual(len(set(all_ids)), len(all_ids))
示例3: test_make_msgid_collisions
# 需要导入模块: from email import Utils [as 别名]
# 或者: from email.Utils import make_msgid [as 别名]
def test_make_msgid_collisions(self):
# Test make_msgid uniqueness, even with multiple threads
class MsgidsThread(Thread):
def run(self):
# generate msgids for 3 seconds
self.msgids = []
append = self.msgids.append
make_msgid = Utils.make_msgid
clock = time.clock
tfin = clock() + 3.0
while clock() < tfin:
append(make_msgid())
threads = [MsgidsThread() for i in range(5)]
with start_threads(threads):
pass
all_ids = sum([t.msgids for t in threads], [])
self.assertEqual(len(set(all_ids)), len(all_ids))
示例4: mail_headers
# 需要导入模块: from email import Utils [as 别名]
# 或者: from email.Utils import make_msgid [as 别名]
def mail_headers(self, group, params):
from email import Utils
subject = self.make_subject(group, params)
try:
subject.encode('ascii')
except UnicodeError:
from email.Header import Header
subject = Header(subject, 'utf-8').encode()
hdrs = 'From: %s\n' \
'To: %s\n' \
'Subject: %s\n' \
'Date: %s\n' \
'Message-ID: %s\n' \
'MIME-Version: 1.0\n' \
'Content-Type: text/plain; charset=UTF-8\n' \
'Content-Transfer-Encoding: 8bit\n' \
'X-Svn-Commit-Project: %s\n' \
'X-Svn-Commit-Author: %s\n' \
'X-Svn-Commit-Revision: %d\n' \
'X-Svn-Commit-Repository: %s\n' \
% (self.from_addr, ', '.join(self.to_addrs), subject,
Utils.formatdate(), Utils.make_msgid(), group,
self.repos.author or 'no_author', self.repos.rev,
os.path.basename(self.repos.repos_dir))
if self.reply_to:
hdrs = '%sReply-To: %s\n' % (hdrs, self.reply_to)
return hdrs + '\n'
示例5: send_mail
# 需要导入模块: from email import Utils [as 别名]
# 或者: from email.Utils import make_msgid [as 别名]
def send_mail(sender, receiver, subject, content, ctype="html", pics=()):
"""subject and body are unicode objects"""
if not sender:
sender = current_app.config.get("DEFAULT_MAIL_SENDER")
smtp_server = current_app.config.get("MAIL_SERVER")
if ctype == "html":
msg = MIMEText(content, 'html', 'utf-8')
else:
msg = MIMEText(content, 'plain', 'utf-8')
if len(pics) != 0:
msg_root = MIMEMultipart('related')
msg_text = MIMEText(content, 'html', 'utf-8')
msg_root.attach(msg_text)
i = 1
for pic in pics:
fp = open(pic, "rb")
image = MIMEImage(fp.read())
fp.close()
image.add_header('Content-ID', '<img%02d>' % i)
msg_root.attach(image)
i += 1
msg = msg_root
msg['Subject'] = Header(subject, 'utf-8')
msg['From'] = sender
msg['To'] = ';'.join(receiver)
msg['Message-ID'] = Utils.make_msgid()
msg['date'] = time.strftime('%a, %d %b %Y %H:%M:%S %z')
smtp = smtplib.SMTP()
smtp.connect(smtp_server, 25)
username, password = current_app.config.get("MAIL_USERNAME"), current_app.config.get("MAIL_PASSWORD")
if username and password:
smtp.login(username, password)
smtp.sendmail(sender, receiver, msg.as_string())
smtp.quit()