__ __ __ __ _____ _ _ _____ _ _ _ | \/ | \ \ / / | __ \ (_) | | / ____| | | | | | \ / |_ __\ V / | |__) | __ ___ ____ _| |_ ___ | (___ | |__ ___| | | | |\/| | '__|> < | ___/ '__| \ \ / / _` | __/ _ \ \___ \| '_ \ / _ \ | | | | | | |_ / . \ | | | | | |\ V / (_| | || __/ ____) | | | | __/ | | |_| |_|_(_)_/ \_\ |_| |_| |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1 if you need WebShell for Seo everyday contact me on Telegram Telegram Address : @jackleetFor_More_Tools:
# -*- test-case-name: twisted.mail.test.test_bounce -*-
#
# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.
"""
Support for bounce message generation.
"""
import email.utils
import os
import time
from io import SEEK_END, SEEK_SET, StringIO
from twisted.mail import smtp
BOUNCE_FORMAT = """\
From: postmaster@{failedDomain}
To: {failedFrom}
Subject: Returned Mail: see transcript for details
Message-ID: {messageID}
Content-Type: multipart/report; report-type=delivery-status;
boundary="{boundary}"
--{boundary}
{transcript}
--{boundary}
Content-Type: message/delivery-status
Arrival-Date: {ctime}
Final-Recipient: RFC822; {failedTo}
"""
def generateBounce(message, failedFrom, failedTo, transcript="", encoding="utf-8"):
"""
Generate a bounce message for an undeliverable email message.
@type message: a file-like object
@param message: The undeliverable message.
@type failedFrom: L{bytes} or L{unicode}
@param failedFrom: The originator of the undeliverable message.
@type failedTo: L{bytes} or L{unicode}
@param failedTo: The destination of the undeliverable message.
@type transcript: L{bytes} or L{unicode}
@param transcript: An error message to include in the bounce message.
@type encoding: L{str} or L{unicode}
@param encoding: Encoding to use, default: utf-8
@rtype: 3-L{tuple} of (E{1}) L{bytes}, (E{2}) L{bytes}, (E{3}) L{bytes}
@return: The originator, the destination and the contents of the bounce
message. The destination of the bounce message is the originator of
the undeliverable message.
"""
if isinstance(failedFrom, bytes):
failedFrom = failedFrom.decode(encoding)
if isinstance(failedTo, bytes):
failedTo = failedTo.decode(encoding)
if not transcript:
transcript = """\
I'm sorry, the following address has permanent errors: {failedTo}.
I've given up, and I will not retry the message again.
""".format(
failedTo=failedTo
)
failedAddress = email.utils.parseaddr(failedTo)[1]
data = {
"boundary": "{}_{}_{}".format(time.time(), os.getpid(), "XXXXX"),
"ctime": time.ctime(time.time()),
"failedAddress": failedAddress,
"failedDomain": failedAddress.split("@", 1)[1],
"failedFrom": failedFrom,
"failedTo": failedTo,
"messageID": smtp.messageid(uniq="bounce"),
"message": message,
"transcript": transcript,
}
fp = StringIO()
fp.write(BOUNCE_FORMAT.format(**data))
orig = message.tell()
message.seek(0, SEEK_END)
sz = message.tell()
message.seek(orig, SEEK_SET)
if sz > 10000:
while 1:
line = message.readline()
if isinstance(line, bytes):
line = line.decode(encoding)
if len(line) <= 0:
break
fp.write(line)
else:
messageContent = message.read()
if isinstance(messageContent, bytes):
messageContent = messageContent.decode(encoding)
fp.write(messageContent)
return b"", failedFrom.encode(encoding), fp.getvalue().encode(encoding)
| Name | Type | Size | Permission | Actions |
|---|---|---|---|---|
| __pycache__ | Folder | 0755 |
|
|
| newsfragments | Folder | 0755 |
|
|
| scripts | Folder | 0755 |
|
|
| test | Folder | 0755 |
|
|
| __init__.py | File | 142 B | 0644 |
|
| _cred.py | File | 2.68 KB | 0644 |
|
| _except.py | File | 8.49 KB | 0644 |
|
| _pop3client.py | File | 45.64 KB | 0644 |
|
| alias.py | File | 23.43 KB | 0644 |
|
| bounce.py | File | 3.1 KB | 0644 |
|
| imap4.py | File | 206.47 KB | 0644 |
|
| interfaces.py | File | 31.32 KB | 0644 |
|
| mail.py | File | 20.09 KB | 0644 |
|
| maildir.py | File | 27.07 KB | 0644 |
|
| pb.py | File | 3.62 KB | 0644 |
|
| pop3.py | File | 53.6 KB | 0644 |
|
| pop3client.py | File | 487 B | 0644 |
|
| protocols.py | File | 12.04 KB | 0644 |
|
| relay.py | File | 5.14 KB | 0644 |
|
| relaymanager.py | File | 37.6 KB | 0644 |
|
| smtp.py | File | 70.6 KB | 0644 |
|
| tap.py | File | 12.5 KB | 0644 |
|