[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SF.net SVN: ledger-smb: [1805] trunk



Revision: 1805
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=1805&view=rev
Author:   tetragon
Date:     2007-10-22 13:20:29 -0700 (Mon, 22 Oct 2007)

Log Message:
-----------
Adding more POD to LSMB::M

Modified Paths:
--------------
    trunk/LedgerSMB/Mailer.pm
    trunk/t/98-pod-coverage.t

Modified: trunk/LedgerSMB/Mailer.pm
===================================================================
--- trunk/LedgerSMB/Mailer.pm	2007-10-22 19:44:33 UTC (rev 1804)
+++ trunk/LedgerSMB/Mailer.pm	2007-10-22 20:20:29 UTC (rev 1805)
@@ -50,10 +50,10 @@
 
 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,8 +67,37 @@
 	$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
 
 sub prepare_message {
@@ -114,8 +143,16 @@
 	$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
 
 sub attach {
@@ -123,6 +160,15 @@
 	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 @@
 
 	# 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 @@
 	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(

Modified: trunk/t/98-pod-coverage.t
===================================================================
--- trunk/t/98-pod-coverage.t	2007-10-22 19:44:33 UTC (rev 1804)
+++ trunk/t/98-pod-coverage.t	2007-10-22 20:20:29 UTC (rev 1805)
@@ -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::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");


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.