本文整理汇总了Python中twisted.mail.smtp.rfc822date函数的典型用法代码示例。如果您正苦于以下问题:Python rfc822date函数的具体用法?Python rfc822date怎么用?Python rfc822date使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rfc822date函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: receivedHeader
def receivedHeader(self, helo, origin, recipients):
"""
Generate a received header string for a message.
@type helo: 2-L{tuple} of (L{bytes}, L{bytes})
@param helo: The client's identity as sent in the HELO command and its
IP address.
@type origin: L{Address}
@param origin: The origination address of the message.
@type recipients: L{list} of L{User}
@param recipients: The destination addresses for the message.
@rtype: L{bytes}
@return: A received header string.
"""
authStr = heloStr = b""
if self.user:
authStr = b" auth=" + self.user.encode('xtext')
if helo[0]:
heloStr = b" helo=" + helo[0]
fromUser = (b"from " + helo[0] + b" ([" + helo[1] + b"]" +
heloStr + authStr)
by = (b"by " + self.host + b" with " + self.protocolName +
b" (" + networkString(longversion) + b")")
forUser = (b"for <" + b' '.join(map(bytes, recipients)) + b"> " +
smtp.rfc822date())
return (b"Received: " + fromUser + b"\n\t" + by +
b"\n\t" + forUser)
示例2: send_plain_email
def send_plain_email(smtphost, username, password, fromEmail, toEmail, content, headers,
senderDomainName=None, port=25, requireSSL=True):
requireAuth = bool(password)
msg = MIMEText(content)
# Setup the mail headers
for (header, value) in headers.items():
msg[header] = value
headkeys = [k.lower() for k in headers.keys()]
# Add required headers if not present
if "message-id" not in headkeys:
msg["Message-ID"] = messageid()
if "date" not in headkeys:
msg["Date"] = rfc822date()
if "from" not in headkeys and "sender" not in headkeys:
msg["From"] = fromEmail
if "to" not in headkeys and "cc" not in headkeys and "bcc" not in headkeys:
msg["To"] = toEmail
# send message
f = StringIO(msg.as_string())
d = defer.Deferred()
factory = ESMTPSenderFactory(username, password, fromEmail, toEmail, f, d,
requireAuthentication=requireAuth,
requireTransportSecurity=requireSSL)
if senderDomainName is not None:
factory.domain = senderDomainName
connectTCP(smtphost, port, factory)
return d
示例3: receivedHeader
def receivedHeader(self, helo, origin, recipients):
clientHostname, _ = helo
myHostname = self.protocol.transport.getHost().host
headerValue = 'from %s by %s with ESMTP ; %s' % (clientHostname,
myHostname,
smtp.rfc822date())
return 'Received: %s' % Header(headerValue)
示例4: compose_plain_email
def compose_plain_email(fromEmail, toEmail, content, headers):
msg = MIMEText(content)
# Setup the mail headers
for (header, value) in headers.items():
msg[header] = value
msg.set_charset('utf-8')
headkeys = [k.lower() for k in headers.keys()]
# Add required headers if not present
if "message-id" not in headkeys:
msg["Message-ID"] = messageid()
if "date" not in headkeys:
msg["Date"] = rfc822date()
if "from" not in headkeys and "sender" not in headkeys:
msg["From"] = fromEmail
if "to" not in headkeys and "cc" not in headkeys and "bcc" not in headkeys:
msg["To"] = toEmail
if "reply-to" not in headkeys:
msg["Reply-To"] = SUPPORT_ADDRESS
if "user-agent" not in headkeys:
msg["User-Agent"] = USER_AGENT
return msg.as_string()
示例5: receivedHeader
def receivedHeader(self, helo, origin, recipients):
"""
Generate a received header string for a message.
@type helo: 2-L{tuple} of (L{bytes}, L{bytes})
@param helo: The client's identity as sent in the HELO command and its
IP address.
@type origin: L{Address}
@param origin: The origination address of the message.
@type recipients: L{list} of L{User}
@param recipients: The destination addresses for the message.
@rtype: L{bytes}
@return: A received header string.
"""
authStr = heloStr = ""
if self.user:
authStr = " auth=%s" % (self.user.encode('xtext'),)
if helo[0]:
heloStr = " helo=%s" % (helo[0],)
from_ = "from %s ([%s]%s%s)" % (helo[0], helo[1], heloStr, authStr)
by = "by %s with %s (%s)" % (
self.host, self.protocolName, longversion
)
for_ = "for <%s>; %s" % (' '.join(map(str, recipients)), smtp.rfc822date())
return "Received: %s\n\t%s\n\t%s" % (from_, by, for_)
示例6: receivedHeader
def receivedHeader(self, helo, orgin, recipents):
myHostname, clientIP = helo
headerValue = "by %s from %s with ESMTP; %s" % (
myHostname, clientIP, smtp.rfc822date())
retval = "Recieved: %s" % Header(headerValue)
#retval = ""
self.logger.debug("receivedHeader: helo:%s orgin:%s recipents:%s", helo, orgin, [r.dest for r in recipents] )
return retval
示例7: receivedHeader
def receivedHeader(self, helo, unused, ignored):
myHostname, self.clientIP = helo
date = smtp.rfc822date()
headerValue = 'by %s from %s with ESMTP ; %s' % (
myHostname, self.clientIP, date)
log.info('Relayed (or sent directly) from: %s', self.clientIP)
header = 'Received: %s' % Header(headerValue)
return header
示例8: receivedHeader
def receivedHeader(self, helo, origin, recipients):
authStr = heloStr = ""
if self.user:
authStr = " auth=%s" % (self.user.encode('xtext'),)
if helo[0]:
heloStr = " helo=%s" % (helo[0],)
from_ = "from %s ([%s]%s%s)" % (helo[0], helo[1], heloStr, authStr)
by = "by %s with %s (%s)" % (
self.host, self.protocolName, longversion
)
for_ = "for <%s>; %s" % (' '.join(map(str, recipients)), smtp.rfc822date())
return "Received: %s\n\t%s\n\t%s" % (from_, by, for_)
示例9: receivedHeader
def receivedHeader(self, helo, origin, recipients):
header = conf.smtp_header.format(
sender_ip = helo[1],
sender_host = helo[0],
srv_host = conf.smtp_hostname,
srv_info = conf.srv_version,
sender = conf.smtp_email_delim.join([origin.local, origin.domain]),
id = self.messageid,
rcpt = conf.smtp_email_delim.join([recipients[0].dest.local, recipients[0].dest.domain]),
date = smtp.rfc822date()
)
return 'Received: %s' % Header(header)
示例10: receivedHeader
def receivedHeader(self, helo, origin, recipients):
"""Create the ``Received:`` header for an incoming email.
:type helo: tuple
:param helo: The lines received during SMTP client HELO.
:type origin: :api:`twisted.mail.smtp.Address`
:param origin: The email address of the sender.
:type recipients: list
:param recipients: A list of :api:`twisted.mail.smtp.User` instances.
"""
cameFrom = "%s (%s [%s])" % (helo[0] or origin, helo[0], helo[1])
cameFor = ', '.join(["<{0}>".format(recp.dest) for recp in recipients])
hdr = str("Received: from %s for %s; %s"
% (cameFrom, cameFor, smtp.rfc822date()))
return hdr
示例11: receivedHeader
def receivedHeader(self, helo, origin, recipients):
"""Create the ``Received:`` header for an incoming email.
:type helo: tuple
:param helo: The lines received during SMTP client HELO.
:type origin: :api:`twisted.mail.smtp.Address`
:param origin: The email address of the sender.
:type recipients: list
:param recipients: A list of :api:`twisted.mail.smtp.User` instances.
"""
helo_ = ' helo={0}'.format(helo[0]) if helo[0] else ''
from_ = 'from %s ([%s]%s)' % (helo[0], helo[1], helo_)
by_ = 'by %s with BridgeDB (%s)' % (smtp.DNSNAME, __version__)
for_ = 'for %s; %s ' % (' '.join(map(str, recipients)), rfc822date())
return str('Received: %s\n\t%s\n\t%s' % (from_, by_, for_))
示例12: receivedHeader
def receivedHeader(self, helo, origin, recipients):
"""Generates the Received header for a message.
Specified by IMessageDelivery interface.
Args:
helo: The argument to the HELO command and the client's IP address.
origin: The address the message is from.
recipients: A list of the addresses for which this message is bound.
Returns:
The full "Received" header string.
"""
client_hostname, _ = helo
server_hostname = self.protocol.transport.getHost().host
header_value = 'from %s by %s with ESMTP ; %s' % (
client_hostname, server_hostname, smtp.rfc822date())
return 'Received: %s' % (email.Header.Header(header_value),)
示例13: writeHeaders
def writeHeaders(self, fromAddress, toAddress, subject=None,
inReplyTo=None, includeMessageID=True,
contentType='text/plain; charset="utf-8"', **kwargs):
"""Write all headers into the response email.
:param str fromAddress: The email address for the ``'From:'`` header.
:param str toAddress: The email address for the ``'To:'`` header.
:type subject: None or str
:param subject: The ``'Subject:'`` header.
:type inReplyTo: None or str
:param inReplyTo: If set, an ``'In-Reply-To:'`` header will be
generated. This should be set to the ``'Message-ID:'`` header from
the client's original request email.
:param bool includeMessageID: If ``True``, generate and include a
``'Message-ID:'`` header for the response.
:param str contentType: The ``'Content-Type:'`` header.
:kwargs: If given, the key will become the name of the header, and the
value will become the Contents of that header.
"""
self.write("From: %s" % fromAddress)
self.write("To: %s" % toAddress)
if includeMessageID:
self.write("Message-ID: %s" % smtp.messageid().encode('utf-8'))
if inReplyTo:
self.write("In-Reply-To: %s" % inReplyTo.encode('utf-8'))
self.write("Content-Type: %s" % contentType.encode('utf-8'))
self.write("Date: %s" % smtp.rfc822date().encode('utf-8'))
if not subject:
subject = '[no subject]'
if not subject.lower().startswith('re'):
subject = "Re: " + subject
self.write("Subject: %s" % subject.encode('utf-8'))
if kwargs:
for headerName, headerValue in kwargs.items():
headerName = headerName.capitalize()
headerName = headerName.replace(' ', '-')
headerName = headerName.replace('_', '-')
header = "%s: %s" % (headerName, headerValue)
self.write(header.encode('utf-8'))
# The first blank line designates that the headers have ended:
self.write(self.delimiter)
示例14: addMessage
def addMessage(self, msg, flags=None, date=None):
#print "Add Message: %s :: %s" % (msg, flags)
# passes a file handler here, need to cache fetchBodyFile so I can find the message id.
# list of uids
# uids[sequence_number] = msg_uid
# add new uid
# rpush[msg_uid]
parse = Parser()
email_obj = parse.parse(msg)
fp = StringIO()
g = Generator(fp, mangle_from_=False, maxheaderlen=60)
g.flatten(email_obj)
body = fp.getvalue()
msg_uid = self.conn.incr("%s:mailboxes:%s:uidnext" % (self.user,
self.folder)) - 1;
self.conn.zadd("%s:mailboxes:%s:uidlist"% (self.user, self.folder), msg_uid, msg_uid)
self.seqlist.append((msg_uid, ['\Recent']))
seq_number = len(self.seqlist)
if flags:
self.conn.sadd("%s:mailboxes:%s:mail:%s:flags" % (self.user, self.folder,
msg_uid), *flags)
self.conn.set("%s:mailboxes:%s:mail:%s:date" % (self.user, self.folder,
msg_uid), rfc822date())
self.conn.incr("%s:mailboxes:%s:count" % (self.user, self.folder))
self.conn.set("%s:mailboxes:%s:mail:%s:size" % (self.user, self.folder,
msg_uid), len(body))
self.conn.set("%s:mailboxes:%s:mail:%s:body" % (self.user, self.folder,
msg_uid), body)
self.conn.sadd("%s:mailboxes:%s:mail:%s:headers" % (self.user, self.folder,
msg_uid), *(email_obj.keys()))
#print email_obj.keys()
for header in email_obj.keys():
self.conn.set("%s:mailboxes:%s:mail:%s:header:%s" % (self.user,
self.folder, msg_uid, header.lower()), email_obj[header])
#print header, msg_uid, self.folder, self.user
self.conn.incr("%s:mailboxes:%s:recent" % (self.user, self.folder))
self.recent_count += 1
self.conn.publish("%s:mailboxes:%s:channel" % (self.user, self.folder),
"count %d" % (msg_uid))
return defer.succeed(seq_number)
示例15: send
def send(self, response):
message = response['reply']
response['To'] = response['target']
response['Date'] = smtp.rfc822date()
if 'Subject' not in response:
response['Subject'] = 'Message from %s' % ibid.config['botname']
response['Content-Type'] = 'text/plain; charset=utf-8'
del response['target']
del response['source']
del response['reply']
body = ''
for header, value in response.items():
body += '%s: %s\n' % (header, value)
body += '\n'
body += message
port = ':' in self.relayhost and int(self.relayhost.split(':')[1]) or 25
smtp.sendmail(self.relayhost.split(':')[0], self.address, response['To'], body.encode('utf-8'), port=port)
self.log.debug(u"Sent email to %s: %s", response['To'], response['Subject'])