Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'One-script version with full body text' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
One-script version with full body text
Authored by: jima on Sep 03, '02 07:41:08AM
This is a one-script version of wfolta's "Cleaner but two-script version"... plus I added the To: field, and made a few changes to grab all of the body text. Not that this script MUST be named mailexport.pl (unless you change it in the source code).
#!/usr/bin/perl

if ($ARGV[1] == 2) {

	$mail_dir = $ARGV[0] ; 
	
	$date = "???" ;
	$subject = "???" ;
	$from = "???" ;
	$to = "???" ;
	
	while () {

		$body = '';
		push (@message, );
		foreach (@message) {

			if (/^From: (.+)$/) {
				chomp ($from = $1);
			}

			elsif (/^Subject: (.+)$/) {
				chomp ($subject = $1);
			}

			elsif (/^Date: (.+)$/) {
				chomp ($date = $1);
			}
			
			elsif (/^To: (.+)$/) {
				chomp ($to = $1);
			}
			
			else {
				$body .= $_;
			}

		}

	}
	
	print ("$mail_dirt$datet$fromt$tot$subjectt", $body, "n") ;

} else {

	$full_dir = $ARGV[0] ;
	($mail_dir = $full_dir) =~ s|^.+?//|| ;
	$mail_dir =~ s|.mbox/mbox|| ;
	$mail_dir =~ s|/| : |g ;
	$full_dir =~ s/ /\ /g ;

	system("cat '$full_dir' | formail -e -k -X Subject: -X From: -X " .
			"Date: -X To: -s ./mailexport.pl '$mail_dir' '2'") ;

}
To run it type (same as earlier post):
find ~/Library/Mail/Mailboxes/ -name mbox -exec ./mailexport.pl 
'{}' ';' > tab-delimited-list


[ Reply to This | # ]
Corrected
Authored by: jima on Sep 03, '02 07:48:23AM

We need a hint on how to post source code without it getting munged :-/

#!/usr/bin/perl

if ($ARGV[1] == 2) {

$mail_dir = $ARGV[0] ;

$date = "???" ;
$subject = "???" ;
$from = "???" ;
$to = "???" ;

while (<STDIN>) {

$body = '';
push (@message, <STDIN>);
foreach (@message) {

if (/^From: (.+)$/) {
chomp ($from = $1);
}

elsif (/^Subject: (.+)$/) {
chomp ($subject = $1);
}

elsif (/^Date: (.+)$/) {
chomp ($date = $1);
}

elsif (/^To: (.+)$/) {
chomp ($to = $1);
}

else {
$body .= $_;
}

}

}

print ("$mail_dir\t$date\t$from\t$to\t$subject\t", $body, "\n") ;

} else {

$full_dir = $ARGV[0] ;
($mail_dir = $full_dir) =~ s|^.+?//|| ;
$mail_dir =~ s|\.mbox/mbox|| ;
$mail_dir =~ s|/| : |g ;
$full_dir =~ s/ /\\ /g ;

system("cat '$full_dir' | formail -e -k -X Subject: -X From: -X " .
"Date: -X To: -s ./mailexport.pl '$mail_dir' '2'") ;

}



[ Reply to This | # ]
Entourage X
Authored by: jima on Sep 03, '02 08:04:56AM

I noticed that if you drag a folder from the Entourage X Inbox to the Finder it saves it in a *.mbox format. So to make this work with Entourage, drag a folder from Entourage to the same Finder directory that the script is in (in this example the folder was called 'work' in Entourage, and in the Finder it appeared as 'work.mbox'). Next, use BBEdit (or ??) to change the line endings from Mac to Unix. Then in the Terminal from the directory that the script is in, type:

perl ./mailexport.pl work.mbox > tab-delimited-list

whoo-hoo! :)



[ Reply to This | # ]
One-script version with full body text
Authored by: Miga on Sep 03, '02 06:35:10PM

Does this script run with Jaguar?

I have nothing else as delete messages for mac.com mailbox and outbox in Mailboxes, the input boxes are in separate folders together with drafts, deleted messages (again), message UIDs already downloaded, and sent messages.

I have tried the script with the name of one this folder instead of Mailboxes, but it does not seem to work.

Maybe I did something wrong, as I'm new at shell scripting.



[ Reply to This | # ]
One-script version with full body text
Authored by: wfolta on Sep 04, '02 10:16:53AM

These scripts should work with Jaguar. Note that the find command assumes the mailboxes are in Library, which I believe changed from early versions of Mail that had them in Mailboxes directly in your home directory. (At least I had a Mailboxes directory in my home directory, which I think was a result of that.)

What kind of error/problem are you getting?



[ Reply to This | # ]
How would you run this on a specific mailbox?
Authored by: illovich on Jun 18, '04 11:59:47AM

How would you run this on a specific mailbox? I'm tying to run it on a mailbox:

/Users/illovich/Library/Mail/Mailboxes//From Faculty.mbox

(I don't know why that double slash is between the file and directory t the end, btw... maybe it has something to do with my find. I was trying to do this:

[code]find ~/Library/Mail/Mailboxes/ -name 'From Faculty.mbox' -exec ./mailexport.pl '{}' ';' > tab-delimited-list[/code]

but I get a blank text file. Can anyone see what I'm doing wrong? Thanks.

---
illovich
http://illovich.com



[ Reply to This | # ]
One-script version with full body text
Authored by: brunus on Sep 01, '08 03:11:57AM

hi there,
nice script!
But how could I export the header field for specific messages, from within mail, into a csv or tab file?
any idea on this?

thanks,

brunus



[ Reply to This | # ]