ironcamel / Dancer-Plugin-Email

Simple email sending for Dancer
http://p3rl.org/Dancer::Plugin::Email
6 stars 10 forks source link

Suggestion: New driver #1

Closed sgnix closed 13 years ago

sgnix commented 13 years ago

To make the developing of your app easier, let's add a new email driver - 'logfile'. What it does is it dumps the entire email body in the log file. This way you can set this in your developement.yml and monitor the emails you send, w/o actually sending them. I've already added this to my local copy of the plugin. It would be great if you think it's a good idea and add it to the distribution:

$ diff -wu Email.pm{~,}
--- Email.pm~   2011-02-17 21:08:54.076462280 -0800
+++ Email.pm    2011-02-17 21:10:20.877080171 -0800
@@ -127,9 +127,17 @@
         if (lc($settings->{driver}) eq lc("nntp")) {
             $self->{send_using} = ['NNTP', $settings->{host}];
         }
+        my $to_logfile = 0;
+        if ( lc( $settings->{driver} eq lc("logfile") ) ) {
+            debug "\n --- EMAIL --- \n" . $self->as_string . "\n --- END EMAIL --- \n";
+            $to_logfile = 1;
+        }
         my $email = $self->email or return undef;
+
         # die Dumper $email->as_string;
-        return $self->mailer->send( $email );
+        return $to_logfile 
+            ? $self->as_string 
+            : $self->mailer->send($email);
     }
     else {
         $self->using(@arguments) if @arguments; # Arguments passed to ->using
ironcamel commented 13 years ago

Thanks naturalist. I am fine with adding this feature. My concern is that alnewkirk has been wanting to refactor this entire plugin to use his Emailesque module (http://p3rl.org/Emailesque). Lets include him in this discussion and see what he thinks.

alnewkirk commented 13 years ago

I think this is a great idea, i will add this to Emailesque and then push both Emailesque and Dancer::Plugin::Email to CPAN once properly tested.

ironcamel commented 13 years ago

Al, before you push the refactored Dancer::Plugin::Email to cpan, please let me test it on my box first. Last time I tried Emailesque, it didn't work. Also, it would be great if naturalist could test it as well.

sgnix commented 13 years ago

I'll test alright. I'm not sure why we're switching to Emailesque, though. It still uses Email::Stuff. Why do we need another wrapper?

ironcamel commented 13 years ago

The purpose of Emailesque is to be able to use the nice interface Dancer::Plugin::Email provides inside of non-Dancer applications. I'm going to close this issue now. If you would like this patch to go in D::P::Email, send it to me as a pull request. Al and I can figure out how to merge this project with Emailesque when the time comes.