1) How do I extract that string of text from the body, the reference number,
and assign it to a variable. The structure of the reference number is:
REF#12345678
Please note that "REF#" is always the same, and 12345678 are 8 digits from 0
to 9 .
Something like this:
:0 BD
* ^REF#\/[0-9]+
{ REFERENCE = $MATCH }
# BD means case sensitive in the body of the message
# \/ means match everything to the right of this (so anything
# after 'REF#' is put into the variable $MATCH)
# The last part sets the variable REFERENCE equal to the matched numberw
If the REF isn't always going to be at the start of a line, you can
remove the '^' that anchors it. The example above also lets you have
a REF that is variable in length (1 to n numeric characters), but if
you always want 8 change the second line to
* ^REF#\/[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]
This will pull the first REF# that it finds, so if you have multiple
ones you're sunk. If you need to account for multiple ones, you'll
need some sort of scoring system set up (and a logic system to decide
which REF# is the valid one).
2) Once I extracted the reference number and asign it to a variable, let's
say $REFERENCE, how do I change the subject of the email for the variable
$REFERENCE ?
If you want to replace the Subject: header entirely, you can do something
like this (after the first recipe):
:0 fhw
| formail -I"Subject: $REFERENCE"
If you want to have the reference number in brackets before the
original Subject: (i.e. '[141251236] Need help fast'), then this
will do it:
:0 fhw
* ^Subject: \/.*
| formail -I "Subject: [$REFERENCE] $MATCH"
There's probably a more elegant way to do this (David? Era? Philip? :)
Chris