Skip to content

Commit

Permalink
Saner parsing of mbox format
Browse files Browse the repository at this point in the history
Also: Correctly handle mutt-flags
  • Loading branch information
Drahflow committed May 3, 2013
1 parent 99fba11 commit 6926870
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions perl/import-mail
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ my $timeToReadOwnMail = Settings::getImportMailTimeToReadOwnMail();
my $timeToReadMLMail = Settings::getImportMailTimeToReadMLMail();
my $utilityOfReadOwnMail = Settings::getImportMailUtilityOfReadOwnMail();

eval {
foreach my $inbox (@INBOXEN) {
my @errors;

foreach my $inbox (@INBOXEN) {
eval {
print "Searching for $inbox\n";

$inbox =~ /(.*)\/[^\/]+/ or die "cannot get directory of $inbox";
Expand All @@ -43,11 +45,15 @@ eval {
my $inboxBaseUtility = Secrets::importMailBaseUtilByInbox($inbox);

while(my $line = <INBOX>) {
if($line =~ /^X-Mozilla-Status: ...(.)$/) {
$seen = $1;
if($line =~ /^From /) {
$toMe = 0;
$state = 1;
$thisExtraUtility = 0;
$seen = 0;
} elsif($line =~ /^X-Mozilla-Status: ...(.)$/) {
$seen = $1;
} elsif($line =~ /^Status: .*R.*/) {
$seen = 1;
} elsif($state == 2 and $line =~ /^\t(.*)$/) {
$subject .= $1;
} elsif($state == 1 or $state == 2) {
Expand Down Expand Up @@ -87,18 +93,23 @@ eval {
}
}
close INBOX;
};

if($@) {
push @errors, $@;
}
}

print "Unread: " . $unreadCount . "\n";
print "Estimated utility: " . ($estimatedUtility / 1000.0) . "\n";
print "Estimated time: " . $estimatedTime . "s\n";
print "Extra utility: " . ($extraUtility / 1000.0) . "\n";

print "Unread: " . $unreadCount . "\n";
print "Estimated utility: " . ($estimatedUtility / 1000.0) . "\n";
print "Estimated time: " . $estimatedTime . "s\n";
print "Extra utility: " . ($extraUtility / 1000.0) . "\n";
createTask('Read mails', $estimatedUtility, $estimatedTime);
createTask('Read important mails', $extraUtility, 120);

createTask('Read mails', $estimatedUtility, $estimatedTime);
createTask('Read important mails', $extraUtility, 120);
};
if($@) {
createTask("Fix import-mails: $@", 1000000, 1800);
if(@errors) {
# createTask("Fix import-mails: @errors", 1000000, 1800);
}

sub createTask {
Expand Down

0 comments on commit 6926870

Please sign in to comment.