def get_sent_messages(self, to=None, sender=None, subject=None, body=None, html=None): """Get a list of mail messages sent via the Mail API. Args: to: A regular expression that at least one recipient must match. sender: A regular expression that the sender must match. subject: A regular expression that the message subject must match. body: A regular expression that the text body must match. html: A regular expression that the HTML body must match. Returns: A list of matching mail.EmailMessage objects. """ messages = self._cached_messages def recipient_matches(recipient): return re.search(to, recipient) if to: messages = [m for m in messages if filter(recipient_matches, m.to_list())] if sender: messages = [m for m in messages if re.search(sender, m.sender())] if subject: messages = [m for m in messages if re.search(subject, m.subject())] if body: messages = [m for m in messages if re.search(body, m.textbody())] if html: messages = [m for m in messages if re.search(html, m.htmlbody())] mail_messages = [] for message in messages: mime_message = mail.mail_message_to_mime_message(message) email_message = mail.EmailMessage(mime_message=mime_message) mail_messages.append(email_message) return mail_messages
def get_sent_messages(self, to=None, sender=None, subject=None, body=None, html=None): """Get a list of mail messages sent via the Mail API. Args: to: A regular expression that at least one recipient must match. sender: A regular expression that the sender must match. subject: A regular expression that the message subject must match. body: A regular expression that the text body must match. html: A regular expression that the HTML body must match. Returns: A list of matching mail.EmailMessage objects. """ messages = self._cached_messages def recipient_matches(recipient): return re.search(to, recipient) if to: messages = [m for m in messages if filter(recipient_matches, m.to_list())] if sender: messages = [m for m in messages if re.search(sender, m.sender())] if subject: messages = [m for m in messages if re.search(subject, m.subject())] if body: messages = [m for m in messages if re.search(body, m.textbody())] if html: messages = [m for m in messages if re.search(html, m.htmlbody())] mail_messages = [] for message in messages: mime_message = mail.mail_message_to_mime_message(message) email_message = mail.EmailMessage(mime_message=mime_message) mail_messages.append(email_message) return mail_messages