Operating System - HP-UX
1830327 Members
2206 Online
110001 Solutions
New Discussion

Re: how to forward large mailbox

 
SOLVED
Go to solution
Geetam
Frequent Advisor

how to forward large mailbox

After a few problems on their side, my ISP has given me a large file in unix mailbox format with over 1100 emails for many different people.

Can I use one of my UX machines (or Linux) to forward these emails to the correct email addresses? How? Please help me to do this quickly.

Thanks
6 REPLIES 6
Kofi ARTHIABAH
Honored Contributor

Re: how to forward large mailbox

Geetam:

If you can, provide more information eg. What OS and sendmail version does your ISP use (because different versions of unix store mails in different formats); a sample header of the mailbox file will also be helpful. Essentially what needs to be done is to write an awk script that will parse the large mailbox for individual messages and mail them off based on the To: field.

but in order to be able to come up with such a script, we need to know how each message starts; and what extension parts it has.

A typical message may be of the form:

From $user $date
Recieved: from ( $user@$hostname) by $thishost $more_sendmail_info
Date: $date
From: $sender
Message-Id: <$messageID>
To: $receipient
Subject: $subject_of_message
$Otherheaders
$BODY_OF_MESSAGE

From $user $date
Recieved: from ( $user@$hostname) by $thishost $more_sendmail_info

nothing wrong with me that a few lines of code cannot fix!
Geetam
Frequent Advisor

Re: how to forward large mailbox

Kofi

It sounds to me that you have a good idea there; I think that might work.

I am not sure what our ISP is using, one of the problems is communication between them and us (not just datacomms!)

I think am sure it is some sort of unix, and I have heard them talk about qmail.

I have been able to open this mailbox file with mutt; that is how I know how many emails are in there.

I attach a sample of the contents of the mailbox file.

Thanks for your help
Geetam
Frequent Advisor

Re: how to forward large mailbox

Can you give me an example of an awk command line or awk script which would do a job like that (look for beginning of each email, look for destination email address, ouput suitable email to destination address)? (If I understand it I can modify it myself to make it work)

Can the text as I see it in the mailbox file be used as input to a mailer (mailx) or do I save each email in a file in a particular directory to it queue for processing?

Thanks
Kofi ARTHIABAH
Honored Contributor

Re: how to forward large mailbox

Geetam:

sorry about the delay.. here is something quick and dirty ( you might have to look it over and modify accordingly eg., deal with the subject line, use elm, etc...) This is just to give you an idea...

you could invoke the script with:

awk -f remail.awk mailfilefromISP

#!/usr/bin/awk
#
#
BEGIN { FS="n" }
total_lines=0
if ( match ($0, /^From /)) {

processoldrecord ( record, totallines )
else
record[totallines++]=$0
}


function processoldrecord (record, totallines) {
if ( totallines == 0 ) { return}

print > "temp.out"

for ( counter = 0 ; counter < totallines ; counter++ ) {

print record[counter] >> "temp.out"
if ( match($0, /"^To: "/ )) {

toaddr=extractaddress($0)
}

system ( "mail " toaddr "< temp.out" )
}

function extractaddress (inline) {

z = split ( inline, array, " ")
for (i = 1 ; i <= z ; ++i ) {
if ( match(array[i], /[a-zA-Z0-9.]+@[a-zA-Z0-9.]+/ ) return array[i]
return array[z] # if no @ sign, assume last parameter is address
}
nothing wrong with me that a few lines of code cannot fix!
Geetam
Frequent Advisor

Re: how to forward large mailbox

Kofi

Thanks, that is very helpfull, but...

I think some \ (backslashes) are missing.
I spotted one in the FS, which I am assuming is supposed to be a new-line.

But I also get syntax errors problems on the line:
if ( match ($0, /^From /)) { ....

I have not used the built-in function match before, so I don't know what may be wrong there

Could you attach your example awk srcipt as a file, please

Thanks
Kofi ARTHIABAH
Honored Contributor
Solution

Re: how to forward large mailbox

Geetam:

gremlins ahoy!! :-)

here you are with the awk script... I tested this in my environment and it seemed to work - I have commented out the part that mails out (so that you do not have it firing off e-mails ... you might want to test some parts of it first)

the match() is supposed to return the value of the first match of a regular expression in a string.

I have identified some to do's which you may want to look at...

lets know how it goes - I am in and out today, so it might be delayed.
nothing wrong with me that a few lines of code cannot fix!