First of all, Postfix mail routing rules can be very complex, and the preferred solution seems to include a lot of hype in the wrong places. You donβt want to accidentally show someone elseβs emails to someone, do you? Secondly, although Postfix can do almost everything, it should not, because it is only an MDA (mail delivery agent).
Your solution is best solved using a POP3 or IMAP server (Cyrus IMAPd, Courier, etc.). IMAP servers can have "superuser accounts" that can read messages from all users. Then your web application can connect to the users mailbox and return headers and bodys.
If you want to show only the subject line, you can get them with a special IMAP command and very low overhead. However, Pythonβs IMAP library is not the easiest way to understand the API. I will take a snapshot (not verified!) With an example taken from the standard library:
import imaplib sess = imaplib.IMAP4() sess.login('superuser', 'password') # Honor the mailbox syntax of your server! sess.select('INBOX/Luke') # Or something similar. typ, data = sess.search(None, 'ALL') # All Messages. subjectlines = [] for num in data[0].split(): typ, msgdata = sess.fetch(num, '(RFC822.SIZE BODY[HEADER.FIELDS (SUBJECT)])') subject = msgdata[0][1].lstrip('Subject: ').strip() subjectlines.append(subject)
This log is registered on the IMAP server, selects the users mailbox, retrieves all message identifiers, and then extracts (I hope) only storylines and adds the data to the list of thematic sections.
To get other parts of mail, change the line using sess.fetch. For specific fetch syntax, see RFC 2060 (Section 6.4.5).
Good luck
source share