Skip to content

Commit

Permalink
Item11379: stamp the run with the time at the start, not the end, to …
Browse files Browse the repository at this point in the history
…avoid race conditions on incoming mails

git-svn-id: http://svn.foswiki.org/trunk/MailInContrib@17647 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
CrawfordCurrie authored and CrawfordCurrie committed May 7, 2014
1 parent c4668b3 commit 6b54f47
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions lib/Foswiki/Contrib/MailInContrib.pm
@@ -1,7 +1,7 @@
#
# Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# Copyright (C) 2009 Foswiki Contributors. All Rights Reserved.
# Copyright (C) 2009-2014 Foswiki Contributors. All Rights Reserved.
# Foswiki Contributors are listed in the AUTHORS file in the root
# of this distribution. NOTE: Please extend that file, not this notice.
#
Expand Down Expand Up @@ -34,7 +34,7 @@ use Time::ParseDate;
use Error qw( :try );
use Carp;

our $VERSION = '$Rev: 10183$';
our $VERSION = '3.0';
our $RELEASE = '18 Jan 2010';
our $SHORTDESCRIPTION = 'Supports submissions to Foswiki via e-mail';

Expand All @@ -47,7 +47,7 @@ BEGIN {
package MIMEFolder;

use Email::Folder;
our @ISA = qw( );
our @ISA = qw( Email::Folder );

sub bless_message {
my $self = shift;
Expand All @@ -67,16 +67,23 @@ Construct a new inbox processor.

sub new {
my ( $class, $session, $debug ) = @_;
my $this = bless( {}, $class );
$this->{session} = $session;
$this->{debug} = $debug;
my $this = bless(
{
session => $session,
debug => $debug,
startTime => time()
},
$class
);

# Find out when we last processed mail
my $workdir = Foswiki::Func::getWorkArea('MailInContrib');
if ( -e "$workdir/timestamp" ) {
open( F, "<$workdir/timestamp" ) || die $!;
$this->{lastMailIn} = <F>;
chomp( $this->{lastMailIn} );
print STDERR "Timestamp is $this->{lastMailIn} ("
. Foswiki::Time::formatTime( $this->{lastMailIn} ) . ")\n";
close(F);
}
else {
Expand All @@ -101,7 +108,7 @@ sub wrapUp {
# re-stamp
my $workdir = Foswiki::Func::getWorkArea('MailInContrib');
open( F, ">$workdir/timestamp" ) || die $!;
print F time(), "\n";
print F $this->{startTime}, "\n";
close(F);
}

Expand Down Expand Up @@ -226,6 +233,10 @@ sub processInbox {
}
}

print STDERR "Received: $received ("
. Foswiki::Time::formatTime($received) . ")\n"
if $this->{debug};

print STDERR "User is '", ( $user || 'undefined' ), "'\n"
if ( $this->{debug} );

Expand Down Expand Up @@ -294,7 +305,6 @@ s/^(\s*(?:($Foswiki::regex{webNameRegex})\.)?($Foswiki::regex{topicNameRegex})(:
print STDERR "Skipping; no topic\n" if ( $this->{debug} );
next unless $topic;
}

if ( $box->{ignoreMessageTime} or $received > $this->{lastMailIn} ) {
my $err = '';
unless ( Foswiki::Func::webExists($web) ) {
Expand Down Expand Up @@ -615,7 +625,7 @@ sub _saveTopic {
my ( $meta, $text ) = Foswiki::Func::readTopic( $web, $topic );

my $opts;
if ( $text =~ /<!--MAIL(?:{(.*?)})?-->/ ) {
if ( $text && $text =~ /<!--MAIL(?:{(.*?)})?-->/ ) {
$opts = new Foswiki::Attrs($1);
}
else {
Expand Down

0 comments on commit 6b54f47

Please sign in to comment.