Koozali.org: home of the SME Server
Contribs.org Forums => General Discussion => Topic started by: purvis on April 10, 2013, 10:40:46 AM
-
i hope this bit of code helps save somebody some time
This code does not remove carriage return characters from the header if they exist it and
the code assumes no carriage return characters are in the header.
The returned string semailheader includes the full email header with all full lines and all lines are terminated with a linefeed.
Any lines in the original email that where wrapped in the email have been unwrapped.
All tab characters in the lines are replaced by one space character.
semailheader=$(grep -B10000 -m1 ^$ $filename | tr -s '\t' '\040'|sed -e ':a;N;$!ba;s/\n / /g')
a function for including in a bash file
function getemailheaderfromemailfile {
semailheader=$(grep -B10000 -m1 ^$ $filename | tr -s '\t' '\040'|sed -e ':a;N;$!ba;s/\n / /g')
# echo -e "$semailheader"
return
}
getemailheaderfromemailfile $filename
echo -e "$semailheader"
-
I beg your pardon but... why?
-
to make the above an executable here is the code for a bash file
place this code in a file named similar to "emailheader"
use nano to create the file nano -w -c emailheader
cut and paste the code in it
make sure there is no blank lines at the top of the file
close nano with ctrl-x
last, make the file executable with chmod +x emailheader
run the program with a email file name on the command line
emailheader filename
#!/bin/bash
filename="$*"
if [ -f "$filename" ] && [ -e "$filename" ] && [ -r "$filename" ]
then
echo -e "$(grep -B10000 -m1 ^$ "$filename" | tr -s '\t' '\040'|sed -e ':a;N;$!ba;s/\n / /g')"
exit 0
else
exit 1
fi
-
I repeat my question in another way: cui prodest? :-)
-
Stefano
It will be used in code I will be posting later and I looked all over for a fast way to get the email headers.
This is a gift.
As far as i know, there is no built in program to get to this information in sme.
This code requires not compiling either.
-
Stefano,
If this is no benefit to you. Don't use it.
And please speak English.