Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

awking an email - part 2

Status
Not open for further replies.

BIS

Technical User
Jun 1, 2001
1,893
NL
Hallo All,

In a previuos thread, I manage to start replacing characters in the body of an email, ignoring the headers by something like this:

# Set field-separator.
BEGIN { FS = " *= *" }
# Remove trailing spaces.
{ sub(/[ \t]+$/, "") }
/^$/ {flg=1}
flg!=1{next}

This works fine, the end result is as expected when run form the command line.

Problem:
The idea of this is to rewrite the email, then re-inject it to the MTA for delivery. As the result of the awk script strips all the headers out, this obviously results in an undeliverable email.

Challenge:
Is it possible to keep all the headers intact, and only process the body? Somthing like:

don't touch headers, keep intact and write
start awk at the beginning of a completely empty line
/^$/ {flg=1}
flg!=1{next}

Any ideas?


 
Replace this:
flg!=1{next}
By this:
flg!=1{print;next}

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hmm - that was simple....

Doing this gives me a new problem. I need to insert some tags like:

Set field-separator.
BEGIN { FS = " *= *"; print "<TAG1>\n<TAG2>" }

but only in the body.

I tried:

/^$/ {flg=1}
flg!=1{print;next}
#
# Set field-separator.
BEGIN { FS = " *= *"; print "<TAG1>\n<TAG2>" )


but that still inserts it at the very beginning. Is it possible to simply:

/^$/ {flg=1}
flg!=1{print;next}
BEGIN { FS = " *= *" )
# Remove trailing spaces.
{ sub(/[ \t]+$/, "") }
print TAG1
print TAG2
start awk here..

somehow?



 
# Set field-separator.
BEGIN { FS = " *= *" }
# Remove trailing spaces.
{ sub(/[ \t]+$/, "") }
/^$/ {flg=1}
flg==0{print;next}
flg==1{print TAG1;print TAG2;++flg}
start awk here..

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Many thanks!

For some reason it does not print TAG1 or TAG2 - is there perhaps something missing from

flg==1{print TAG1;print TAG2;++flg} ?

 
Code:
# Set field-separator.
BEGIN { FS = " *= *" }

# Remove trailing spaces.
{ sub(/[ \t]+$/, "") }

!working && /^$/ { working = 1
  print "<TAG1>\n<TAG2>" }
!working { print ; next }

/^First_Name/ { first = $2 ; next }
/^my_last_name/ {
  $0 = "<name>" first " " $2 "</name>"}
/^Address/ {$0="<address>" $2 "</address>"}
1
 
Thanks!!

This actually works - would you have the energy to explain that construct to me?
 
Fair enough...

Thanks for your help though - much appreciated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top