File: mail2folder

package info (click to toggle)
bow 19991122-4
  • links: PTS
  • area: main
  • in suites: woody
  • size: 2,544 kB
  • ctags: 2,987
  • sloc: ansic: 38,660; lisp: 1,072; makefile: 594; perl: 492; yacc: 149; sh: 91
file content (42 lines) | stat: -rw-r--r-- 1,251 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
#!/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){
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 ([\w\.]+@[\w\.]+)/ ) {
		print "New mail from: $1\n" if $opt_d;
		if ($mail ne "" && $file ne "") {
			open (FILE,">$PREDIR/$file") || die ("Could not create $file\n");
			print FILE $mail;
			close FILE;
			print "Created $file\n" if $opt_d;
		}
		$mail=""; $file="";
		print "New mail found\n" if $opt_d;
		$add_mail=1;}
	if ($add_mail==1){		
		print "Adding $line" if $opt_d;
		$mail=$mail.$line;}
	if ($line =~ /^Message-ID: (.*)$/i ) {
		$file=$1;
		print "ID found for message: $file\n" if $opt_d;
		}
} # del while $line
close FILEREAD;
} # del if -f
} # del while shift

exit 0;