|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
I try to write a bash script to filter an email with attached file,
save it, print it and returning only text to procmail. procmail last command is .... |$BADCRIPT in badscript formail -X "" $1 > head.txt munpack -q -t $1 ..... formail to extract the headers and munpack to extract the attached files and the message in various mime type (files are named part1 part2 and contains plaint/text and html/text) but I wrote bad something If I run to first formail: the headers are in head.txt but munpack don't find the body of messagge in $1 when change position and run formail after munpack, head.txt contain from: foo.bar and date when I try to substitute formail with: sed -e '/^$/ q' $1 > head.txt if sed is before munpack, extract the headers well, but munpack don't find the attached files, and extract the message only in plain text do sed after munpack write a empty file. to test badscript without send mails, I used two differents way, firt cat email.eml | ./badscrpt and ./badscript < email.eml with differents results, why? I try to write $1 in a file, but echo $1 > temp.txt or echo -e $1 or echo "$1" or echo -e "$1" write file with empty line |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
fd0 wrote:
> I try to write a bash script to filter an email with attached file, > save it, print it and returning only text to procmail. > > procmail last command is > > ... > |$BADCRIPT > > in badscript > > formail -X "" $1 > head.txt > munpack -q -t $1 > .... > formail to extract the headers and munpack to extract the attached > files and the message in various mime type (files are named part1 > part2 and contains plaint/text and html/text) > > but I wrote bad something > > If I run to first formail: the headers are in head.txt Strange. From manpage of formail (Version v3.22 2001/09/10): "The mail/mailbox/article contents will be expected on stdin." formail -X "" < $1 > head.txt ^ -- Best regards | "The only way to really learn scripting is to write Cyrus | scripts." -- Advanced Bash-Scripting Guide |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
On Sat, 01 Sep 2007 15:37:50 -0000, fd0
<210766@gmail.com> wrote: > > > I try to write a bash script to filter an email with attached file, > save it, print it and returning only text to procmail. > > procmail last command is > > ... >|$BADCRIPT > > in badscript > > formail -X "" $1 > head.txt > munpack -q -t $1 > .... > formail to extract the headers and munpack to extract the attached > files and the message in various mime type (files are named part1 > part2 and contains plaint/text and html/text) > > but I wrote bad something > > If I run to first formail: the headers are in head.txt but munpack > don't find the body of messagge in $1 > when change position and run formail after munpack, head.txt contain > from: foo.bar and date > Assuming that the variable BADCRIPT contains the name of your script, there is no $1. formail reads standard input, and there is nothing for munpack to read. You could do something like tempfile=$(mktemp) touch "$tempfile" || exit 1 tee "$tempfile" | formail -X "" >head.txt munpack -q -t "$tempfile" && rm "$tempfile" > when I try to substitute formail with: sed -e '/^$/ q' $1 > head.txt > if sed is before munpack, extract the headers well, but munpack don't > find the attached files, and extract the message only in plain text > do sed after munpack write a empty file. > > to test badscript without send mails, I used two differents way, firt > cat email.eml | ./badscrpt and ./badscript < email.eml > > with differents results, why? > What are the different results? > I try to write $1 in a file, but echo $1 > temp.txt or echo -e $1 or > echo "$1" or echo -e "$1" write file with empty line > -- BOFH excuse #146: Communications satellite used by the military for star wars. |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
On Sep 1, 7:04 pm, Bill Marcum <marcumb...@bellsouth.net> wrote:
> Assuming that the variable BADCRIPT contains the name of your script, right full path > there is no $1. formail reads standard input, and there is nothing for > munpack to read. You could do something like > tempfile=$(mktemp) > touch "$tempfile" || exit 1 > tee "$tempfile" | formail -X "" >head.txt > munpack -q -t "$tempfile" && rm "$tempfile" thanks, i'm a novice to a linux shell and didn't know mktemp features but this do the same a bad result. extract the headers and only the first of the attached file I look the tempfile created in /tmp/ and it's different from original mail's file I passed. the last section with 3 encoded file is gone lost the result is the same when using: cat email.eml | badscript or badscript < email.eml > > when I try to substitute formail with: sed -e '/^$/ q' $1 > head.txt > > if sed is before munpack, extract the headers well, but munpack don't > > find the attached files, and extract the message only in plain text > > do sed after munpack write a empty file. > > > to test badscript without send mails, I used two differents way, firt > > cat email.eml | ./badscrpt and ./badscript < email.eml > > > with differents results, why? > > What are the different results? an example (sorry I really don't remember every change made and results) formail -X "" $1 > head.txt munpack -q -t $1 with formail before munpack, every time head.txt contain the header, but: if you send email.eml whit: cat email.eml | badscript munpack extracts only the first part of message (text/plain). when I use < to redirect email.eml munpack found all attached files but not the message sincerely thanks |
|
![]() |
| Outils de la discussion | |
|
|