procmail
[Top] [All Lists]

Re: trimming forwarded messages

2000-11-17 14:20:05
* Mark E. Crane <mark(_at_)louisville(_dot_)edu> [001117 04:07] wrote:
Right now I'm trying to clean up messages going to my pager. My
users are really only familiar with groupwise, so I'm forwarding
their gwise messages to a pine account, where I am trying to use
procmail to strip out unnecessary header stuff so that I can get
the message within the 200 character limit of my pager. Judging
from the archives this is a recurring problem. Below is the recipe
I'm using to try and shorten the headers:

:0 fhW
   | formail -k -X From: -X Subject

The -k shouldn't be needed, since the h flag tells procmail to only
feed the head to the pipe. More importantly though, do you need to
do this at all? I have used a variety of SMS and paging providers,
and all of them automatically strip other headers from the incoming
message before sending it on. They also reformat the From: header,
leaving just the comment part if there is one. I think that the
message length is considered only after those headers are stripped
(although I am not sure).

I know I'm doing something fundamentally wrong in the above
script, because it's not forwarding stuff that's been formail-ed,
but I'll figure it out. The bigger problem, however, is that
the messages forwarded from Groupwise keep the original as
attachments, so I'm trying to figure out how to scrub the
forwarded message so that only the From:, Subject: and body go to
my pager.

Here's what a forwarded groupwise message looks like when saved
from pine. Thanks for any help you might render, and my preemptive
apologies if this question is too simple:

Ok. Since so many have been asking for it, here is what I use to
send selected messages to my cell phone. This is stable code except
for any typos I may have introduced preparing it for this posting.



# Set up some variables:
#
#  if $pagesms is non-null, this is an SMS paging address
#  $here is a tag for x-loop

  pagesms=1234567(_at_)sms(_dot_)service(_dot_)com
  here=me(_at_)example(_dot_)com

# $smsmaxmsg is the longest SMS message my provider will process
# it is built up from smaller strings

  smsmaxmsg=200
  sms10=.^*.^*.^*.^*.^*.^*.^*.^*.^*.^*
  sms100=$sms10$sms10$sms10$sms10$sms10$sms10$sms10$sms10$sms10$sms10
  sms200=$sms100$sms100

# $online will have substring ' still' if we are online. If your user name
# has the substring ' still', this will not work.

  :0 h i w
  online=| last -1 $LOGNAME

# Page me if I am not now online and the service is defined. This requires
# reducing the message to a size acceptable by the SMS provider.

  :0 c
  * pagesms ?? .
  * ! online ?? () still
  { 

    # Strip comments out of body. Perhaps this should come after the mime
    # processing, but it works fine here as well. If your sed doesn't handle
    # [:space:], use an equivalent construct. Note that the square braces
    # enclose a space and a tab. There are other forms of quoting which may
    # be encountered, but they aren't handled here.

    osm=SHELLMETAS SHELLMETAS
    :0 B f b w i
    * ^[  ]*>
    | sed -e '/^[[:space:]]*>/d'
    SHELLMETAS=osm

    # default to a messages that says that the body was textless, then handle
    # plain text and mime messages that have text parts.

    pagebody="** no text **"

    # If the header says multipart, look in the body for a text/plain part and
    # grab 10 lines after the blank line(s) after the content-type header. You
    # may want a larger value than 10 if your service handles longer messages.
    # This doesn't deal with encodings. SMOP.

    :0 B
    * H ?? ^content-type:.*multipart
    * ^content-type:.*text/plain(.*$)+\
      [  ]*$(([  ]*$)*)*\/[^  
].*$(.*$)?(.*$)?(.*$)?(.*$)?(.*$)?(.*$)?(.*$)?(.*$)?(.*$)?
    { pagebody=$MATCH }

    # If it wasn't a multipart mime message with at least one text/plain part,
    # just grab 10 lines after the header/body neck. This skips leading space
    # on the first text line as well.

    :0 E B
    * ^^([  ]*$)*[  ]*\/[^  
].*$(.*$)?(.*$)?(.*$)?(.*$)?(.*$)?(.*$)?(.*$)?(.*$)?(.*)?
    { pagebody=$MATCH }

    # Ok, pagebody has plain text in it, but still may have a signature. We
    # can handle that if it is separated with a sigdash.

    :0
    * MATCH ?? ^^\/((([^-]|-[^-]).*)?$)*
    * MATCH ?? ^^\/(.*$)*.*[^ ]*
    { pagebody=$MATCH }

    # Now check the length of what is left. If it is too long, trim it to the
    # first $smsmaxmsg characters.

    :0
    * 1^1 pagebody ?? .
    * $ -$smsmaxmsg^0
    * $ pagebody ?? ^^\/$sms200
    { pagebody=$MATCH }

    # Replace the message body with the pagebody, leaving the headers intact.

    :0 f b w i
    | echo "$pagebody"

    # Add an X-Loop header in case the SMS provider bounces this back.

    :0 f h w
    | formail -A "X-Loop: $here"

    # Send it on its way.

    :0
    ! -- $pagesms
  }

-- 
Rik Kabel      old enough to be an adult      rik(_at_)panix(_dot_)com
_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail

<Prev in Thread] Current Thread [Next in Thread>