Net::SMTP and orcpt

M

Matthew Braid

Hi all,

I'm using Net::SMTP in a maillist manager, and I need to add some basic
bounce-handling. I've decided to use the orcpt option in the rcpt
commands, but I can't figure out how to do so.

I looked at Net::SMTP's code and fiddled a bit, and added some code to
the recipient function to accept address-specific options (at the moment
just Original => addr) so you can do something like:

$smtp->recipient(['(e-mail address removed)',
{Original => '(e-mail address removed)'}]);

which would generate a rcpt to line like:

rcpt to:<[email protected]> orcpt=rfc822;[email protected]

It will do the correct + quoting that is required for orcpt, eg +, =,
ascii < 33, ascii > 126 become +ORD, where ORD is the 2 digit hex
representation of ord(char), and it will carp if ESMTP is not supported
(in the same fashion as the rest of Net::SMTP).

I haven't tested it yet, but attached is a patch I made. Any comments?

MB

--- SMTP.pm Wed Jan 14 11:41:34 2004
+++ /usr/local/lib/perl5/5.8.1/Net/SMTP.pm Thu Oct 16 10:38:45 2003
@@ -327,20 +327,6 @@
$me->_RSET();
}

-sub _orcpt {
- my $self = shift;
- my $orig = shift;
- my $ret = ' orcpt=rfc822;';
- for my $i (1..length($orig)) {
- my $char = substr($orig, $i - 1, 1);
- if ($char eq '=' or $char eq '+' or ord($char) < 33 or ord($char) > 126) {
- $ret .= sprintf('+%02x', ord($char));
- } else {
- $ret .= $char;
- }
- }
- return $ret;
-}

sub recipient
{
@@ -370,6 +356,7 @@
carp 'Net::SMTP::recipient: DSN option not supported by host';
}
}
+
carp 'Net::SMTP::recipient: unknown option(s) '
. join(" ", keys %opt)
. ' - ignored'
@@ -385,23 +372,7 @@
my $addr;
foreach $addr (@_)
{
- my ($raddr, $aopts) = ('', ' ');
- if (ref($addr) eq 'ARRAY') {
- if (not exists $esmtp->{DSN}) {
- carp 'Net::SMTP::recipient: ESMTP not supported by host - address options discarded';
- $raddr = $addr->[0];
- } else {
- my $opth;
- ($raddr, $opta) = @$addr;
- my $orig = delete($opta->{Original});
- $aopts .= _orcpt($smtp, $orig) if defined $orig;
- carp 'Net::SMTP::recipient: unknown address option(s) ' .
- join(' ', keys %$opta) . ' - ignored' if scalar keys %$opta;
- }
- } else {
- $raddr = $addr;
- }
- if($smtp->_RCPT("TO:" . _addr($smtp, $raddr) . $opts . $aopts)) {
+ if($smtp->_RCPT("TO:" . _addr($smtp, $addr) . $opts)) {
push(@ok,$addr) if $skip_bad;
}
elsif(!$skip_bad) {
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top