PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > parameter $1
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

parameter $1

Réponse
 
LinkBack Outils de la discussion
Vieux 01/09/2007, 16h37   #1
fd0
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut parameter $1

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

  Réponse avec citation
Vieux 01/09/2007, 17h44   #2
Cyrus Kriticos
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: parameter $1

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
  Réponse avec citation
Vieux 01/09/2007, 18h04   #3
Bill Marcum
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: parameter $1

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.
  Réponse avec citation
Vieux 01/09/2007, 19h37   #4
fd0
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: parameter $1

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




  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 17h42.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,12192 seconds with 12 queries