[Solar-talk] Solar_Mail, take 2

Paul M Jones pmjones at ciaweb.net
Sat Mar 31 12:36:30 PDT 2007


Hey guys --

Not trying to steal the thunder on Antti's work with Abovo_Mail, but  
I have done a thorough extraction, refactoring, and modification of  
Zend_Mail and related components into a series of Solar components.   
The Solar code now in Subversion, I hope it is needless to say, is  
much cleaner and easier to follow than the Zend code; anything  
remaining from Zend should be unrecognizable.

The easier part was re-doing the SMTP client; that's at Solar_Smtp.   
There are adapters for various kinds of SMTP authentication  
(including "no authentication" by default).

More difficult was recombining the Mime and Message classes into  
something less complex and more coherent; you can see the results at  
Solar_Mail_Message. Example usage looks something like this (pretty  
standard stuff) --

     // create a message
     $mail = Solar::factory('Solar_Mail_Message');

     // headers
     $mail->setFrom('pmjones at solarphp.com');
     $mail->addTo('solar-talk at lists.solarphp.com', 'Solar-Talk List');
     $mail->setSubject('This is a test.');

     // alternative parts
     $mail->setText('This is **only** a test.');
     $mail->setHtml('<p>This is <b>only</b> a test.</p>');

     // attach an image file
     $mail->attachFile('/path/to/test-image.jpg', 'image/jpeg');

     // create a transport for the message, and send it.
     $transport = Solar::factory('Solar_Mail_Transport', array(
         'adapter' => 'Solar_Mail_Transport_Adapter_Smtp',
     ));

     $transport->send($mail);

One of the nicer adaptations is that we use what I think is better  
header escaping than Zend.  Also, we're using streams for quoted- 
printable encoding instead of userland code.

I remember there were some character-set issues you guys were talking  
about back in January; let me know if the new Solar_Mail code does/ 
does-not have the same problems.

Would be happy to hear what can be improved or fixed, and I it proves  
useful for everyone.


--

Paul M. Jones  <http://paul-m-jones.com>

Solar: Simple Object Library and Application Repository
for PHP5.   <http://solarphp.com>

Savant: The simple, elegant, and powerful solution for
templates in PHP.   <http://phpsavant.com>




More information about the solar-talk mailing list