This file is indexed.

/usr/share/perl5/Email/LocalDelivery/Mbox.pm is in libemail-localdelivery-perl 0.217-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
package Email::LocalDelivery::Mbox;
use strict;

use File::Path;
use File::Basename;
use Email::Simple 1.998;  # needed for ->header_obj
use Fcntl qw(:DEFAULT :seek);
use Symbol qw(gensym);

use vars qw($VERSION);
$VERSION = "1.103";

sub deliver {
  # The slightly convoluted method of unrolling the stack is intended to limit
  # the scope of which a large string at $_[1] might be in memory before being
  # constructed into an Email::Simple. -- rjbs, 2007-05-25
  my $class = shift;

  my $email;
  if (eval { $_[0]->isa('Email::Simple') }) {
    $email = shift;
  } else {
    my $text = shift;
    $email = Email::Simple->new(\$text); # requires Email::Simple 1.998 or so
  }

  my @files = @_;

  my @rv;

  for my $file (@files) {
    my $fh = $class->_open_fh($file) or next;
    print $fh "\n" if tell($fh) > 0;
    print $fh $class->_from_line($email);
    print $fh $class->_escape_from_body($email);

    # This will make streaming a bit more annoying. -- rjbs, 2007-05-25
    print $fh "\n" unless $email->as_string =~ /\n$/;

    $class->_close_fh($fh, $file) || next;
    push @rv, $file;
  }
  return @rv;
}

sub _open_fh {
  my ($class, $file) = @_;
  my $dir = dirname($file);
  return if !-d $dir and not mkpath($dir);

  my $fh = gensym;
  open $fh, ">> $file" or return;
  $class->getlock($fh, $file) || return;
  seek $fh, 0, 2;
  return $fh;
}

sub _close_fh {
  my ($class, $fh, $file) = @_;
  $class->unlock($fh, $file) || return;
  close $fh or return;
  return 1;
}

sub _escape_from_body {
  my ($class, $email) = @_;

  my $body = $email->body;
  $body =~ s/^(From )/>$1/gm;

  return $email->header_obj->as_string . $email->crlf . $body;
}

sub _from_line {
  my ($class, $email) = @_;

  # The qmail way.
  return $ENV{UFLINE} . $ENV{RPLINE} . $ENV{DTLINE} if exists $ENV{UFLINE};

  # The boring way.
  return _from_line_boring($email);
}

sub _from_line_boring {
  my $mail = shift;
  my $from = $mail->header("Return-path")
    || $mail->header("Sender")
    || $mail->header("Reply-To")
    || $mail->header("From")
    || 'root@localhost';
  $from = $1 if $from =~ /<(.*?)>/;  # comment <email@address> -> email@address
  $from =~ s/\s*\(.*\)\s*//;         # email@address (comment) -> email@address
  $from =~ s/\s+//g;                 # if any whitespace remains, get rid of it.

  my $fromtime = localtime;
  $fromtime =~ s/(:\d\d) \S+ (\d{4})$/$1 $2/;  # strip timezone.
  return "From $from  $fromtime\n";
}

sub getlock {
  my ($class, $fh, $file) = @_;
  for (1..10) {
    return 0 unless $class->getlock_fcntl($fh);
    return 1 if $class->getlock_dotlock($file);
    sleep int(rand(10 * $_));
  }
  $class->unlock_fcntl($fh);
  return 0;

}

sub getlock_fcntl {
  my ($class, $fh) = @_;
  my $lock = pack('ss@256', F_WRLCK, SEEK_SET);
  for (1..10) {
    return 1 if fcntl($fh, F_SETLK, $lock);
    sleep $_;
  }
  return 0 ;
}

sub getlock_dotlock {
  my ($class, $file) = @_;
  my $lockfile = $file . ".lock";
  my $cmd = "/usr/bin/dotlockfile";
  system($cmd, $lockfile);
  return 1 unless $?;
  if ($? == -1) {
    die("Couldn't exec $cmd: $!");
  }
  if ($? & 127) {
    warn("$cmd exited with signal " . ($? & 127));
  }
  return 0;
}

sub unlock {
  my ($class,$fh, $file) = @_;
  return 0 unless $class->unlock_dotlock($file);
  return 0 unless $class->unlock_fcntl($fh);
  return 1;
}

sub unlock_fcntl {
  my ($class, $fh) = @_;
  my $lock = pack('ss@256', F_UNLCK, SEEK_SET);
  return 1 if fcntl($fh, F_SETLK, $lock);
  return 0;
}

sub unlock_dotlock {
  my ($class, $file) = @_;
  my $lockfile = $file . ".lock";
  my $cmd = "/usr/bin/dotlockfile";
  system($cmd, "-u", $lockfile);
  return 1 unless $?;
  if ($? == -1) {
    die("Couldn't exec $cmd: $!");
  }
  if ($? & 127) {
    warn("$cmd exited with signal " . ($? & 127));
  }
  return 0;
}

1;