summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfukachan <fukachan>2004-01-02 16:07:23 +0000
committerfukachan <fukachan>2004-01-02 16:07:23 +0000
commit616f369d353e5a238348bc14e4b342d597d12508 (patch)
tree50b70fe943e02cf44741e04bd87ebab8d979f5a1
parentdf354c66aa759a61abde82a615c0fc2e30d53a4f (diff)
downloadfml8-616f369d353e5a238348bc14e4b342d597d12508.tar.gz
fml8-616f369d353e5a238348bc14e4b342d597d12508.tar.bz2
fml8-616f369d353e5a238348bc14e4b342d597d12508.zip
more strict error checks.
fix comments.
-rw-r--r--fml/lib/FML/Mailer.pm43
1 files changed, 30 insertions, 13 deletions
diff --git a/fml/lib/FML/Mailer.pm b/fml/lib/FML/Mailer.pm
index cd74594c..f10a149c 100644
--- a/fml/lib/FML/Mailer.pm
+++ b/fml/lib/FML/Mailer.pm
@@ -4,7 +4,7 @@
# All rights reserved. This program is free software; you can
# redistribute it and/or modify it under the same terms as Perl itself.
#
-# $FML: Mailer.pm,v 1.24 2004/01/02 10:23:55 fukachan Exp $
+# $FML: Mailer.pm,v 1.25 2004/01/02 14:50:28 fukachan Exp $
#
package FML::Mailer;
@@ -28,7 +28,7 @@ FML::Mailer - utilities to send mails
});
where C<$message> is a C<Mail::Message> object to send.
-If you want to sent plural recipinets,
+If you want to sent to plural recipinets,
specify the recipients as ARRAY REFERENCE at C<recipients> parameter.
$obj->send( {
@@ -49,7 +49,7 @@ If you send a file, you can specify the filename as a data to send.
=head1 DESCRIPTION
-It sends Mail::Message objects.
+This module sends Mail::Message object(s).
=head1 METHODS
@@ -76,14 +76,14 @@ sub new
=head2 send($send_args)
send the given C<message>.
-$send_args can take the following arguments:
+$send_args (HASH_REF) can take the following arguments:
----------------------------------
- sender string
- recipient string
+ sender STR
+ recipient STR
recipients ARRAY_REF
- message Mail::Message object
- file string
+ message Mail::Message OBJ
+ file STR
=cut
@@ -126,7 +126,7 @@ sub send
}
# 1. sender
- my $sender = (defined $send_args->{sender} ? $send_args->{sender} : $maintainer);
+ my $sender = $send_args->{sender} || $maintainer || '';
unless ($sender) {
$curproc->logerror("FML::Mailer: no sender");
return 0;
@@ -135,22 +135,39 @@ sub send
# 2. recipient(s)
my $recipients = [];
if (defined $send_args->{ recipients }) { # ARRAY_REF
- $recipients = $send_args->{ recipients };
+ if (ref($send_args->{ recipients }) eq 'ARRAY') {
+ $recipients = $send_args->{ recipients };
+ }
+ else {
+ $curproc->logerror("FML::Mailer: invalid type: recipients");
+ $recipients = [];
+ }
}
elsif (defined $send_args->{ recipient }) { # STR
- my $recipient = $send_args->{ recipient };
- $recipients = [ $recipient ];
+ unless (ref($send_args->{ recipient })) {
+ my $recipient = $send_args->{ recipient };
+ $recipients = [ $recipient ];
+ }
+ else {
+ $curproc->logerror("FML::Mailer: invalid type: recipient");
+ $recipients = [];
+ }
}
else {
$curproc->logerror("FML::Mailer: no recipient(s)");
return 0;
}
+ unless (@$recipients) {
+ $curproc->logerror("FML::Mailer: no recipient(s)");
+ return 0;
+ }
+
# 3. message
my $message = undef;
# 3.1 message object
- if (defined($send_args->{ message })) {
+ if (defined($send_args->{ message }) && ref($send_args->{ message })) {
$message = $send_args->{ message };
}
else {