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

SF.net SVN: ledger-smb:[3324] trunk/LedgerSMB/Mailer.pm



Revision: 3324
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=3324&view=rev
Author:   ehuelsmann
Date:     2011-06-24 14:52:19 +0000 (Fri, 24 Jun 2011)

Log Message:
-----------
Clean up Mailer::attach().

Patch by: John Locke
Tweaked by: me

Modified Paths:
--------------
    trunk/LedgerSMB/Mailer.pm

Modified: trunk/LedgerSMB/Mailer.pm
===================================================================
--- trunk/LedgerSMB/Mailer.pm	2011-06-24 14:39:50 UTC (rev 3323)
+++ trunk/LedgerSMB/Mailer.pm	2011-06-24 14:52:19 UTC (rev 3324)
@@ -143,12 +143,13 @@
 	$self->{_message}->binmode(':utf8');
 }
 
-=head2 $mail->attach(data => $data, filename => $name, strip => $strip)
+=head2 $mail->attach(data => $data, file => $file,
+                     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.
+given by $file.  If both a file and data are given, the data is attached.
+filename must be given and is used to name the attachment.
 
 $strip is an optional string to remove from the filename send with the
 attachment.
@@ -160,22 +161,23 @@
 	my %args = @_;
 
 	carp "Message not prepared" unless ref $self->{_message};
-	if (defined $args{filename}) {
-		if (!$args{filename}){
+	if (defined $args{file}) {
+		if (!$args{file}){
 			carp "Invalid filename provided";
-		} elsif (!defined $args{data} and !(-f $args{filename} and -r $args{filename})){
-			carp "Cannot access file: $args{filename}";
+		} elsif (!defined $args{data}
+			 and !(-f $args{file} and -r $args{file})){
+			carp "Cannot access file: $args{file}";
 		}
 	} else {
 		carp "No attachement supplied" unless defined $args{data};
 	}
 
 	# strip path from output name
-	my $file;
+	my $filename;
 	if ($args{filename}) {
 		my $strip = quotemeta $args{strip};
-		$file = $args{filename};
-		$file =~ s/(.*\/|$strip)//g;
+		$filename = $args{filename};
+		$filename =~ s/(.*\/|$strip)//g;
         }
 
 	# handle both string and file types of input
@@ -188,7 +190,7 @@
 
 	$self->{_message}->attach(
 		'Type' => $args{mimetype},
-		'Filename' => $file,
+		'Filename' => $filename,
 		'Disposition' => 'attachment',
 		@data,
 		);


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