コード例 #1
0
ファイル: email2trac.py プロジェクト: nyuhuhuu/trachacks
def mail2project(env, message):
    """relays an email message to a project"""

    # keep copy of original message for error handling
    original_message = email.message_from_string(message)

    # whether or not to email back on error
    email_errors = env.config.getbool('mail', 'email_errors', True)

    # lookup the message
    message = lookup(env, message)

    # get the handlers
    handlers = ExtensionPoint(IEmailHandler).extensions(env)
    _handlers = env.config.getlist('mail', 'handlers')
    if not _handlers: # default value
        _handlers = [ 'RemoveQuotes', 'ReplyToTicket', 'EmailToTicket' ]
    handler_dict = dict([(h.__class__.__name__, h)
                             for h in handlers])
    handlers = [handler_dict[h] for h in _handlers
                if h in handler_dict ]

    # handle the message
    warnings = []
    for handler in handlers:
        if not handler.match(message):
            continue
        try:
            message = handler.invoke(message, warnings)
        except EmailException, e:
            # handle the error
            if email_errors and original_message['from']:
                subject = reply_subject(original_message['subject'])
                response = 'Subject: %s\n\n%s' % (subject, reply_body(str(e), original_message))
                send_email(env, 
                           original_message['to'],
                           [ original_message['from'] ],
                           response
                           )
                warnings = [] # clear warnings
                return
            else:
                raise

        # if the message is consumed, quit processing
        if not message:
            break
コード例 #2
0
ファイル: email2trac.py プロジェクト: pombredanne/trachacks
def mail2project(env, message):
    """relays an email message to a project"""

    # keep copy of original message for error handling
    original_message = email.message_from_string(message)

    # whether or not to email back on error
    email_errors = env.config.getbool('mail', 'email_errors', True)

    # lookup the message
    message = lookup(env, message)

    # get the handlers
    handlers = ExtensionPoint(IEmailHandler).extensions(env)
    _handlers = env.config.getlist('mail', 'handlers')
    if not _handlers:  # default value
        _handlers = ['RemoveQuotes', 'ReplyToTicket', 'EmailToTicket']
    handler_dict = dict([(h.__class__.__name__, h) for h in handlers])
    handlers = [handler_dict[h] for h in _handlers if h in handler_dict]

    # handle the message
    warnings = []
    for handler in handlers:
        if not handler.match(message):
            continue
        try:
            message = handler.invoke(message, warnings)
        except EmailException, e:
            # handle the error
            if email_errors and original_message['from']:
                subject = reply_subject(original_message['subject'])
                response = 'Subject: %s\n\n%s' % (
                    subject, reply_body(str(e), original_message))
                send_email(env, original_message['to'],
                           [original_message['from']], response)
                warnings = []  # clear warnings
                return
            else:
                raise

        # if the message is consumed, quit processing
        if not message:
            break
コード例 #3
0
ファイル: email2trac.py プロジェクト: nyuhuhuu/trachacks
    if warnings:

        # format warning message
        if len(warnings) == 1:
            body = warnings[0]
            pass
        else:
            body = "\n\n".join(["* %s" % warning.strip() 
                                for warning in warnings])
        
        # notify the sender
        subject = reply_subject(original_message['subject'])
        response = 'Subject: %s\n\n%s' % (subject, reply_body(body, original_message))
        send_email(env, 
                   original_message['to'],
                   [ original_message['from'] ],
                   response
                   )

### command line handler

def main(args=sys.argv[1:]):

    # parse the options
    from optparse import OptionParser
    parser = OptionParser()
    parser.add_option('-p', '--project', '--projects', 
                      dest='projects', action='append', 
                      default=[], 
                      help='projects to apply to',)
    parser.add_option('-f', '--file', dest='file',
コード例 #4
0
ファイル: email2trac.py プロジェクト: pombredanne/trachacks
    # email warnings
    if warnings:

        # format warning message
        if len(warnings) == 1:
            body = warnings[0]
            pass
        else:
            body = "\n\n".join(
                ["* %s" % warning.strip() for warning in warnings])

        # notify the sender
        subject = reply_subject(original_message['subject'])
        response = 'Subject: %s\n\n%s' % (subject,
                                          reply_body(body, original_message))
        send_email(env, original_message['to'], [original_message['from']],
                   response)


### command line handler


def main(args=sys.argv[1:]):

    # parse the options
    from optparse import OptionParser
    parser = OptionParser()
    parser.add_option(
        '-p',
        '--project',
        '--projects',
        dest='projects',