Question

I want to process incoming forwarded emails received by procmail to grab the subject and recipient of the forwarded (child) email.

For example:

  • UserA receives an email from UserB
  • UserA forwards that email to the email server
  • email server receives the email and extracts UserB's email address

Is there an approach or recipe that performs this task? Or do I have to regex my way through the body of the main email?

EDIT:

By request, I will offer boundary conditions. Email clients of the 'UserA group' are Gmail and Outlook. All users sending in English. The 'UserB' is an automated agent under my control.

One of my servers ('User B') sends automated emails to my users ('UserA') who are supposed to forward the email to a second server for processing (to confirm they received the automated email).

I assume, then, that there are no consistent headers for forwarding and that I am needing to regex my way through the email to extract the data I need.

Was it helpful?

Solution

(This isn't really a proper answer, but I cannot use formatting in comments, so here goes.)

Depends on what you mean by "forwards". If you mean "uses the 'Forward' button in a sane email client" it could come out as an attachment (possibly with a content-transfer-encoding which needs to be decoded in order to access it) or an in-line copy of the original message as a textual body; or if you mean "uses the 'Forward' button in a broken email client, such as anything from Mordor Redmond" there are a number of possible additional complications. Technically, some clients might also "forward" by adding a "Resent-to:" header and otherwise just resending the original message verbatim. Or in some modern clients, you could drag the message over into the composition pane of a new empty message, and make it appear as an attachment to the new message, possibly with user control of the containing message's content-type and encoding, and the attachment's.

Assuming you end up with something like the following ...

From: UserA <usera@such.example.com>
To: server@example.net
Subject: VB: Hi

Hey, here is a message I received.

-- User A

---- Ursprungligt meddelande ----
Från: UserB [mailto:userb@elsewhere.example.org]
Till: UserA
Ämne: Hi
Datum: perjantai 13. lokakuuta 2012 23:45

Here is the original message

-- User B

.... the representation really isn't suitable for automatic processing. You can come up with heuristics such as identifying the "original message" separator and the first (possibly localized and mutilated) "to:" field after the separator, perhaps by requiring all messages to be from a particular version of a particular client with a particular locale setting, but in the general case, this cannot be solved reliably.

(For fun, I constructed an example from a Swedish localization running with Finnish system settings; so the labels from the client are in Swedish, but the system's date is in Finnish.)

If you can edit your question to include an example of a forwarded message and maybe some boundary conditions (it's always from the same user, the version and localization of the client software she uses will not change, etc, perhaps) we can try to take it from there.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top