summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortetragon <tetragon@4979c152-3d1c-0410-bac9-87ea11338e46>2007-10-22 20:20:29 +0000
committertetragon <tetragon@4979c152-3d1c-0410-bac9-87ea11338e46>2007-10-22 20:20:29 +0000
commit93ce762595a4687a446fbf1c405929f37986c2eb (patch)
tree26a5dad94b72e265ab127cd4ed0a58653743bb7c
parent9c5936b5c08ce952ff7c06008219dca0ba525f76 (diff)
Adding more POD to LSMB::M
git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@1805 4979c152-3d1c-0410-bac9-87ea11338e46
-rw-r--r--LedgerSMB/Mailer.pm59
-rw-r--r--t/98-pod-coverage.t3
2 files changed, 56 insertions, 6 deletions
diff --git a/LedgerSMB/Mailer.pm b/LedgerSMB/Mailer.pm
index a650d4e1..4903b629 100644
--- a/LedgerSMB/Mailer.pm
+++ b/LedgerSMB/Mailer.pm
@@ -50,10 +50,10 @@ use LedgerSMB::Sysconfig;
our $VERSION = '0.13';
-=head2 LedgerSMB::Mailer->new([%args])
+=head2 LedgerSMB::Mailer->new(...)
Create a new Mailer object. If any arguments are passed in, a message
-that uses them will be automatically prepared.
+that uses them will be automatically prepared but not sent.
=cut
@@ -67,7 +67,36 @@ sub new {
$self;
}
-=head2 $mail->prepare_message
+=head2 $mail->prepare_message(to => $to, from => $from, ...)
+
+Prepares and encodes base message for sending or adding attachments.
+
+=head3 Arguments
+
+=over
+
+=item to, from, cc, bcc
+
+Address fields for the email.
+
+=item subject
+
+The subject for the email.
+
+=item message
+
+The message body for the email.
+
+=item contenttype
+
+The conttent type for the body of the message, not for any attachments.
+
+=item notify
+
+Sets the Disposition-Notification-To header (read receipt request) for the
+message. This header will only be added if a from address is set.
+
+=back
=cut
@@ -114,7 +143,15 @@ sub prepare_message {
$self->{_message}->binmode(':utf8');
}
-=head2 $mail->attach
+=head2 $mail->attach(data => $data, filename => $name, strip => $strip)
+
+Add an attachment to the prepared message. If $data is specified, use the
+value of that variable as the attachment value, otherwise attach the file
+given by $name. If both a filename and data are given, the data is attached
+and given the name from filename.
+
+$strip is an optional string to remove from the filename send with the
+attachment.
=cut
@@ -123,6 +160,15 @@ sub attach {
my %args = @_;
carp "Message not prepared" unless ref $self->{_message};
+ if (defined $args{filename}) {
+ if (!$args{filename}){
+ carp "Invalid filename provided";
+ } elsif (!defined $args{data} and !(-f $args{filename} and -r $args{filename})){
+ carp "Cannot access file: $args{filename}";
+ }
+ } else {
+ carp "No attachement supplied" unless defined $args{data};
+ }
# strip path from output name
my $file;
@@ -134,7 +180,7 @@ sub attach {
# handle both string and file types of input
my @data;
- if ($args{data}) {
+ if (defined $args{data}) {
@data = ('Data', $args{data});
} else {
@data = ('Path', $args{filename});
@@ -158,6 +204,9 @@ sub send {
my $self = shift;
carp "Message not prepared" unless ref $self->{_message};
+ # SC: Set the X-Mailer header here so that it will be the last
+ # header set. This ensures that MIME::Lite will not rewrite
+ # it during the preparation of the message.
$self->{_message}->replace( 'X-Mailer' => "LedgerSMB::Mailer $VERSION" );
if ( ${LedgerSMB::Sysconfig::smtphost} ) {
$self->{_message}->send(
diff --git a/t/98-pod-coverage.t b/t/98-pod-coverage.t
index bba38dd8..c7f80cd5 100644
--- a/t/98-pod-coverage.t
+++ b/t/98-pod-coverage.t
@@ -8,7 +8,7 @@
use strict;
use warnings;
-use Test::More tests => 14;
+use Test::More tests => 15;
use Test::More;
eval "use Test::Pod::Coverage";
plan skip_all => "Test::Pod::Coverage required for testing POD coverage" if $@;
@@ -19,6 +19,7 @@ pod_coverage_ok("LedgerSMB::AM");
pod_coverage_ok("LedgerSMB::Database");
pod_coverage_ok("LedgerSMB::Locale");
pod_coverage_ok("LedgerSMB::Log");
+pod_coverage_ok("LedgerSMB::Mailer");
pod_coverage_ok("LedgerSMB::Template");
pod_coverage_ok("LedgerSMB::Template::CSV");
pod_coverage_ok("LedgerSMB::Template::HTML");