l.s.m.incoming : module documentation

Part of lp.services.mail

Functions dealing with mails coming into Launchpad.
Function canonicalise_line_endings Canonicalise the line endings to 'rn'.
Class InvalidSignature The signature failed to validate.
Class InactiveAccount The account for the person sending this email is inactive.
Function authenticateEmail Authenticates an email by verifying the PGP signature.
Function extract_addresses Extract the domain the mail was sent to.
Function report_oops Record an OOPS for the current exception and return the OOPS ID.
Function handleMail Undocumented
Function handle_one_mail Process one message.
Function _isDkimDomainTrusted Undocumented
Function _verifyDkimOrigin Find a From or Sender address for which there's a DKIM signature.
Function _getPrincipalByDkim Determine the security principal from DKIM, if possible.
Function _gpgAuthenticateEmail Check GPG signature.
Function _send_email_oops Handle an error that generates an oops.
def canonicalise_line_endings(text):

Canonicalise the line endings to 'rn'.

>>> canonicalise_line_endings('\n\nfoo\nbar\rbaz\r\n')
'\r\n\r\nfoo\r\nbar\r\nbaz\r\n'
>>> canonicalise_line_endings('\r\rfoo\r\nbar\rbaz\n')
'\r\n\r\nfoo\r\nbar\r\nbaz\r\n'
>>> canonicalise_line_endings('\r\nfoo\r\nbar\nbaz\r')
'\r\nfoo\r\nbar\r\nbaz\r\n'
def _isDkimDomainTrusted(domain):
Undocumented
def _verifyDkimOrigin(signed_message):
Find a From or Sender address for which there's a DKIM signature.

:returns: A string email address for the trusted sender, if there is one,
otherwise None.

:param signed_message: ISignedMessage
def _getPrincipalByDkim(mail):

Determine the security principal from DKIM, if possible.

To qualify:
  • there must be a dkim signature from a trusted domain
  • the From or Sender must be in that domain
  • the address in this header must be verified for a person
Returns(None, None), or (principal, trusted_addr).
def authenticateEmail(mail, signature_timestamp_checker=None):
Authenticates an email by verifying the PGP signature.

The mail is expected to be an ISignedMessage.

If this completes, it will set the current security principal to be the message sender.

Parameterssignature_timestamp_checkerThis callable is passed the message signature timestamp, and it can raise an exception if it dislikes it (for example as a replay attack.) This parameter is intended for use in tests. If None, ensure_sane_signature_timestamp is used.
def _gpgAuthenticateEmail(mail, principal, person, signature_timestamp_checker):
Check GPG signature.
ParametersprincipalClaimed sender of the mail; to be checked against the actual signature.
Returnsprincipal, either strongly or weakly authenticated.
def extract_addresses(mail, file_alias_url, log):
Extract the domain the mail was sent to.

Mails sent to Launchpad should have an X-Launchpad-Original-To header. This is added by the MTA before it ends up the mailbox for Launchpad.

def report_oops(file_alias_url=None, error_msg=None):
Record an OOPS for the current exception and return the OOPS ID.
def handleMail(trans=transaction, signature_timestamp_checker=None):
Undocumented
def _send_email_oops(trans, log, mail, error_msg, file_alias_url):

Handle an error that generates an oops.

It does the following:
  • records an OOPS with error_msg and file_alias_url

  • commits the current transaction to ensure that the

    message gets sent

def handle_one_mail(log, mail, file_alias, file_alias_url, signature_timestamp_checker):
Process one message.

Returns None when the message has either been successfully processed, or handled as a known error condition, in which case a reply will have been sent if appropriate.

API Documentation for Launchpad, generated by pydoctor at 2018-08-18 00:00:04.