File: mail2folder

package info (click to toggle)
bow 20020213-8
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 2,596 kB
  • ctags: 2,871
  • sloc: ansic: 36,321; lisp: 1,072; cpp: 969; makefile: 569; perl: 495; sh: 101
file content (45 lines) | stat: -rw-r--r-- 1,282 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/perl
# Changes mail folders into folders with separate files
# named by Message-ID
# (c) Javier Fernandez-Sanguino Pea 1998
# Distributed under the GNU GPL License

use Getopt::Std;
getopts('d:');
$mail="";
$add_mail=0;
while ($file_to_folder=shift(ARGV)) {
	if (-f $file_to_folder){
		my $file = 0;
		open (FILEREAD,"<$file_to_folder") || die ("Could not read $file_to_folder\n");
		print "Opening $file_to_folder for reading\n" if $opt_d;
		mkdir $file_to_folder.".folder",0700 || die ("Could not creat directory for $file_to_folder\n");
		$PREDIR="./".$file_to_folder.".folder";
		print "Creating directory $PREDIR\n" if $opt_d;
		while ($line=<FILEREAD>) {
			if ($line =~ /^From (.+) / ) {
				print "New mail from: $1\n" if $opt_d;
				if ($mail ne "") {
					open (FILE,">$PREDIR/$file") || die ("Could not create $file\n");
					print FILE $mail;
					close FILE;
					print "Created $file\n" if $opt_d;
				}
				$mail=""; 
				$add_mail=1;
			}
			if ($add_mail==1){		
				print "Adding $line" if $opt_d > 2;
				$mail=$mail.$line;
			}
			if ($line =~ /^Message-ID: (.*)$/i ) {
				$id=$1;
				$file++;
				print "Saving at $file ID found for message: $id\n" if $opt_d;
			}
		} # del while $line
		close FILEREAD;
	} # del if -f
} # del while shift

exit 0;