E-mail Relaying
by Robert Kiesling

Figure 1: 

To: editors@ddj.com
From: Robert Kiesling <rkiesling@mainmatter.com>
Date: Mon, 26 Mar 2001 11:11:30 +0000


Figure 2: 

220-mail.provider.net ESMTP Sendmail EL-8933/8.9.3;
  Thu, 12 Apr 2001 16:40:22 -0700 (PDT)
HELO mainmatter.com

250 mail.provider.net Hello dialup-server.net [164.52.54.143],
  pleased to meet you
MAIL FROM:<rkiesling@mainmatter.com>

250 rkiesling@mainmatter.com... Sender ok
RCPT TO:<ckiesling@mainmatter.com>

250 <ckiesling@mainmatter.com>... Recipient ok
[... Message transmission follows ...]

Figure 3:
(a)
To: rkiesling@mainmatter.com,
     staff@mainmatter.com,
     info@mainmatter.com

(b)
rkiesling@mainmatter.com,staff@mainmatter.com,info@mainmatter.com

Example 1: 

sub rfc822_addr {
  my ($s) = @_;
  $s =~ s/<|>//g;
  my ($s1,$s2) = ($s =~ /(.*\s)*(.+\@.+)/ );
  $s2 =~ s/ |\t//g;
  $s = ( (defined $s1) ? "$s1 <$s2>" : "<$s2>");
  return $s;
q}

Example 2: 

sub unfold_field {
  my ($fieldname, @header) = @_;
  my (@unfolded, @field,$unfoldedfield,$header,$infield);
  $infield = 0;
  foreach my $l (@header) {
    if( $infield ) {
      if ( ($l) =~ /^([ \t]+.*?)/i ) {
 $l =~ s/^[ \t]+//;
 push @field, ($l);
      } else {
 $infield = 0;
      }
    } elsif( ($l) =~ /$fieldname\s(.*)/i ) {
      push @field, ($1);
      $infield = 1;
    }
  }
  $unfoldedfield = join "\n ", @field;
  $unfoldedfield =~ s/\n\s+/, /g;
  return $unfoldedfield;
}

Example 3: 

  <rkiesling@mainmatter.com>,\
  <staff@mainmatter.com>,\
  <info@mainmatter.com>

Example 4:
(a)
my ($date,$mon,$year,$hour,$min,$sec,$tz) =
  ($ap =~
    m/.*?(\d+)\s*(\S*)\s*(\S*)\s*(\d*)\:(\d*)\:(\d*)\s*(\S*)/);

(b)
my ($weekday,$date,$mon,$year,$hour,$min,$sec,$tz) =
  ($ap =~
m/(\w\w\w\),\s(\d+)\s*(\S*)\s*(\S*)\s*(\d*)\:(\d*)\:(\d*)\s*(\S*)/);





2

