#!/opt/local/bin/perl
$path = "/var/mail/t3knomanser";
$notepath = "/Users/t3knomanser/Dropbox/Notes";

open(MAIL,$path);
@lines = <MAIL>;
$file = join("", @lines);

@messages = split(/\nFrom\st3knomanser/,$file);

foreach(@messages) {
	#parse the important bits
	/Subject:\s(.+?)\n/;
	$filename = $1;
	/\n\n(.*)/s;
	$content = $1;

	#cleanup newlines
	$content =~ s/\n\n/REPLACEME/g;
	$content =~ s/\n//g;
	$content =~ s/REPLACEME/\n\n/g;

	#write the file
	print "Writing to $notepath/$filename.txt\n";
	open(OUTPUT, ">>$notepath/$filename.txt");
	print OUTPUT $content;
	close(OUTPUT);
}
