[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Extracting email headers

On Mon, Sep 02, 2002 at 09:38:44PM -0400, Andy Saxena wrote:
| Hi,
| The problem is really simple.
| I receive email on my long commute, and I'd like to be able to send some
| of the more important messages to my cellphone, so I can make the
| necessary calls.
| The trouble is that my cellphone can only receive about 100 characters
| in the body of the email. So my plan is to use a procmail recipe to
| filter out the important messages and send the subject and the sender's
| name in the subject line of the email to the cellphone; then the body of
| the email will have the first 100 characters from the body of the
| original email.
| I am trying to use formail to extract the "From: " and "Subject"
| headers, and then use tr to put them one line by eliminating the
| newline. However, I am having no success in this. I have read the
| manuals and tried all the options. Obviously, this is not working.
| Could somebody provide some pointers on how to retrieve two headers from
| the email and combine them into one line?
| Even better if somebody has a more eloquent solution :-}.

I found a solution thanks to the efforts of a kind gentleman in Karachi.
His email to me is shown below. I also modified the solution to add
another feature. Details below.

---------------------------Faisal's email (begin)----------------------

From: "Faisal S. Naik" <faisal@hamdard.net.pk>
To: "Andy Saxena" <andyML@nyc.rr.com>
Subject: Re: did u get a solution
Date: Thu, 12 Sep 2002 15:20:48 +0600

Hi once again
Here is a link i found while searching a solution to our problem :)
Section 14.4 caters to it. I tried it but it is give me errors in the
procmail.log file
Hope it helps you. If you are successful please let me know

---------------------------Faisal's email (end)----------------------

Here's my modified version of the procmail recipe that gets rid of the
errors (caused by a missing "\") and also only sends me the email if it
arrives in the inbox between 7 AM and 6 PM. This is my work email, so
obviously I don't want my cellphone beeping while I am enjoying a
fabulous evening in pleasant company or asleep at night. Only the
relevant parts of the procmailrc file are shown.

---------------------~/.procmailrc (begin)----------------------------

#I use IMAP not POP.
IMAP="$DELIVERMAIL -a andy -q -m user.andy"

#Great for troubleshooting.

# I need this because for some reason cyrdeliver will reject email with
# the "From " envelope header, and I don't know any other solution.

| spamassassin -P -F0

# This will send a message to my cellphone causing it to beep. The
# original idea was to split the message body into lines no longer than
# 200 characters, and then send each piece in a separate email. However,
# I am really not interested in the message arriving in 20 pieces and
# flooding my small inbox on the cellphone. Therefore, I use "head -n1"
# to generate only one message. Also I wanted a 100 character limit.
# This solution preserves the original "From: " and "Subject: " headers.

:0 c
    # Construct only from From: and Subject:
    HEADER = `formail -XFrom: -XSubject:`

    :0 bw
    | tr '\012' ' ' | fold -s -w 100 | head -n1 | \
	    if [ `date +%H` -gt 7 ] && [ `date +%H` -lt 18 ]; then \
	    	while read line; do \
	        echo -e "$HEADER\n\n$line" | $SENDMAIL my@email.com; done \


---------------------~/.procmailrc (end)------------------------------


Reply to: