Begin work on processing maildir files.
This commit is contained in:
		
							parent
							
								
									c845c825dd
								
							
						
					
					
						commit
						123dbd6018
					
				
					 1 changed files with 44 additions and 1 deletions
				
			
		|  | @ -16,6 +16,9 @@ use Getopt::Long; | |||
| use File::Spec::Functions; | ||||
| use File::Spec; | ||||
| use File::Path qw(make_path); | ||||
| use Mail::Header; | ||||
| use Email::Address::XS; | ||||
| use File::Copy; | ||||
| 
 | ||||
| my %GROUP_NAMES_BY_DIR = ( confidential => 'CONFIDENTIAL', privilege => 'PRIVILEGE', privileged => 'PRIVILEGE', | ||||
|                            'journalist-privilege' => 'PRIVILEGE' ); | ||||
|  | @ -61,6 +64,36 @@ UsageAndExit("Error reading \"$upiNumberFile\"") unless $count == 1 and $upiStar | |||
| 
 | ||||
| my $upiCurrentNum = $upiStart; | ||||
| 
 | ||||
| sub ProcessMailDir($$) { | ||||
|   my($inputMailDir, $destOutDir) = @_; | ||||
| 
 | ||||
|   my @msgDirs = (catfile($inputMailDir, 'new'), catfile($inputMailDir, 'cur')); | ||||
|   foreach my $dir (@msgDirs) { | ||||
|     die "$inputMailDir must be a readble maildir folder but $dir isn't a readable directory: $!" | ||||
|       unless  (-d $inputMailDir); | ||||
|   } | ||||
|   foreach my $dir (@msgDirs) { | ||||
|     opendir(my $mailDirFH, $dir); | ||||
|     while (my $file = readdir $mailDirFH) { | ||||
|       next if -d $file;    # skip directories | ||||
|       my $msgFile = catfile($dir, $file); | ||||
|       open(my $msgFH, "<", $msgFile); | ||||
|       print "       $msgFile\n"; | ||||
|       my $header = new Mail::Header($msgFH); | ||||
|       my $fields = $header->header_hashref; | ||||
|       foreach my $fieldName (qw/From To Cc Subject Date/) { | ||||
|         foreach my $item (@{$fields->{$fieldName}}) { | ||||
|           chomp $item; | ||||
|           print "             $fieldName $item\n"; | ||||
|         } | ||||
|       } | ||||
|       close $msgFH; | ||||
|     } | ||||
|     closedir $mailDirFH; | ||||
|   } | ||||
| } | ||||
| # Main Loop: | ||||
| 
 | ||||
| opendir(my $topDH, $INPUT_TOPLEVEL_DIR); | ||||
| while (my $rfp = readdir $topDH) { | ||||
|   next unless $rfp =~ /^\s*rfp-(\d+)\s*$/; | ||||
|  | @ -69,7 +102,17 @@ while (my $rfp = readdir $topDH) { | |||
|   while (my $bucketName = readdir $rfpDH) { | ||||
|     next unless $bucketName eq $GROUP; | ||||
|     my $inBucketDirName = catfile($INPUT_TOPLEVEL_DIR, $rfp, $bucketName); | ||||
|     print "  $inBucketDirName\n"; | ||||
|     opendir(my $bucketDH, $inBucketDirName); | ||||
|     while (my $typeName = readdir $bucketDH) { | ||||
|       next if $typeName =~ /^\s*\.\.?\s*$/; | ||||
|       my $typeDirName = catfile($INPUT_TOPLEVEL_DIR, $rfp, $bucketName, $typeName); | ||||
|       die "regular file found where we expected a type in $typeName" unless -d $typeDirName; | ||||
|       print "      $typeDirName\n"; | ||||
|       if ($typeName =~ /email/i) { | ||||
|         ProcessMailDir($typeDirName, ""); | ||||
|       } | ||||
|     } | ||||
|     closedir $bucketDH; | ||||
|   } | ||||
|   closedir $rfpDH; | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 Bradley M. Kuhn
						Bradley M. Kuhn