示例#1
0
def test_attach_text():
    mail = encoding.MailBase()
    mail.attach_text("This is some text.", 'text/plain')

    msg = encoding.to_message(mail)
    assert msg.get_payload(0).get_payload() == "This is some text."
    assert encoding.to_string(mail)

    mail.attach_text("<html><body><p>Hi there.</p></body></html>", "text/html")
    msg = encoding.to_message(mail)
    assert len(msg.get_payload()) == 2
    assert encoding.to_string(mail)
示例#2
0
def test_attach_text():
    mail = encoding.MailBase()
    mail.attach_text("This is some text.", 'text/plain')

    msg = encoding.to_message(mail)
    assert_equal(msg.get_payload(0).get_payload(), "This is some text.")
    assert encoding.to_string(mail)

    mail.attach_text("<html><body><p>Hi there.</p></body></html>", "text/html")
    msg = encoding.to_message(mail)
    assert_equal(len(msg.get_payload()), 2)
    assert encoding.to_string(mail)
示例#3
0
def cleanse(inbox, outbox):
    """
    Uses Salmon mail cleansing and canonicalization system to take an
    input Maildir (or mbox) and replicate the email over into another
    Maildir.  It's used mostly for testing and cleaning.
    """
    error_count = 0

    try:
        inbox = mailbox.mbox(inbox)
    except IOError:
        inbox = mailbox.Maildir(inbox, factory=None)

    outbox = mailbox.Maildir(outbox)

    for msg in inbox:
        try:
            mail = encoding.from_message(msg)
            outbox.add(encoding.to_string(mail))
        except encoding.EncodingError as exc:
            click.echo("ERROR: %s" % exc)
            error_count += 1

    outbox.close()
    inbox.close()

    if error_count > 0:
        raise SalmonCommandError("TOTAL ERRORS: %s" % error_count)
    else:
        click.echo("Completed without errors")
示例#4
0
def test_odd_content_type_with_charset():
    mail = encoding.MailBase()
    mail.body = u"p\xf6stal".encode('utf-8')
    mail.content_encoding['Content-Type'] = ('application/plain', {'charset': 'utf-8'})

    msg = encoding.to_string(mail)
    assert msg
示例#5
0
def test_odd_content_type_with_charset():
    mail = encoding.MailBase()
    mail.body = u"p\xf6stal".encode('utf-8')
    mail.content_encoding['Content-Type'] = ('application/plain', {'charset': 'utf-8'})

    msg = encoding.to_string(mail)
    assert msg
示例#6
0
def test_odd_content_type_with_charset():
    mail = encoding.MailBase()
    mail.body = u"p\xf6stal".encode("utf-8")
    mail.content_encoding["Content-Type"] = ("application/plain", {"charset": "utf-8"})

    msg = encoding.to_string(mail)
    assert msg
示例#7
0
def mail_to_you_is_bouncing(message):
    reason = message.bounce.error_for_humans()

    msg = view.respond(locals(), 'mail/you_bounced.msg',
                       From='*****@*****.**',
                       To=message.bounce.original['to'],
                       Subject="Email to you is bouncing.")

    if message.bounce.report:
        for report in message.bounce.report:
            msg.attach('bounce_report.msg', content_type='text/plain', data=encoding.to_string(report),
                       disposition='attachment')

    if message.bounce.notification:
        msg.attach('notification_report.msg', content_type='text/plain',
                   data=encoding.to_string(message.bounce.notification),
                   disposition='attachment')

    return msg
示例#8
0
    def command(input, output):
        error_count = 0

        try:
            inbox = mailbox.mbox(input)
        except IOError:
            inbox = mailbox.Maildir(input, factory=None)

        outbox = mailbox.Maildir(output)

        for msg in inbox:
            try:
                mail = encoding.from_message(msg)
                outbox.add(encoding.to_string(mail))
            except encoding.EncodingError, exc:
                print "ERROR: ", exc
                error_count += 1
示例#9
0
    def command(input, output):
        error_count = 0

        try:
            inbox = mailbox.mbox(input)
        except IOError:
            inbox = mailbox.Maildir(input, factory=None)

        outbox = mailbox.Maildir(output)

        for msg in inbox:
            try:
                mail = encoding.from_message(msg)
                outbox.add(encoding.to_string(mail))
            except encoding.EncodingError, exc:
                print "ERROR: ", exc
                error_count += 1
示例#10
0
    def command(input, output):
        error_count = 0

        try:
            inbox = mailbox.mbox(input)
        except IOError:
            inbox = mailbox.Maildir(input, factory=None)

        outbox = mailbox.Maildir(output)

        for msg in inbox:
            try:
                mail = encoding.from_message(msg)
                outbox.add(encoding.to_string(mail))
            except encoding.EncodingError as exc:
                print("ERROR: %s" % exc)
                error_count += 1

        outbox.close()
        inbox.close()

        print("TOTAL ERRORS: %s" % error_count)
示例#11
0
文件: commands.py 项目: hovel/salmon
def cleanse_command(input=None, output=None):
    """
    Uses Salmon mail cleansing and canonicalization system to take an
    input maildir (or mbox) and replicate the email over into another
    maildir.  It's used mostly for testing and cleaning.
    """
    error_count = 0

    try:
        inbox = mailbox.mbox(input)
    except IOError:
        inbox = mailbox.Maildir(input, factory=None)

    outbox = mailbox.Maildir(output)

    for msg in inbox:
        try:
            mail = encoding.from_message(msg)
            outbox.add(encoding.to_string(mail))
        except encoding.EncodingError, exc:
            print "ERROR: ", exc
            error_count += 1
示例#12
0
def cleanse_command(input=None, output=None):
    """
    Uses Salmon mail cleansing and canonicalization system to take an
    input maildir (or mbox) and replicate the email over into another
    maildir.  It's used mostly for testing and cleaning.
    """
    error_count = 0

    try:
        inbox = mailbox.mbox(input)
    except IOError:
        inbox = mailbox.Maildir(input, factory=None)

    outbox = mailbox.Maildir(output)

    for msg in inbox:
        try:
            mail = encoding.from_message(msg)
            outbox.add(encoding.to_string(mail))
        except encoding.EncodingError, exc:
            print "ERROR: ", exc
            error_count += 1
示例#13
0
    def command(input, output):
        error_count = 0

        try:
            inbox = mailbox.mbox(input)
        except IOError:
            inbox = mailbox.Maildir(input, factory=None)

        outbox = mailbox.Maildir(output)

        for msg in inbox:
            try:
                mail = encoding.from_message(msg)
                outbox.add(encoding.to_string(mail))
            except encoding.EncodingError as exc:
                print("ERROR: %s" % exc)
                error_count += 1

        outbox.close()
        inbox.close()

        print("TOTAL ERRORS: %s" % error_count)
示例#14
0
 def __str__(self):
     """
     Converts this to a string usable for storage into a queue or 
     transmission.
     """
     return encoding.to_string(self.Email)
示例#15
0
 def __str__(self):
     """
     Converts this to a string usable for storage into a queue or 
     transmission.
     """
     return encoding.to_string(self.base)