procmail
[Top] [All Lists]

Re: Removing multiple spaces from Subject lines

2001-04-06 00:38:12
From: Trevor Jenkins <trevor(_dot_)jenkins(_at_)suneidesis(_dot_)com>

Now to solve the problem of overly long subject lines. (formail returns
the line break.)

The following section of sed code, taken from a longer set of statements
in my auto-reply bot, takes Subject lines longer than - I think I'm going
to get this part right, but I can't remember for certain at this sec -
longer than 48 chars and breaks them at the first *whole word* preceding
the 44th char (so we can then add in " . . ." and have the length still
be no longer than 48 chars).

The "about " you'll see is just a marker in my statement, because the word
"about" appears left-anchored in the auto-reply line that will have the
Subject, forshortened as necessary, appended thereafter.  You ought to be
able to take this section of statements and customize them for your own
similar use.

            sed "s/\$SUBJ/$SUBJ/;                                        \
                 s/$TAB/$SPACE$SPACE$SPACE$SPACE$SPACE/g;                \
                 s/^\(about \".*[.!?]\)\.\"$/\1\"/;                      \
                 s/^\(about \".\{48\}[^$SPACE]*\).*/\1/;                 \
                 s/^\(about \".\{44\}[^$SPACE]*\).*[^\"]$/\1/;           \
                 s/^\(about \".*\)$SPACE.\{0,43\}.*[^\"]$/\1/;           \
                 s/^\(about \"[^$SPACE]\{43\}\)[^$SPACE]\{6\}[^\"].*/\1/;\
                 s/^about \".*[^\"]$/& . . .\"/;      

Here's an example.  I'll send myself an email with a Subject that says
"Now is the time for all good men to come to the aid of their country"
and show, parsed down to the relevant paragraph, the result as sent back: 


  Your message will be read soon.  A personal response will
  follow (if one is indicated) in at most two business days
  about "Now is the time for all good men to come to . . ."
  

The sed stuff also checks for a trailing punctuation mark before
it goes ahead and sticks the " . . ." on there.  This avoids
ugliness that might result from what otherwise could end up
being something like ". . . ." when I really only wanted a three-
dot ellipsis, not a four-.  (A four-dot ellipsis means something
that is different, albeit subtlely so, from a three-dot
ellipsis; and I would not want to use one without intending
so, even if by automation.)

There may be a more elegant way to write the sed statement; if so,
maybe somebody will supply that by way of kibbitzing.

  -=dman=-

-- 
Netcom has imploded.  Please now use NOTnetcom.com for mail.
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Ex-Netcommies:  Mail "forwards" for free forwarding service!
NOT affiliated with EarthLink, Inc.'s Netcom brand identity.
_______________________________________________
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>