~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/services/mail/incoming.py

  • Committer: Martin Pool
  • Date: 2011-10-26 02:30:11 UTC
  • mto: This revision was merged to the branch mainline in revision 14199.
  • Revision ID: mbp@canonical.com-20111026023011-qd3cpyxy5xt115c5
Unexpected errors in pydkim are not fatal to incoming.py

Show diffs side-by-side

added added

removed removed

Lines of Context:
131
131
           signed_message['From'],
132
132
           signed_message['Sender']))
133
133
    signing_details = []
 
134
    dkim_result = False
134
135
    try:
135
 
        # NB: if this fails with a keyword argument error, you need the
136
 
        # python-dkim 0.3-3.2 that adds it
137
136
        dkim_result = dkim.verify(
138
137
            signed_message.parsed_string, dkim_log, details=signing_details)
139
138
    except dkim.DKIMException, e:
140
139
        log.warning('DKIM error: %r' % (e,))
141
 
        dkim_result = False
142
140
    except dns.resolver.NXDOMAIN, e:
143
141
        # This can easily happen just through bad input data, ie claiming to
144
142
        # be signed by a domain with no visible key of that name.  It's not an
145
143
        # operational error.
146
144
        log.info('DNS exception: %r' % (e,))
147
 
        dkim_result = False
148
145
    except dns.exception.DNSException, e:
149
146
        # many of them have lame messages, thus %r
150
147
        log.warning('DNS exception: %r' % (e,))
151
 
        dkim_result = False
152
 
    else:
153
 
        log.info('DKIM verification result=%s' % (dkim_result,))
 
148
    except Exception, e:
 
149
        # DKIM leaks some errors when it gets bad input, as in bug 881237.  We
 
150
        # don't generally want them to cause the mail to be dropped entirely
 
151
        # though.  It probably is reasonable to treat them as potential
 
152
        # operational errors, at least until they're handled properly, by
 
153
        # making pydkim itself more defensive.
 
154
        log.warning(
 
155
            'unexpected error in DKIM verification, treating as unsigned: %r'
 
156
            % (e,))
 
157
    log.info('DKIM verification result: trusted=%s' % (dkim_result,))
154
158
    log.debug('DKIM debug log: %s' % (dkim_log.getvalue(),))
155
159
    if not dkim_result:
156
160
        return None