Example #1
0
def generate_mbox(messages, full_tags):
    mbox_dir = config.get_mbox_path()
    mid = escape_message_id(messages[0][0].get_message_id())

    tmp_mbox_path = "%s/tmp-%s" % (mbox_dir, mid)
    mbox_path = "%s/mbox-%s" % (mbox_dir, mid)

    mbox = mailbox.mbox(tmp_mbox_path, create=True)
    for message, tags in messages:
        new_payload = add_tags(message, merge_tags(full_tags, tags))

        msg = message.get_message_parts()[0]

        # Drop content transfer encoding so msg.set_payload() will re-encode
        if "content-transfer-encoding" in msg:
            del msg["content-transfer-encoding"]

        # Change charset to UTF-8 to guarantee that we can represent all
        # characters.  Think about the case where the patch email was ASCII and
        # a reviewer with a non-ASCII name replied with a Reviewed-by tag, now
        # the patch can no longer be represented by ASCII.
        msg.set_payload(new_payload.encode("utf-8"), "utf-8")
        mbox.add(msg)
    mbox.flush()
    mbox.close()

    os.rename(tmp_mbox_path, mbox_path)

    return config.get_mbox_prefix() + ("mbox-%s" % mid)
Example #2
0
def generate_mbox(messages, full_tags):
    mbox_dir = config.get_mbox_path()
    mid = escape_message_id(messages[0][0].get_message_id())

    tmp_mbox_path = '%s/tmp-%s' % (mbox_dir, mid)
    mbox_path = '%s/mbox-%s' % (mbox_dir, mid)

    mbox = mailbox.mbox(tmp_mbox_path, create=True)
    for message, tags in messages:
        new_payload = add_tags(message, merge_tags(full_tags, tags))

        msg = message.get_message_parts()[0]

        # Drop content transfer encoding so msg.set_payload() will re-encode
        if 'content-transfer-encoding' in msg:
            del msg['content-transfer-encoding']

        # Change charset to UTF-8 to guarantee that we can represent all
        # characters.  Think about the case where the patch email was ASCII and
        # a reviewer with a non-ASCII name replied with a Reviewed-by tag, now
        # the patch can no longer be represented by ASCII.
        msg.set_payload(new_payload.encode('utf-8'), 'utf-8')
        mbox.add(msg)
    mbox.flush()
    mbox.close()

    os.rename(tmp_mbox_path, mbox_path)

    return config.get_mbox_prefix() + ('mbox-%s' % mid)
Example #3
0
def try_to_send(args, notified_dir, sender, message, payload):
    mid = escape_message_id(message['message-id'])
    if os.access(notified_dir + '/mid/' + mid, os.F_OK):
        return

    msg = email.message.Message()

    receipents = [ message['from'] ]
    receipents += message['to']
    receipents += message['cc']
    receipents = map(format_addr, receipents)

    msg['From'] = sender
    msg['Subject'] = 'Re: %s' % message['subject']
    msg['Cc'] = encode_address_list(message['cc'])
    msg['To'] = encode_address_list([ message['from'] ] + message['to'])
    msg['In-Reply-To'] = '<%s>' % message['message-id']
    msg['Date'] = email.utils.formatdate()

    lines = payload.split('\n')
    if len(lines) > 1024:
        lines = lines[0:1024] + ['[Output truncated]']
    payload = '\n'.join(lines)
    msg.set_payload(payload.encode('ascii', errors='replace'))

    txt_msg = msg.as_string().encode('ascii', errors='replace')

    if not args.dry_run and not args.fake:
        sent = False
        for i in range(10):
            try:
                s = smtplib.SMTP(config.get_smtp_server())
                s.sendmail(sender, receipents, txt_msg)
                s.quit()
                sent = True
                break
            except:
                time.sleep(1)

        if not sent:
            raise

    if not args.dry_run:
        f = open(notified_dir + '/mid/' + mid, 'w')
        f.flush()
        f.close()

    print txt_msg
    print '-' * 80
Example #4
0
def try_to_send(args, notified_dir, sender, message, payload):
    mid = escape_message_id(message['message-id'])
    if os.access(notified_dir + '/mid/' + mid, os.F_OK):
        return

    msg = email.message.Message()

    receipents = [message['from']]
    receipents += message['to']
    receipents += message['cc']
    receipents = map(format_addr, receipents)

    msg['From'] = sender
    msg['Subject'] = 'Re: %s' % message['subject']
    msg['Cc'] = encode_address_list(message['cc'])
    msg['To'] = encode_address_list([message['from']] + message['to'])
    msg['In-Reply-To'] = '<%s>' % message['message-id']
    msg['Date'] = email.utils.formatdate()

    lines = payload.split('\n')
    if len(lines) > 1024:
        lines = lines[0:1024] + ['[Output truncated]']
    payload = '\n'.join(lines)
    msg.set_payload(payload.encode('ascii', errors='replace'))

    txt_msg = msg.as_string().encode('ascii', errors='replace')

    if not args.dry_run and not args.fake:
        sent = False
        for i in range(10):
            try:
                s = smtplib.SMTP(config.get_smtp_server())
                s.sendmail(sender, receipents, txt_msg)
                s.quit()
                sent = True
                break
            except:
                time.sleep(1)

        if not sent:
            raise

    if not args.dry_run:
        f = open(notified_dir + '/mid/' + mid, 'w')
        f.flush()
        f.close()

    print txt_msg
    print '-' * 80