# New Ticket Created by  Hanno Hecker 
# Please include the string:  [perl #38747]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/rt3/Ticket/Display.html?id=38747 >


This patch adjusts the parsing of the RCPT TO command to the same
behaviour as the MAIL FROM. 
There's one issue, which is also present in the mail from parser: mails
without surrounding <> are not parsed correctly if it contains spaces. 
Suggestion is not to accept addresses without <> in mail() and rcpt().

        Hanno
--- lib/Qpsmtpd/SMTP.pm.orig    2006-03-04 08:36:21.000000000 +0100
+++ lib/Qpsmtpd/SMTP.pm 2006-03-04 09:21:46.000000000 +0100
@@ -335,14 +335,22 @@
   my $self = shift;
   return $self->respond(501, "syntax error in parameters") unless $_[0] and 
$_[0] =~ m/^to:/i;
   return $self->respond(503, "Use MAIL before RCPT") unless 
$self->transaction->sender;
+  my $rcpt_parameter = join " ", @_;
+  my ($rcpt) = ($rcpt_parameter =~ m/^to:\s*(<[^>]*>)/i)[0];
+  # support addresses without <> ... maybe we shouldn't?
+  ($rcpt) = "<" . ($rcpt_parameter =~ m/^to:\s*(\S+)/i)[0] . ">"
+      unless $rcpt;
 
-  my ($rcpt) = ($_[0] =~ m/to:(.*)/i)[0];
-  $rcpt = $_[1] unless $rcpt;
   $self->log(LOGALERT, "to email address : [$rcpt]");
-  $rcpt = (Qpsmtpd::Address->parse($rcpt))[0];
 
+
+  $rcpt = (Qpsmtpd::Address->parse($rcpt))[0];
+  ### does this one ever happen?
   return $self->respond(501, "could not parse recipient") unless $rcpt;
 
+  return $self->respond(501, "cound not parse recipient") 
+    if $rcpt->format eq '<>';
+
   my ($rc, $msg) = $self->run_hooks("rcpt", $rcpt);
   if ($rc == DONE) {
     return 1;

Reply via email to