[Mew-dist 12316] Re: im-13[5-7] imput error
Koyama Mituru
mkoya at example.com
2000年 2月 9日 (水) 21:22:20 JST
小山です。
From: Hajimu UMEMOTO (梅本 肇) <ume at example.com>
Subject: [Mew-dist 12312] Re: im-13[5-7] imput error
Date: Wed, 9 Feb 2000 16:39:08 +0900
> ksakai> ! for (my $i = 0; $i <= $#Smtp_servers; $i++) {
>
> 何か 1 回回りすぎてません? $i < $#Smtp_servers のような?
オリジナルのIM-137から、[12245], [12282], [12310]とimputの2か所
の$i<=$#Smtp_serversの部分の修正を統合した以下のパッチで動作してい
ます。
----
小山満 mkoya at example.com
-------------- next part --------------
diff -urN im-137/IM/Smtp.pm myim-137/IM/Smtp.pm
--- im-137/IM/Smtp.pm Fri Jan 28 12:27:22 2000
+++ myim-137/IM/Smtp.pm Wed Feb 9 20:51:08 2000
@@ -34,7 +34,7 @@
=head1 SYNOPSIS
-$return_code = &smtp_open(log_flag);
+$return_code = &smtp_open(current_server, server_list, log_flag);
$return_code = &smtp_close(socket, savehist_flag);
$return_code = &smtp_transaction(bcc_flag, part_current, part_total);
$return_code = &smtp_transaction_for_error_notify;
@@ -47,7 +47,8 @@
$Esmtp_flag %ESMTP);
##### SMTP SESSION OPENING #####
#
-# smtp_open(server_list, log_flag)
+# smtp_open(server, server_list, log_flag)
+# server: current server
# server_list:
# log_flag: conversations are saved in $Session_log if true
# return value:
@@ -55,14 +56,14 @@
# 1: recoverable error (should be retried)
# -1: unrecoverable error
#
-sub smtp_open ($$) {
- my ($servers, $logging) = @_;
+sub smtp_open ($$$) {
+ my ($server, $server_list, $logging) = @_;
local $_;
my $rc;
my $svr = &get_cur_server_original_form();
@Status =();
if ($Smtp_opened) {
- if (grep {$svr eq $_} @$servers) {
+ if (grep {$svr eq $_} @$server_list) {
im_notice("resetting SMTP session.\n");
return 0 unless (&tcp_command(\*SMTPd, 'RSET', ''));
}
@@ -70,7 +71,8 @@
# return 1;
}
&tcp_logging($logging);
- *SMTPd = &connect_server($servers, 'smtp', 0);
+ my @s = ($server);
+ *SMTPd = &connect_server(\@s, 'smtp', 0);
return 1 if ($SMTPd eq '');
$SmtpErrTitle = "(while talking to " . &get_cur_server() . " with smtp)\n";
return $rc if ($rc = &tcp_command(\*SMTPd, '', ''));
@@ -138,35 +140,39 @@
sub smtp_transaction ($$$$$$) {
my ($servers, $Header, $Body, $bcc, $part, $total) = @_;
my $rc;
- do {
- $rc = &smtp_transact_sub($servers, $Header, $Body, $bcc, $part,$total);
- $rc = 1 if ($rc == -1 && $#$servers >= 0 && $main::Smtp_fatal_next);
- my (@resp) = &command_response;
- if ($rc > 0 && $#$servers >= 0) {
- # close and try the next server if TEMPFAIL
- &smtp_close;
- &log_action($Esmtp_flag ? 'esmtp' : 'smtp', &get_cur_server(),
- join(',', @main::Recipients), 'skipped', @resp);
- } elsif ($rc < 0 || $rc > 0 && $#$servers < 0) {
- # log if fatal or the last server
-# &smtp_close(1, 0);
- &log_action($Esmtp_flag ? 'esmtp' : 'smtp', &get_cur_server(),
- join(',', @main::Recipients), 'failed', @resp);
- }
- if ($rc) {
- my (@resp) = &command_response;
- im_warn($SmtpErrTitle . join("\n", @resp) . "\n");
- $SmtpErrTitle = '';
- }
- return -1 if ($rc < 0);
- } while ($rc != 0 && $#$servers >= 0);
+ my $fatal_error = 0;
+
+ for (my $i = 0; $i <= $#$servers; $i++) {
+ $rc = smtp_transact_sub(@$servers[$i], $servers, $Header, $Body,
+ $bcc, $part, $total);
+ return 0 if ($rc == 0);
+
+ if (($rc < 0 && !$main::Smtp_fatal_next) || $#$servers == $i) {
+ # fatal error or the last server
+ $fatal_error = 1;
+ }
+
+ # close and try the next server if TEMPFAIL
+ smtp_close() unless ($fatal_error);
+
+ log_action($Esmtp_flag ? 'esmtp' : 'smtp', get_cur_server(),
+ join(',', @main::Recipients),
+ $fatal_error ? 'failed' : 'skipped', command_response());
+ im_warn($SmtpErrTitle . join("\n", command_response()) . "\n");
+ $SmtpErrTitle = '';
+
+ return $rc if ($fatal_error);
+ }
return $rc;
}
##### SMTP TRANSACTION MANAGEMENT SUBROUTUNE #####
#
-# smtp_transact_sub(server_list, bcc_flag, part, total)
+# smtp_transact_sub(server, server_list, header, body, bcc_flag, part, total)
+# server: current server
# server_list:
+# header:
+# body:
# bcc_flag: send message in "bcc" style
# part: part number to be sent in partial message mode
# total: total number of partial messages
@@ -175,10 +181,10 @@
# 1: recoverable error (should be retried)
# -1: unrecoverable error
#
-sub smtp_transact_sub ($$$$$$) {
- my ($servers, $Header, $Body, $bcc, $part, $total) = @_;
+sub smtp_transact_sub ($$$$$$$) {
+ my ($server, $server_list, $Header, $Body, $bcc, $part, $total) = @_;
my ($i, $rc, $fail, @fatal, $msg_size, $btype);
- return $rc if ($rc = &smtp_open($servers, 1));
+ return $rc if ($rc = smtp_open($server, $server_list, 1));
if ($ESMTP{'8BITMIME'} && $main::Has_8bit_body && !$main::do_conv_8to7) {
$btype = ' BODY=8BIT';
} else {
@@ -260,20 +266,23 @@
##### SMTP TRANSACTION MANAGEMENT FOR RETURN ERROR NOTIFY #####
#
-# smtp_transaction_for_error_notify(server_list)
+# smtp_transaction_for_error_notify(server, server_list, header, body)
+# server: current server
# server_list:
+# header:
+# body:
# return value:
# 0: success
# 1: recoverable error (should be retried)
# -1: unrecoverable error
#
-sub smtp_transaction_for_error_notify ($$$) {
- my ($servers, $Header, $Body) = @_;
+sub smtp_transaction_for_error_notify ($$$$) {
+ my ($server, $servers, $Header, $Body) = @_;
my ($rc, @prev_rcpt, @prev_stat);
@prev_rcpt = @main::Recipients;
@prev_stat = @Status;
@main::Recipients = ($main::Sender);
- return $rc if ($rc = &smtp_open($servers, 0));
+ return $rc if ($rc = &smtp_open($server, $servers, 0));
return $rc if ($rc = &tcp_command(\*SMTPd, "MAIL FROM:<>", ''));
return $rc if ($rc = &tcp_command(\*SMTPd, "RCPT TO:<$main::Sender>", ''));
return $rc if ($rc = &tcp_command(\*SMTPd, 'DATA', ''));
diff -urN im-137/IM/TcpTransaction.pm myim-137/IM/TcpTransaction.pm
--- im-137/IM/TcpTransaction.pm Fri Jan 28 12:27:22 2000
+++ myim-137/IM/TcpTransaction.pm Wed Feb 9 20:51:43 2000
@@ -89,7 +89,7 @@
if ($s =~ s/\/(\d+)$//) {
$remoteport = $1;
} else {
- $remoteport = $serv;
+ next unless ($remoteport = getserv($serv, 'tcp'));
}
if ($main::SSH_server eq 'localhost') {
im_warn( "Don't use port-forwarding to `localhost'.\n" );
@@ -437,35 +437,13 @@
my ($node, $serv, $family, $socktype, $proto, $flags) = @_;
- my ($pe_name, $pe_aliases, $pe_proto);
- my ($se_name, $se_aliases, $se_port);
+ my ($pe_name, $pe_aliases, $pe_proto, $se_port);
if (unixp()) {
$proto = 'tcp' unless ($proto);
($pe_name, $pe_aliases, $pe_proto) = getprotobyname($proto);
}
$pe_proto = 6 unless ($pe_name);
- if ($serv =~ /^\d+$/o) {
- $se_port = $serv;
- } else {
- ($se_name, $se_aliases, $se_port) = getservbyname($serv, $proto)
- if (unixp());
- unless ($se_name) {
- if ($serv eq 'smtp') {
- $se_port = 25;
- } elsif ($serv eq 'http') {
- $se_port = 80;
- } elsif ($serv eq 'nntp') {
- $se_port = 119;
- } elsif ($serv eq 'pop3') {
- $se_port = 110;
- } elsif ($serv eq 'imap') {
- $se_port = 143;
- } else {
- im_err("unknown service: $serv\n");
- return undef;
- }
- }
- }
+ return unless ($se_port = getserv($serv, $proto));
my ($he_name, $he_alias, $he_type, $he_len, @he_addrs);
if ($node =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/) {
@@ -474,7 +452,7 @@
} elsif ($node =~ /^[\da-f:]+$/i) {
if ($node =~ /::.*::/) {
im_err("bad server address in IPv6 format: $node\n");
- return undef;
+ return;
}
if ($node =~ /::/) {
(my $t = $node) =~ s/[^:]//g;
@@ -492,14 +470,14 @@
$family = inet6_family(); # AF_INET6
} else {
im_err("bad server address in IPv6 format: $node\n");
- return undef;
+ return;
}
} else {
alarm(dns_timeout()) unless win95p();
($he_name, $he_alias, $he_type, $he_len, @he_addrs)
= gethostbyname($node);
alarm(0) unless win95p();
- return undef unless ($he_name);
+ return unless ($he_name);
$family = $he_type;
}
@@ -514,6 +492,36 @@
push(@infos, $family, $socktype, $pe_proto, $sin, $he_name);
}
@infos;
+}
+
+sub getserv($$) {
+ my ($serv, $proto) = @_;
+
+ my ($se_port);
+ if ($serv =~ /^\d+$/o) {
+ $se_port = $serv;
+ } else {
+ my ($se_name, $se_aliases);
+ ($se_name, $se_aliases, $se_port) = getservbyname($serv, $proto)
+ if (unixp());
+ unless ($se_name) {
+ if ($serv eq 'smtp') {
+ $se_port = 25;
+ } elsif ($serv eq 'http') {
+ $se_port = 80;
+ } elsif ($serv eq 'nntp') {
+ $se_port = 119;
+ } elsif ($serv eq 'pop3') {
+ $se_port = 110;
+ } elsif ($serv eq 'imap') {
+ $se_port = 143;
+ } else {
+ im_err("unknown service: $serv\n");
+ return undef;
+ }
+ }
+ }
+ $se_port;
}
sub inet6_pack_sockaddr_in6 ($;$) {
diff -urN im-137/imput.in myim-137/imput.in
--- im-137/imput.in Fri Jan 28 12:27:20 2000
+++ myim-137/imput.in Wed Feb 9 20:54:13 2000
@@ -13,7 +13,7 @@
@im_src_siteperl@
};
-$VERSION = "imput version 20000113(IM136)";
+$VERSION = "imput version 20000128(IM137)";
$Prog = 'imput';
@@ -1942,16 +1942,15 @@
@Smtp_servers = split(',', $Smtp_servers);
push(@Smtp_servers, split(',', $Emg_Smtp_servers));
- do {
- $rc = &smtp_transaction_for_error_notify(\@Smtp_servers,
- \@Header, \@Body);
- if ($rc) {
- &smtp_close;
- my @resp = &command_response;
- &log_action($Esmtp_flag ? 'esmtp' : 'smtp', &get_cur_server(),
- join(',', @Recipients), 'skipped', @resp);
- }
- } while ($rc > 0 && $#Smtp_servers >= 0);
+ for (my $i = 0; $i < $#Smtp_servers; $i++) {
+ $rc = smtp_transaction_for_error_notify($Smtp_servers[$i],
+ \@Smtp_servers, \@Header, \@Body);
+ return 0 if ($rc == 0);
+
+ smtp_close();
+ log_action($Esmtp_flag ? 'esmtp' : 'smtp', get_cur_server(),
+ join(',', @Recipients), 'skipped', command_response());
+ }
if ($rc) {
im_warn($errlog);
&set_command_response;
@@ -1979,17 +1978,16 @@
@Smtp_servers = split(',', $Smtp_servers);
push(@Smtp_servers, split(',', $Emg_Smtp_servers));
- do {
- $rc = &smtp_transaction_for_error_notify(\@Smtp_servers,
- \@Header, \@Body);
- if ($rc) {
- &smtp_close;
- my (@resp) = &command_response;
- &log_action($Esmtp_flag ? 'esmtp' : 'smtp', &get_cur_server(),
- join(',', @Recipients), 'skipped', @resp);
- }
+ for (my $i = 0; $i < $#Smtp_servers; $i++) {
+ $rc = &smtp_transaction_for_error_notify($Smtp_servers[$i],
+ \@Smtp_servers, \@Header, \@Body);
+ last if ($rc == 0);
+
+ smtp_close();
+ log_action($Esmtp_flag ? 'esmtp' : 'smtp', get_cur_server(),
+ join(',', @Recipients), 'skipped', command_response());
- } while ($rc > 0 && $#Smtp_servers >= 0);
+ }
if ($rc) {
# im_warn($errlog);
&set_command_response;
Mew-dist メーリングリストの案内