my $msg = shift; # rename $src_msg
my $mhfolder = shift;
my ($msgnum, $mhmsg); # rename $dst_msg and $dst_msgpath
- my $try;
# We must do this even in -n mode because later steps fail without
# it. This should be harmless.
}
$mhmsg = "$mh/$mhfolder/$msgnum";
} else {
- # This loop is a modified version of the maildir delivery algorithm.
- $msgnum = get_highest_msgnum($mhfolder);
- for ($try = 0; ; $try++) {
- $msgnum++;
- $mhmsg = "$mh/$mhfolder/$msgnum";
-
- if (not stat($mhmsg)) {
- if ($!{ENOENT}) {
- # Now we have a non-existent file, let's try to create
- # it. We must create a zero-byte file first because a
- # file my appear between our happy stat results and
- # our later rename(2), which would clobber said file.
- # So attempt to create a file with this name. If it
- # succeeds, in just a bit here we'll knowingly clobber
- # this file with the rename(2) call.
-
- # Another way to do this is not to use rename(2), but
- # use link(2) + unlink(2) instead. That's how the
- # standard maildir algorithm does it. Each method has
- # a disadvantage: the program may crash between the
- # link(2) and unlink(2) calls. With the standard
- # maildir algorithm, that means the message will end
- # up duplicated. The advantage of creating an empty
- # file followed by rename(2) is that an extra empty
- # file is left behind as opposed to a duplicate
- # message. This is more easily detected by the user.
- if ($run) {
- if (sysopen(MSG, $mhmsg,
- O_WRONLY | O_EXCL | O_CREAT, 0600)) {
- close(MSG);
+ # This loop is a modified version of the maildir delivery algorithm.
+ $msgnum = get_highest_msgnum($mhfolder);
+ my $try;
+ for ($try = 0; ; $try++) {
+ $msgnum++;
+ $mhmsg = "$mh/$mhfolder/$msgnum";
+
+ if (not stat($mhmsg)) {
+ if ($!{ENOENT}) {
+ # Now we have a non-existent file, let's try to create
+ # it. We must create a zero-byte file first because a
+ # file my appear between our happy stat results and
+ # our later rename(2), which would clobber said file.
+ # So attempt to create a file with this name. If it
+ # succeeds, in just a bit here we'll knowingly clobber
+ # this file with the rename(2) call.
+
+ # Another way to do this is not to use rename(2), but
+ # use link(2) + unlink(2) instead. That's how the
+ # standard maildir algorithm does it. Each method has
+ # a disadvantage: the program may crash between the
+ # link(2) and unlink(2) calls. With the standard
+ # maildir algorithm, that means the message will end
+ # up duplicated. The advantage of creating an empty
+ # file followed by rename(2) is that an extra empty
+ # file is left behind as opposed to a duplicate
+ # message. This is more easily detected by the user.
+ if ($run) {
+ if (sysopen(MSG, $mhmsg,
+ O_WRONLY | O_EXCL | O_CREAT, 0600)) {
+ close(MSG);
+ last;
+ }
+ } else {
last;
}
- } else {
- last;
}
}
- }
- # This algorithm is different from the maildir one; let's make
- # 10 tries instead of 3.
- if ($try == 9) {
- die("Attempted filename $mhmsg exists.");
- }
+ # This algorithm is different from the maildir one; let's make
+ # 10 tries instead of 3.
+ if ($try == 9) {
+ die("Attempted filename $mhmsg exists.");
+ }
- # This algorithm is different; i don't think we need to sleep.
- #sleep(2);
- }
+ # This algorithm is different; i don't think we need to sleep.
+ #sleep(2);
+ }
if ($run) {
# Mark each message as soon as we store it and bomb if that