[MKDoc-modules] Petal::Mail usage

William McKee william at knowmad.com
Fri Dec 12 17:52:57 GMT 2003


On Fri, Dec 12, 2003 at 04:57:36PM +0000, Jean-Michel Hiver wrote:
> Well, there's not many people on the mkdoc-modules list... I must said
> that I haven't been promoting it very much.

Too bad there's not more. It sounds like you could definitely use the
help. I feel for you having to refactor the MKDoc codebase. I'm doing
the same to one of my older projects which is probably not a tenth the
size of MKDoc and it ain't easy!


> > While testing, I had problems with Taint again. Specifically at line 63
> > in Petal/Cache/Disk.pm. I tried setting $Petal::TAINT=1 but that did not
> > help. I'm not going to debug this problem right now; just wanted to note
> > it. Well, nix that; it's working now. Not sure what changed though which
> > worries me a bit.
> 
> ??

Yeah, it appears to have something to do with how the file cache is
written. If I run the script without taintchecking then I can run it
safely with taintchecking (until I change the file on disk). Like I
said, I'm not going to worry about debugging it now. Just wanted to make
a note of it.


> > 	- there is no documentation for the send function
> 
> That's because it's _exactly_ the same arguments as process(). All it
> does is call process() and dump the results into sendmail...

However, there appears to be a bug in it. You call $$self. Perl says
this value doesn't exist. I replaced that with $mail and it worked.
Also, I like to be able to pass in arguments to methods rather than via
the environment. Thus, I've modifed the send() function to accept an
authorized sender value. I'm sure there are more elegant ways to handle
this but I think you'll see what I'm trying to achieve from the patch
(btw, this patch is a superset of the previous one; best apply it to a
clean Mail.pm file from the 0.1 release).

Also, I created a new test for the send function. It needs some work but
contains the basic tests--it would be nice if it would ask for a real
email address and then use that. It would also be nice to allow the user
to skip this test if they didn't want it. I'm not sure how to do that in
the tests yet so would appreciate some pointers or a patch.


Thanks,
William

-- 
Knowmad Services Inc.
http://www.knowmad.com
-------------- next part --------------
7a8
>   use Petal::Mail;
58a60,68
> =head1 FUNCTIONS
> 
> =head2 process
> 
> This function processes a template. It takes a hash or hashref which is used
> to fill out any elements in the template. It returns the processed template as
> a string. See L<Petal> for further details.
> 
> =cut
66a77,87
> =head2 send
> 
> This function processes a template and sends an email message according to the
> headers in the template.  It takes the same parameters as process in addition
> to the email address of the authorized sender. The authorized sender may also
> be set with the environment parameter 'SERVER_ADMIN'. Returns null on success
> or dies on failure.
> 
> 	$petal_mail->send(AUTH_SENDER => 'lewis at carroll.net', %args);
> 
> =cut
70,73c91,97
<     my $mail = $self->process (@_)                       || die '$self->process (\@_) returned undef';
<     $ENV{SERVER_ADMIN}                                   || die '$ENV{SERVER_ADMIN} not set';
<     open (SENDMAIL, "| $Sendmail -f $ENV{SERVER_ADMIN}") || die "error opening sendmail [$Sendmail]: $!";
<     print SENDMAIL $$self                                || die "error writing to sendmail [$Sendmail]: $!";
---
> 	my %args = @_;
> 	my $authorized_sender = $args{'AUTH_SENDER'} || $ENV{SERVER_ADMIN} || '';
> 	delete $args{'AUTH_SENDER'};
>     $authorized_sender									 || die 'No authorized sender defined and $ENV{SERVER_ADMIN} not set';
>     my $mail = $self->process (%args)                    || die '$self->process (\@_) returned undef';
>     open (SENDMAIL, "| $Sendmail -f $authorized_sender") || die "error opening sendmail [$Sendmail]: $!";
>     print SENDMAIL $mail                                 || die "error writing to sendmail [$Sendmail]: $!";
352a377,381
> =back
> 
> Text contained in <p> tags will ignore white space characters (e.g., extra
> spaces, tabs, carriage returns, etc.). See the XHTML specs at W3C for complete
> details-- http://www.w3.org/MarkUp/.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 002_Sendmail.t
Type: application/x-troff
Size: 425 bytes
Desc: not available
Url : http://lists.webarch.co.uk/pipermail/mkdoc-modules/attachments/20031212/9ead32d3/002_Sendmail.t


More information about the MKDoc-modules mailing list