You are viewing a plain text version of this content. The canonical link for it is here.
Posted to site-dev@james.apache.org by ba...@apache.org on 2006/10/30 14:01:39 UTC

svn commit: r469138 [24/29] - in /james/site/trunk/www: ./ server/ server/2.2.0/ server/2.3.0/ server/2.3.0/apidocs/ server/2.3.0/apidocs/org/apache/james/ server/2.3.0/apidocs/org/apache/james/class-use/ server/2.3.0/apidocs/org/apache/james/context/ ...

Modified: james/site/trunk/www/server/2.3.0/xref/org/apache/james/transport/mailets/RemoteDelivery.html
URL: http://svn.apache.org/viewvc/james/site/trunk/www/server/2.3.0/xref/org/apache/james/transport/mailets/RemoteDelivery.html?view=diff&rev=469138&r1=469137&r2=469138
==============================================================================
--- james/site/trunk/www/server/2.3.0/xref/org/apache/james/transport/mailets/RemoteDelivery.html (original)
+++ james/site/trunk/www/server/2.3.0/xref/org/apache/james/transport/mailets/RemoteDelivery.html Mon Oct 30 04:59:35 2006
@@ -101,7 +101,7 @@
 <a name="92" href="#92">92</a>  <em> *</em>
 <a name="93" href="#93">93</a>  <em> * as well as other places.</em>
 <a name="94" href="#94">94</a>  <em> *</em>
-<a name="95" href="#95">95</a>  <em> * @version CVS $Revision: 428557 $ $Date: 2006-08-04 00:56:47 +0200 (ven, 04 ago 2006) $</em>
+<a name="95" href="#95">95</a>  <em> * @version CVS $Revision: 450877 $ $Date: 2006-09-28 16:49:38 +0200 (gio, 28 set 2006) $</em>
 <a name="96" href="#96">96</a>  <em> */</em>
 <a name="97" href="#97">97</a>  <strong>public</strong> <strong>class</strong> <a href="../../../../../org/apache/james/transport/mailets/RemoteDelivery.html">RemoteDelivery</a> <strong>extends</strong> <a href="../../../../../org/apache/mailet/GenericMailet.html">GenericMailet</a> implements Runnable {
 <a name="98" href="#98">98</a>  
@@ -514,868 +514,873 @@
 <a name="505" href="#505">505</a>                         <em class="comment">// performance enhancement can be done.</em>
 <a name="506" href="#506">506</a>                         <strong>if</strong> (transport instanceof SMTPTransport)  {
 <a name="507" href="#507">507</a>                             SMTPTransport smtpTransport = (SMTPTransport) transport;
-<a name="508" href="#508">508</a>                             <em class="comment">// if the message is alredy 8bit or binary and the</em>
-<a name="509" href="#509">509</a>                             <em class="comment">// server doesn't support the 8bit extension it has</em>
-<a name="510" href="#510">510</a>                             <em class="comment">// to be converted to 7bit. Javamail api don't do</em>
-<a name="511" href="#511">511</a>                             <em class="comment">// that conversion, but it is required to be a</em>
-<a name="512" href="#512">512</a>                             <em class="comment">// rfc-compliant smtp server.</em>
-<a name="513" href="#513">513</a>                             <strong>if</strong> (!smtpTransport.supportsExtension(<span class="string">"8BITMIME"</span>)) { 
-<a name="514" href="#514">514</a>                                 <strong>try</strong> {
-<a name="515" href="#515">515</a>                                     convertTo7Bit(message);
-<a name="516" href="#516">516</a>                                 } <strong>catch</strong> (IOException e) {
-<a name="517" href="#517">517</a>                                     <em class="comment">// An error has occured during the 7bit conversion.</em>
-<a name="518" href="#518">518</a>                                     <em class="comment">// The error is logged and the message is sent anyway.</em>
-<a name="519" href="#519">519</a>                                     
-<a name="520" href="#520">520</a>                                     log(<span class="string">"Error during the conversion to 7 bit."</span>, e);
-<a name="521" href="#521">521</a>                                 }
-<a name="522" href="#522">522</a>                             }
-<a name="523" href="#523">523</a>                             
-<a name="524" href="#524">524</a>                             <em class="comment">/*</em>
-<a name="525" href="#525">525</a> <em class="comment">                             * Workaround for a javamail 1.3.2 bug: if</em>
-<a name="526" href="#526">526</a> <em class="comment">                             * a message is sent without encoding information</em>
-<a name="527" href="#527">527</a> <em class="comment">                             * and the 8bit allow property is set an exception</em>
-<a name="528" href="#528">528</a> <em class="comment">                             * is trown during the mail delivery.</em>
-<a name="529" href="#529">529</a> <em class="comment">                             */</em>
-<a name="530" href="#530">530</a>                             
-<a name="531" href="#531">531</a>                             <strong>try</strong> {
-<a name="532" href="#532">532</a>                                 setEncodingIfMissing(message);
-<a name="533" href="#533">533</a>                             } <strong>catch</strong> (IOException e) {
-<a name="534" href="#534">534</a>                                 log(<span class="string">"Error while adding encoding information to the message"</span>, e);
-<a name="535" href="#535">535</a>                             }
-<a name="536" href="#536">536</a>                         } <strong>else</strong> {
-<a name="537" href="#537">537</a>                             <em class="comment">// If the transport is not the one</em>
-<a name="538" href="#538">538</a>                             <em class="comment">// developed by Sun we are not sure of how it</em>
-<a name="539" href="#539">539</a>                             <em class="comment">// handles the 8 bit mime stuff,</em>
-<a name="540" href="#540">540</a>                             <em class="comment">// so I convert the message to 7bit.</em>
-<a name="541" href="#541">541</a>                             <strong>try</strong> {
-<a name="542" href="#542">542</a>                                 convertTo7Bit(message);
-<a name="543" href="#543">543</a>                             } <strong>catch</strong> (IOException e) {
-<a name="544" href="#544">544</a>                                 log(<span class="string">"Error during the conversion to 7 bit."</span>, e);
-<a name="545" href="#545">545</a>                             }
-<a name="546" href="#546">546</a>                         }
-<a name="547" href="#547">547</a>                         transport.sendMessage(message, addr);
-<a name="548" href="#548">548</a>                     } <strong>finally</strong> {
-<a name="549" href="#549">549</a>                         <strong>if</strong> (transport != <strong>null</strong>) {
-<a name="550" href="#550">550</a>                             transport.close();
-<a name="551" href="#551">551</a>                             transport = <strong>null</strong>;
-<a name="552" href="#552">552</a>                         }
-<a name="553" href="#553">553</a>                     }
-<a name="554" href="#554">554</a>                     logMessageBuffer =
-<a name="555" href="#555">555</a>                                       <strong>new</strong> StringBuffer(256)
-<a name="556" href="#556">556</a>                                       .append(<span class="string">"Mail ("</span>)
-<a name="557" href="#557">557</a>                                       .append(mail.getName())
-<a name="558" href="#558">558</a>                                       .append(<span class="string">") sent successfully to "</span>)
-<a name="559" href="#559">559</a>                                       .append(outgoingMailServer.getHostName())
-<a name="560" href="#560">560</a>                                       .append(<span class="string">" at "</span>)
-<a name="561" href="#561">561</a>                                       .append(outgoingMailServer.getHost())
-<a name="562" href="#562">562</a>                                       .append(<span class="string">" for "</span>)
-<a name="563" href="#563">563</a>                                       .append(mail.getRecipients());
-<a name="564" href="#564">564</a>                     log(logMessageBuffer.toString());
-<a name="565" href="#565">565</a>                     <strong>return</strong> <strong>true</strong>;
-<a name="566" href="#566">566</a>                 } <strong>catch</strong> (SendFailedException sfe) {
-<a name="567" href="#567">567</a>                     logSendFailedException(sfe);
-<a name="568" href="#568">568</a> 
-<a name="569" href="#569">569</a>                     <strong>if</strong> (sfe.getValidSentAddresses() != <strong>null</strong>) {
-<a name="570" href="#570">570</a>                         Address[] validSent = sfe.getValidSentAddresses();
-<a name="571" href="#571">571</a>                         <strong>if</strong> (validSent.length > 0) {
-<a name="572" href="#572">572</a>                             StringBuffer logMessageBuffer =
-<a name="573" href="#573">573</a>                                 <strong>new</strong> StringBuffer(256)
-<a name="574" href="#574">574</a>                                 .append(<span class="string">"Mail ("</span>)
-<a name="575" href="#575">575</a>                                 .append(mail.getName())
-<a name="576" href="#576">576</a>                                 .append(<span class="string">") sent successfully for "</span>)
-<a name="577" href="#577">577</a>                                 .append(Arrays.asList(validSent));
-<a name="578" href="#578">578</a>                             log(logMessageBuffer.toString());
-<a name="579" href="#579">579</a>                         }
-<a name="580" href="#580">580</a>                     }
-<a name="581" href="#581">581</a> 
-<a name="582" href="#582">582</a>                     <em class="comment">/*<em class="comment"> SMTPSendFailedException introduced in JavaMail 1.3.2, and provides detailed protocol reply code for the operation */</em></em>
-<a name="583" href="#583">583</a>                     <strong>if</strong> (sfe instanceof SMTPSendFailedException) {
-<a name="584" href="#584">584</a>                         SMTPSendFailedException ssfe = (SMTPSendFailedException) sfe;
-<a name="585" href="#585">585</a>                         <em class="comment">// if 5xx, terminate this delivery attempt by re-throwing the exception.</em>
-<a name="586" href="#586">586</a>                         <strong>if</strong> (ssfe.getReturnCode() >= 500 &amp;&amp; ssfe.getReturnCode() &lt;= 599) <strong>throw</strong> sfe;
-<a name="587" href="#587">587</a>                     }
-<a name="588" href="#588">588</a> 
-<a name="589" href="#589">589</a>                     <strong>if</strong> (sfe.getValidUnsentAddresses() != <strong>null</strong>
-<a name="590" href="#590">590</a>                         &amp;&amp; sfe.getValidUnsentAddresses().length > 0) {
-<a name="591" href="#591">591</a>                         <strong>if</strong> (isDebug) log(<span class="string">"Send failed, "</span> + sfe.getValidUnsentAddresses().length + <span class="string">" valid addresses remain, continuing with any other servers"</span>);
-<a name="592" href="#592">592</a>                         lastError = sfe;
-<a name="593" href="#593">593</a>                         <strong>continue</strong>;
-<a name="594" href="#594">594</a>                     } <strong>else</strong> {
-<a name="595" href="#595">595</a>                         <em class="comment">// There are no valid addresses left to send, so rethrow</em>
-<a name="596" href="#596">596</a>                         <strong>throw</strong> sfe;
-<a name="597" href="#597">597</a>                     }
-<a name="598" href="#598">598</a>                 } <strong>catch</strong> (MessagingException me) {
-<a name="599" href="#599">599</a>                     <em class="comment">//MessagingException are horribly difficult to figure out what actually happened.</em>
-<a name="600" href="#600">600</a>                     StringBuffer exceptionBuffer =
-<a name="601" href="#601">601</a>                         <strong>new</strong> StringBuffer(256)
-<a name="602" href="#602">602</a>                         .append(<span class="string">"Exception delivering message ("</span>)
-<a name="603" href="#603">603</a>                         .append(mail.getName())
-<a name="604" href="#604">604</a>                         .append(<span class="string">") - "</span>)
-<a name="605" href="#605">605</a>                         .append(me.getMessage());
-<a name="606" href="#606">606</a>                     log(exceptionBuffer.toString());
-<a name="607" href="#607">607</a>                     <strong>if</strong> ((me.getNextException() != <strong>null</strong>) &amp;&amp;
-<a name="608" href="#608">608</a>                           (me.getNextException() instanceof java.io.IOException)) {
-<a name="609" href="#609">609</a>                         <em class="comment">//This is more than likely a temporary failure</em>
-<a name="610" href="#610">610</a> 
-<a name="611" href="#611">611</a>                         <em class="comment">// If it's an IO exception with no nested exception, it's probably</em>
-<a name="612" href="#612">612</a>                         <em class="comment">// some socket or weird I/O related problem.</em>
-<a name="613" href="#613">613</a>                         lastError = me;
-<a name="614" href="#614">614</a>                         <strong>continue</strong>;
-<a name="615" href="#615">615</a>                     }
-<a name="616" href="#616">616</a>                     <em class="comment">// This was not a connection or I/O error particular to one</em>
-<a name="617" href="#617">617</a>                     <em class="comment">// SMTP server of an MX set.  Instead, it is almost certainly</em>
-<a name="618" href="#618">618</a>                     <em class="comment">// a protocol level error.  In this case we assume that this</em>
-<a name="619" href="#619">619</a>                     <em class="comment">// is an error we'd encounter with any of the SMTP servers</em>
-<a name="620" href="#620">620</a>                     <em class="comment">// associated with this MX record, and we pass the exception</em>
-<a name="621" href="#621">621</a>                     <em class="comment">// to the code in the outer block that determines its severity.</em>
-<a name="622" href="#622">622</a>                     <strong>throw</strong> me;
-<a name="623" href="#623">623</a>                 }
-<a name="624" href="#624">624</a>             } <em class="comment">// end while</em>
-<a name="625" href="#625">625</a>             <em class="comment">//If we encountered an exception while looping through,</em>
-<a name="626" href="#626">626</a>             <em class="comment">//throw the last MessagingException we caught.  We only</em>
-<a name="627" href="#627">627</a>             <em class="comment">//do this if we were unable to send the message to any</em>
-<a name="628" href="#628">628</a>             <em class="comment">//server.  If sending eventually succeeded, we exit</em>
-<a name="629" href="#629">629</a>             <em class="comment">//deliver() though the return at the end of the try</em>
-<a name="630" href="#630">630</a>             <em class="comment">//block.</em>
-<a name="631" href="#631">631</a>             <strong>if</strong> (lastError != <strong>null</strong>) {
-<a name="632" href="#632">632</a>                 <strong>throw</strong> lastError;
-<a name="633" href="#633">633</a>             }
-<a name="634" href="#634">634</a>         } <strong>catch</strong> (SendFailedException sfe) {
-<a name="635" href="#635">635</a>         logSendFailedException(sfe);
-<a name="636" href="#636">636</a> 
-<a name="637" href="#637">637</a>             Collection recipients = mail.getRecipients();
-<a name="638" href="#638">638</a> 
-<a name="639" href="#639">639</a>             <strong>boolean</strong> deleteMessage = false;
-<a name="640" href="#640">640</a> 
-<a name="641" href="#641">641</a>             <em class="comment">/*</em>
-<a name="642" href="#642">642</a> <em class="comment">             * If you send a message that has multiple invalid</em>
-<a name="643" href="#643">643</a> <em class="comment">             * addresses, you'll get a top-level SendFailedException</em>
-<a name="644" href="#644">644</a> <em class="comment">             * that that has the valid, valid-unsent, and invalid</em>
-<a name="645" href="#645">645</a> <em class="comment">             * address lists, with all of the server response messages</em>
-<a name="646" href="#646">646</a> <em class="comment">             * will be contained within the nested exceptions.  [Note:</em>
-<a name="647" href="#647">647</a> <em class="comment">             * the content of the nested exceptions is implementation</em>
-<a name="648" href="#648">648</a> <em class="comment">             * dependent.]</em>
-<a name="649" href="#649">649</a> <em class="comment">             *</em>
-<a name="650" href="#650">650</a> <em class="comment">             * sfe.getInvalidAddresses() should be considered permanent.</em>
-<a name="651" href="#651">651</a> <em class="comment">             * sfe.getValidUnsentAddresses() should be considered temporary.</em>
-<a name="652" href="#652">652</a> <em class="comment">             *</em>
-<a name="653" href="#653">653</a> <em class="comment">             * JavaMail v1.3 properly populates those collections based</em>
-<a name="654" href="#654">654</a> <em class="comment">             * upon the 4xx and 5xx response codes to RCPT TO.  Some</em>
-<a name="655" href="#655">655</a> <em class="comment">             * servers, such as Yahoo! don't respond to the RCPT TO,</em>
-<a name="656" href="#656">656</a> <em class="comment">             * and provide a 5xx reply after DATA.  In that case, we</em>
-<a name="657" href="#657">657</a> <em class="comment">             * will pick up the failure from SMTPSendFailedException.</em>
-<a name="658" href="#658">658</a> <em class="comment">             *</em>
-<a name="659" href="#659">659</a> <em class="comment">             */</em>
-<a name="660" href="#660">660</a> 
-<a name="661" href="#661">661</a>             <em class="comment">/*<em class="comment"> SMTPSendFailedException introduced in JavaMail 1.3.2, and provides detailed protocol reply code for the operation */</em></em>
-<a name="662" href="#662">662</a>             <strong>if</strong> (sfe instanceof SMTPSendFailedException) {
-<a name="663" href="#663">663</a>                 <em class="comment">// If we got an SMTPSendFailedException, use its RetCode to determine default permanent/temporary failure</em>
-<a name="664" href="#664">664</a>                 SMTPSendFailedException ssfe = (SMTPSendFailedException) sfe;
-<a name="665" href="#665">665</a>                 deleteMessage = (ssfe.getReturnCode() >= 500 &amp;&amp; ssfe.getReturnCode() &lt;= 599);
-<a name="666" href="#666">666</a>             } <strong>else</strong> {
-<a name="667" href="#667">667</a>                 <em class="comment">// Sometimes we'll get a normal SendFailedException with nested SMTPAddressFailedException, so use the latter RetCode</em>
-<a name="668" href="#668">668</a>                 MessagingException me = sfe;
-<a name="669" href="#669">669</a>                 Exception ne;
-<a name="670" href="#670">670</a>                 <strong>while</strong> ((ne = me.getNextException()) != <strong>null</strong> &amp;&amp; ne instanceof MessagingException) {
-<a name="671" href="#671">671</a>                     me = (MessagingException)ne;
-<a name="672" href="#672">672</a>                     <strong>if</strong> (me instanceof SMTPAddressFailedException) {
-<a name="673" href="#673">673</a>                         SMTPAddressFailedException ssfe = (SMTPAddressFailedException)me;
-<a name="674" href="#674">674</a>                         deleteMessage = (ssfe.getReturnCode() >= 500 &amp;&amp; ssfe.getReturnCode() &lt;= 599);
-<a name="675" href="#675">675</a>                     }
-<a name="676" href="#676">676</a>                 }
-<a name="677" href="#677">677</a>             }
-<a name="678" href="#678">678</a> 
-<a name="679" href="#679">679</a>             <em class="comment">// log the original set of intended recipients</em>
-<a name="680" href="#680">680</a>             <strong>if</strong> (isDebug) log(<span class="string">"Recipients: "</span> + recipients);
-<a name="681" href="#681">681</a> 
-<a name="682" href="#682">682</a>             <strong>if</strong> (sfe.getInvalidAddresses() != <strong>null</strong>) {
-<a name="683" href="#683">683</a>                 Address[] address = sfe.getInvalidAddresses();
-<a name="684" href="#684">684</a>                 <strong>if</strong> (address.length > 0) {
-<a name="685" href="#685">685</a>                     recipients.clear();
-<a name="686" href="#686">686</a>                     <strong>for</strong> (<strong>int</strong> i = 0; i &lt; address.length; i++) {
-<a name="687" href="#687">687</a>                         <strong>try</strong> {
-<a name="688" href="#688">688</a>                             recipients.add(<strong>new</strong> <a href="../../../../../org/apache/mailet/MailAddress.html">MailAddress</a>(address[i].toString()));
-<a name="689" href="#689">689</a>                         } <strong>catch</strong> (ParseException pe) {
-<a name="690" href="#690">690</a>                             <em class="comment">// this should never happen ... we should have</em>
-<a name="691" href="#691">691</a>                             <em class="comment">// caught malformed addresses long before we</em>
-<a name="692" href="#692">692</a>                             <em class="comment">// got to this code.</em>
-<a name="693" href="#693">693</a>                             log(<span class="string">"Can't parse invalid address: "</span> + pe.getMessage());
-<a name="694" href="#694">694</a>                         }
-<a name="695" href="#695">695</a>                     }
-<a name="696" href="#696">696</a>                     <strong>if</strong> (isDebug) log(<span class="string">"Invalid recipients: "</span> + recipients);
-<a name="697" href="#697">697</a>                     deleteMessage = failMessage(mail, sfe, <strong>true</strong>);
-<a name="698" href="#698">698</a>                 }
-<a name="699" href="#699">699</a>             }
-<a name="700" href="#700">700</a> 
-<a name="701" href="#701">701</a>             <strong>if</strong> (sfe.getValidUnsentAddresses() != <strong>null</strong>) {
-<a name="702" href="#702">702</a>                 Address[] address = sfe.getValidUnsentAddresses();
-<a name="703" href="#703">703</a>                 <strong>if</strong> (address.length > 0) {
-<a name="704" href="#704">704</a>                     recipients.clear();
-<a name="705" href="#705">705</a>                     <strong>for</strong> (<strong>int</strong> i = 0; i &lt; address.length; i++) {
-<a name="706" href="#706">706</a>                         <strong>try</strong> {
-<a name="707" href="#707">707</a>                             recipients.add(<strong>new</strong> <a href="../../../../../org/apache/mailet/MailAddress.html">MailAddress</a>(address[i].toString()));
-<a name="708" href="#708">708</a>                         } <strong>catch</strong> (ParseException pe) {
-<a name="709" href="#709">709</a>                             <em class="comment">// this should never happen ... we should have</em>
-<a name="710" href="#710">710</a>                             <em class="comment">// caught malformed addresses long before we</em>
-<a name="711" href="#711">711</a>                             <em class="comment">// got to this code.</em>
-<a name="712" href="#712">712</a>                             log(<span class="string">"Can't parse unsent address: "</span> + pe.getMessage());
-<a name="713" href="#713">713</a>                         }
-<a name="714" href="#714">714</a>                     }
-<a name="715" href="#715">715</a>                     <strong>if</strong> (isDebug) log(<span class="string">"Unsent recipients: "</span> + recipients);
-<a name="716" href="#716">716</a>                     <strong>if</strong> (sfe instanceof SMTPSendFailedException) {
-<a name="717" href="#717">717</a>                         SMTPSendFailedException ssfe = (SMTPSendFailedException) sfe;
-<a name="718" href="#718">718</a>                         deleteMessage = failMessage(mail, sfe, ssfe.getReturnCode() >= 500 &amp;&amp; ssfe.getReturnCode() &lt;= 599);
-<a name="719" href="#719">719</a>                     } <strong>else</strong> {
-<a name="720" href="#720">720</a>                         deleteMessage = failMessage(mail, sfe, false);
-<a name="721" href="#721">721</a>                     }
-<a name="722" href="#722">722</a>                 }
-<a name="723" href="#723">723</a>             }
-<a name="724" href="#724">724</a> 
-<a name="725" href="#725">725</a>             <strong>return</strong> deleteMessage;
-<a name="726" href="#726">726</a>         } <strong>catch</strong> (MessagingException ex) {
-<a name="727" href="#727">727</a>             <em class="comment">// We should do a better job checking this... if the failure is a general</em>
-<a name="728" href="#728">728</a>             <em class="comment">// connect exception, this is less descriptive than more specific SMTP command</em>
-<a name="729" href="#729">729</a>             <em class="comment">// failure... have to lookup and see what are the various Exception</em>
-<a name="730" href="#730">730</a>             <em class="comment">// possibilities</em>
-<a name="731" href="#731">731</a> 
-<a name="732" href="#732">732</a>             <em class="comment">// Unable to deliver message after numerous tries... fail accordingly</em>
-<a name="733" href="#733">733</a> 
-<a name="734" href="#734">734</a>             <em class="comment">// We check whether this is a 5xx error message, which</em>
-<a name="735" href="#735">735</a>             <em class="comment">// indicates a permanent failure (like account doesn't exist</em>
-<a name="736" href="#736">736</a>             <em class="comment">// or mailbox is full or domain is setup wrong).</em>
-<a name="737" href="#737">737</a>             <em class="comment">// We fail permanently if this was a 5xx error</em>
-<a name="738" href="#738">738</a>             <strong>return</strong> failMessage(mail, ex, ('5' == ex.getMessage().charAt(0)));
-<a name="739" href="#739">739</a>         }
-<a name="740" href="#740">740</a> 
-<a name="741" href="#741">741</a>         <em class="comment">/*<em class="comment"> If we get here, we've exhausted the loop of servers without</em></em>
-<a name="742" href="#742">742</a> <em class="comment">         * sending the message or throwing an exception.  One case</em>
-<a name="743" href="#743">743</a> <em class="comment">         * where this might happen is if we get a MessagingException on</em>
-<a name="744" href="#744">744</a> <em class="comment">         * each transport.connect(), e.g., if there is only one server</em>
-<a name="745" href="#745">745</a> <em class="comment">         * and we get a connect exception.</em>
-<a name="746" href="#746">746</a> <em class="comment">         */</em>
-<a name="747" href="#747">747</a>         <strong>return</strong> failMessage(mail, <strong>new</strong> MessagingException(<span class="string">"No mail server(s) available at this time."</span>), false);
-<a name="748" href="#748">748</a>     }
-<a name="749" href="#749">749</a> 
-<a name="750" href="#750">750</a>     <em>/**<em>*</em></em>
-<a name="751" href="#751">751</a> <em>     * Converts a message to 7 bit.</em>
-<a name="752" href="#752">752</a> <em>     * </em>
-<a name="753" href="#753">753</a> <em>     * @param message</em>
-<a name="754" href="#754">754</a> <em>     * @return</em>
-<a name="755" href="#755">755</a> <em>     */</em>
-<a name="756" href="#756">756</a>     <strong>private</strong> <strong>void</strong> convertTo7Bit(MimePart part) throws MessagingException, IOException {
-<a name="757" href="#757">757</a>         <strong>if</strong> (part.isMimeType(<span class="string">"multipart/*"</span>)) {
-<a name="758" href="#758">758</a>             MimeMultipart parts = (MimeMultipart) part.getContent();
-<a name="759" href="#759">759</a>             <strong>int</strong> count = parts.getCount();
-<a name="760" href="#760">760</a>             <strong>for</strong> (<strong>int</strong> i = 0; i &lt; count; i++) {
-<a name="761" href="#761">761</a>                 convertTo7Bit((MimePart)parts.getBodyPart(i));
-<a name="762" href="#762">762</a>             }
-<a name="763" href="#763">763</a>         } <strong>else</strong> {
-<a name="764" href="#764">764</a>             <strong>if</strong> (part.isMimeType(<span class="string">"text/*"</span>)) {
-<a name="765" href="#765">765</a>                 part.setHeader(<span class="string">"Content-Transfer-Encoding"</span>, <span class="string">"quoted-printable"</span>);
-<a name="766" href="#766">766</a>                 part.addHeader(<span class="string">"X-MIME-Autoconverted"</span>, <span class="string">"from 8bit to quoted-printable by "</span>+getMailetContext().getServerInfo());
-<a name="767" href="#767">767</a>             } <strong>else</strong> {
-<a name="768" href="#768">768</a>                 <em class="comment">// if the part doesn't contain text it will be base64 encoded.</em>
-<a name="769" href="#769">769</a>                 part.setHeader(<span class="string">"Content-Transfer-Encoding"</span>, <span class="string">"base64"</span>);
-<a name="770" href="#770">770</a>                 part.addHeader(<span class="string">"X-MIME-Autoconverted"</span>, <span class="string">"from 8bit to base64 by "</span>+getMailetContext().getServerInfo());
-<a name="771" href="#771">771</a>             }
-<a name="772" href="#772">772</a>         }
-<a name="773" href="#773">773</a>     }
-<a name="774" href="#774">774</a>     
-<a name="775" href="#775">775</a>     <em>/**<em>*</em></em>
-<a name="776" href="#776">776</a> <em>     * Adds an encoding information to each text mime part. This is a workaround</em>
-<a name="777" href="#777">777</a> <em>     * for a javamail 1.3.2 bug: if a message is sent without encoding</em>
-<a name="778" href="#778">778</a> <em>     * information a null pointer exception is thrown during the message</em>
-<a name="779" href="#779">779</a> <em>     * delivery.</em>
-<a name="780" href="#780">780</a> <em>     * </em>
-<a name="781" href="#781">781</a> <em>     * @param part</em>
-<a name="782" href="#782">782</a> <em>     * @throws MessagingException</em>
-<a name="783" href="#783">783</a> <em>     * @throws IOException</em>
-<a name="784" href="#784">784</a> <em>     */</em>
-<a name="785" href="#785">785</a>     <strong>private</strong> <strong>void</strong> setEncodingIfMissing(MimePart part) throws MessagingException, IOException {
-<a name="786" href="#786">786</a>         <strong>if</strong> (part.isMimeType(<span class="string">"text/*"</span>)) {
-<a name="787" href="#787">787</a>             String enc = part.getEncoding();
-<a name="788" href="#788">788</a>             <strong>if</strong> (enc == <strong>null</strong>) part.setHeader(<span class="string">"Content-Transfer-Encoding"</span>, <span class="string">"7bit"</span>);
-<a name="789" href="#789">789</a>         } <strong>else</strong> <strong>if</strong> (part.isMimeType(<span class="string">"multipart/*"</span>)) {
-<a name="790" href="#790">790</a>             Object content = part.getContent();
-<a name="791" href="#791">791</a>             <strong>if</strong> (content instanceof MimeMultipart) {
-<a name="792" href="#792">792</a>                 MimeMultipart parts = (MimeMultipart) content;
-<a name="793" href="#793">793</a>                 <strong>int</strong> count = parts.getCount();
-<a name="794" href="#794">794</a>                 <strong>for</strong> (<strong>int</strong> i = 0; i &lt; count; i++) {
-<a name="795" href="#795">795</a>                     setEncodingIfMissing((MimePart)parts.getBodyPart(i));
-<a name="796" href="#796">796</a>                 }
-<a name="797" href="#797">797</a>             }
-<a name="798" href="#798">798</a>         }
-<a name="799" href="#799">799</a>     }
-<a name="800" href="#800">800</a>     
-<a name="801" href="#801">801</a>     <em>/**<em>*</em></em>
-<a name="802" href="#802">802</a> <em>     * Insert the method's description here.</em>
-<a name="803" href="#803">803</a> <em>     * Creation date: (2/25/00 1:14:18 AM)</em>
-<a name="804" href="#804">804</a> <em>     * @param mail org.apache.james.core.MailImpl</em>
-<a name="805" href="#805">805</a> <em>     * @param exception javax.mail.MessagingException</em>
-<a name="806" href="#806">806</a> <em>     * @param boolean permanent</em>
-<a name="807" href="#807">807</a> <em>     * @return boolean Whether the message failed fully and can be deleted</em>
-<a name="808" href="#808">808</a> <em>     */</em>
-<a name="809" href="#809">809</a>     <strong>private</strong> <strong>boolean</strong> failMessage(<a href="../../../../../org/apache/mailet/Mail.html">Mail</a> mail, MessagingException ex, <strong>boolean</strong> permanent) {
-<a name="810" href="#810">810</a>         StringWriter sout = <strong>new</strong> StringWriter();
-<a name="811" href="#811">811</a>         PrintWriter out = <strong>new</strong> PrintWriter(sout, <strong>true</strong>);
-<a name="812" href="#812">812</a>         <strong>if</strong> (permanent) {
-<a name="813" href="#813">813</a>             out.print(<span class="string">"Permanent"</span>);
-<a name="814" href="#814">814</a>         } <strong>else</strong> {
-<a name="815" href="#815">815</a>             out.print(<span class="string">"Temporary"</span>);
-<a name="816" href="#816">816</a>         }
-<a name="817" href="#817">817</a>         StringBuffer logBuffer =
-<a name="818" href="#818">818</a>             <strong>new</strong> StringBuffer(64)
-<a name="819" href="#819">819</a>                 .append(<span class="string">" exception delivering mail ("</span>)
-<a name="820" href="#820">820</a>                 .append(mail.getName())
-<a name="821" href="#821">821</a>                 .append(<span class="string">": "</span>);
-<a name="822" href="#822">822</a>         out.print(logBuffer.toString());
-<a name="823" href="#823">823</a>         <strong>if</strong> (isDebug) ex.printStackTrace(out);
-<a name="824" href="#824">824</a>         log(sout.toString());
-<a name="825" href="#825">825</a>         <strong>if</strong> (!permanent) {
-<a name="826" href="#826">826</a>             <strong>if</strong> (!mail.getState().equals(Mail.ERROR)) {
-<a name="827" href="#827">827</a>                 mail.setState(Mail.ERROR);
-<a name="828" href="#828">828</a>                 mail.setErrorMessage(<span class="string">"0"</span>);
-<a name="829" href="#829">829</a>                 mail.setLastUpdated(<strong>new</strong> Date());
-<a name="830" href="#830">830</a>             }
-<a name="831" href="#831">831</a>             <strong>int</strong> retries = Integer.parseInt(mail.getErrorMessage());
-<a name="832" href="#832">832</a>             <strong>if</strong> (retries &lt; maxRetries) {
-<a name="833" href="#833">833</a>                 logBuffer =
-<a name="834" href="#834">834</a>                     <strong>new</strong> StringBuffer(128)
-<a name="835" href="#835">835</a>                             .append(<span class="string">"Storing message "</span>)
-<a name="836" href="#836">836</a>                             .append(mail.getName())
-<a name="837" href="#837">837</a>                             .append(<span class="string">" into outgoing after "</span>)
-<a name="838" href="#838">838</a>                             .append(retries)
-<a name="839" href="#839">839</a>                             .append(<span class="string">" retries"</span>);
-<a name="840" href="#840">840</a>                 log(logBuffer.toString());
-<a name="841" href="#841">841</a>                 ++retries;
-<a name="842" href="#842">842</a>                 mail.setErrorMessage(retries + <span class="string">""</span>);
-<a name="843" href="#843">843</a>                 mail.setLastUpdated(<strong>new</strong> Date());
-<a name="844" href="#844">844</a>                 <strong>return</strong> false;
-<a name="845" href="#845">845</a>             } <strong>else</strong> {
-<a name="846" href="#846">846</a>                 logBuffer =
-<a name="847" href="#847">847</a>                     <strong>new</strong> StringBuffer(128)
-<a name="848" href="#848">848</a>                             .append(<span class="string">"Bouncing message "</span>)
-<a name="849" href="#849">849</a>                             .append(mail.getName())
-<a name="850" href="#850">850</a>                             .append(<span class="string">" after "</span>)
-<a name="851" href="#851">851</a>                             .append(retries)
-<a name="852" href="#852">852</a>                             .append(<span class="string">" retries"</span>);
-<a name="853" href="#853">853</a>                 log(logBuffer.toString());
-<a name="854" href="#854">854</a>             }
-<a name="855" href="#855">855</a>         }
-<a name="856" href="#856">856</a> 
-<a name="857" href="#857">857</a>         <strong>if</strong> (mail.getSender() == <strong>null</strong>) {
-<a name="858" href="#858">858</a>             log(<span class="string">"Null Sender: no bounce will be generated for "</span> + mail.getName());
-<a name="859" href="#859">859</a>             <strong>return</strong> <strong>true</strong>;
+<a name="508" href="#508">508</a>                            
+<a name="509" href="#509">509</a>                             <em class="comment">// if the message is alredy 8bit or binary and the</em>
+<a name="510" href="#510">510</a>                             <em class="comment">// server doesn't support the 8bit extension it has</em>
+<a name="511" href="#511">511</a>                             <em class="comment">// to be converted to 7bit. Javamail api doesn't perform</em>
+<a name="512" href="#512">512</a>                             <em class="comment">// that conversion, but it is required to be a</em>
+<a name="513" href="#513">513</a>                             <em class="comment">// rfc-compliant smtp server.</em>
+<a name="514" href="#514">514</a>                             
+<a name="515" href="#515">515</a>                             <em class="comment">// Temporarily disabled. See JAMES-638</em>
+<a name="516" href="#516">516</a>                             <em class="comment">/*</em>
+<a name="517" href="#517">517</a> <em class="comment">                            if (!smtpTransport.supportsExtension("8BITMIME")) { </em>
+<a name="518" href="#518">518</a> <em class="comment">                                try {</em>
+<a name="519" href="#519">519</a> <em class="comment">                                    convertTo7Bit(message);</em>
+<a name="520" href="#520">520</a> <em class="comment">                                } catch (IOException e) {</em>
+<a name="521" href="#521">521</a> <em class="comment">                                    // An error has occured during the 7bit conversion.</em>
+<a name="522" href="#522">522</a> <em class="comment">                                    // The error is logged and the message is sent anyway.</em>
+<a name="523" href="#523">523</a> <em class="comment">                                    </em>
+<a name="524" href="#524">524</a> <em class="comment">                                    log("Error during the conversion to 7 bit.", e);</em>
+<a name="525" href="#525">525</a> <em class="comment">                                }</em>
+<a name="526" href="#526">526</a> <em class="comment">                            }</em>
+<a name="527" href="#527">527</a> <em class="comment">                            */</em>
+<a name="528" href="#528">528</a>                             
+<a name="529" href="#529">529</a>                             <em class="comment">/*</em>
+<a name="530" href="#530">530</a> <em class="comment">                             * Workaround for a javamail 1.3.2 bug: if</em>
+<a name="531" href="#531">531</a> <em class="comment">                             * a message is sent without encoding information</em>
+<a name="532" href="#532">532</a> <em class="comment">                             * and the 8bit allow property is set an exception</em>
+<a name="533" href="#533">533</a> <em class="comment">                             * is trown during the mail delivery.</em>
+<a name="534" href="#534">534</a> <em class="comment">                             */</em>
+<a name="535" href="#535">535</a>                             
+<a name="536" href="#536">536</a>                             <strong>try</strong> {
+<a name="537" href="#537">537</a>                                 setEncodingIfMissing(message);
+<a name="538" href="#538">538</a>                             } <strong>catch</strong> (IOException e) {
+<a name="539" href="#539">539</a>                                 log(<span class="string">"Error while adding encoding information to the message"</span>, e);
+<a name="540" href="#540">540</a>                             }
+<a name="541" href="#541">541</a>                         } <strong>else</strong> {
+<a name="542" href="#542">542</a>                             <em class="comment">// If the transport is not the one</em>
+<a name="543" href="#543">543</a>                             <em class="comment">// developed by Sun we are not sure of how it</em>
+<a name="544" href="#544">544</a>                             <em class="comment">// handles the 8 bit mime stuff,</em>
+<a name="545" href="#545">545</a>                             <em class="comment">// so I convert the message to 7bit.</em>
+<a name="546" href="#546">546</a>                             <strong>try</strong> {
+<a name="547" href="#547">547</a>                                 convertTo7Bit(message);
+<a name="548" href="#548">548</a>                             } <strong>catch</strong> (IOException e) {
+<a name="549" href="#549">549</a>                                 log(<span class="string">"Error during the conversion to 7 bit."</span>, e);
+<a name="550" href="#550">550</a>                             }
+<a name="551" href="#551">551</a>                         }
+<a name="552" href="#552">552</a>                         transport.sendMessage(message, addr);
+<a name="553" href="#553">553</a>                     } <strong>finally</strong> {
+<a name="554" href="#554">554</a>                         <strong>if</strong> (transport != <strong>null</strong>) {
+<a name="555" href="#555">555</a>                             transport.close();
+<a name="556" href="#556">556</a>                             transport = <strong>null</strong>;
+<a name="557" href="#557">557</a>                         }
+<a name="558" href="#558">558</a>                     }
+<a name="559" href="#559">559</a>                     logMessageBuffer =
+<a name="560" href="#560">560</a>                                       <strong>new</strong> StringBuffer(256)
+<a name="561" href="#561">561</a>                                       .append(<span class="string">"Mail ("</span>)
+<a name="562" href="#562">562</a>                                       .append(mail.getName())
+<a name="563" href="#563">563</a>                                       .append(<span class="string">") sent successfully to "</span>)
+<a name="564" href="#564">564</a>                                       .append(outgoingMailServer.getHostName())
+<a name="565" href="#565">565</a>                                       .append(<span class="string">" at "</span>)
+<a name="566" href="#566">566</a>                                       .append(outgoingMailServer.getHost())
+<a name="567" href="#567">567</a>                                       .append(<span class="string">" for "</span>)
+<a name="568" href="#568">568</a>                                       .append(mail.getRecipients());
+<a name="569" href="#569">569</a>                     log(logMessageBuffer.toString());
+<a name="570" href="#570">570</a>                     <strong>return</strong> <strong>true</strong>;
+<a name="571" href="#571">571</a>                 } <strong>catch</strong> (SendFailedException sfe) {
+<a name="572" href="#572">572</a>                     logSendFailedException(sfe);
+<a name="573" href="#573">573</a> 
+<a name="574" href="#574">574</a>                     <strong>if</strong> (sfe.getValidSentAddresses() != <strong>null</strong>) {
+<a name="575" href="#575">575</a>                         Address[] validSent = sfe.getValidSentAddresses();
+<a name="576" href="#576">576</a>                         <strong>if</strong> (validSent.length > 0) {
+<a name="577" href="#577">577</a>                             StringBuffer logMessageBuffer =
+<a name="578" href="#578">578</a>                                 <strong>new</strong> StringBuffer(256)
+<a name="579" href="#579">579</a>                                 .append(<span class="string">"Mail ("</span>)
+<a name="580" href="#580">580</a>                                 .append(mail.getName())
+<a name="581" href="#581">581</a>                                 .append(<span class="string">") sent successfully for "</span>)
+<a name="582" href="#582">582</a>                                 .append(Arrays.asList(validSent));
+<a name="583" href="#583">583</a>                             log(logMessageBuffer.toString());
+<a name="584" href="#584">584</a>                         }
+<a name="585" href="#585">585</a>                     }
+<a name="586" href="#586">586</a> 
+<a name="587" href="#587">587</a>                     <em class="comment">/*<em class="comment"> SMTPSendFailedException introduced in JavaMail 1.3.2, and provides detailed protocol reply code for the operation */</em></em>
+<a name="588" href="#588">588</a>                     <strong>if</strong> (sfe instanceof SMTPSendFailedException) {
+<a name="589" href="#589">589</a>                         SMTPSendFailedException ssfe = (SMTPSendFailedException) sfe;
+<a name="590" href="#590">590</a>                         <em class="comment">// if 5xx, terminate this delivery attempt by re-throwing the exception.</em>
+<a name="591" href="#591">591</a>                         <strong>if</strong> (ssfe.getReturnCode() >= 500 &amp;&amp; ssfe.getReturnCode() &lt;= 599) <strong>throw</strong> sfe;
+<a name="592" href="#592">592</a>                     }
+<a name="593" href="#593">593</a> 
+<a name="594" href="#594">594</a>                     <strong>if</strong> (sfe.getValidUnsentAddresses() != <strong>null</strong>
+<a name="595" href="#595">595</a>                         &amp;&amp; sfe.getValidUnsentAddresses().length > 0) {
+<a name="596" href="#596">596</a>                         <strong>if</strong> (isDebug) log(<span class="string">"Send failed, "</span> + sfe.getValidUnsentAddresses().length + <span class="string">" valid addresses remain, continuing with any other servers"</span>);
+<a name="597" href="#597">597</a>                         lastError = sfe;
+<a name="598" href="#598">598</a>                         <strong>continue</strong>;
+<a name="599" href="#599">599</a>                     } <strong>else</strong> {
+<a name="600" href="#600">600</a>                         <em class="comment">// There are no valid addresses left to send, so rethrow</em>
+<a name="601" href="#601">601</a>                         <strong>throw</strong> sfe;
+<a name="602" href="#602">602</a>                     }
+<a name="603" href="#603">603</a>                 } <strong>catch</strong> (MessagingException me) {
+<a name="604" href="#604">604</a>                     <em class="comment">//MessagingException are horribly difficult to figure out what actually happened.</em>
+<a name="605" href="#605">605</a>                     StringBuffer exceptionBuffer =
+<a name="606" href="#606">606</a>                         <strong>new</strong> StringBuffer(256)
+<a name="607" href="#607">607</a>                         .append(<span class="string">"Exception delivering message ("</span>)
+<a name="608" href="#608">608</a>                         .append(mail.getName())
+<a name="609" href="#609">609</a>                         .append(<span class="string">") - "</span>)
+<a name="610" href="#610">610</a>                         .append(me.getMessage());
+<a name="611" href="#611">611</a>                     log(exceptionBuffer.toString());
+<a name="612" href="#612">612</a>                     <strong>if</strong> ((me.getNextException() != <strong>null</strong>) &amp;&amp;
+<a name="613" href="#613">613</a>                           (me.getNextException() instanceof java.io.IOException)) {
+<a name="614" href="#614">614</a>                         <em class="comment">//This is more than likely a temporary failure</em>
+<a name="615" href="#615">615</a> 
+<a name="616" href="#616">616</a>                         <em class="comment">// If it's an IO exception with no nested exception, it's probably</em>
+<a name="617" href="#617">617</a>                         <em class="comment">// some socket or weird I/O related problem.</em>
+<a name="618" href="#618">618</a>                         lastError = me;
+<a name="619" href="#619">619</a>                         <strong>continue</strong>;
+<a name="620" href="#620">620</a>                     }
+<a name="621" href="#621">621</a>                     <em class="comment">// This was not a connection or I/O error particular to one</em>
+<a name="622" href="#622">622</a>                     <em class="comment">// SMTP server of an MX set.  Instead, it is almost certainly</em>
+<a name="623" href="#623">623</a>                     <em class="comment">// a protocol level error.  In this case we assume that this</em>
+<a name="624" href="#624">624</a>                     <em class="comment">// is an error we'd encounter with any of the SMTP servers</em>
+<a name="625" href="#625">625</a>                     <em class="comment">// associated with this MX record, and we pass the exception</em>
+<a name="626" href="#626">626</a>                     <em class="comment">// to the code in the outer block that determines its severity.</em>
+<a name="627" href="#627">627</a>                     <strong>throw</strong> me;
+<a name="628" href="#628">628</a>                 }
+<a name="629" href="#629">629</a>             } <em class="comment">// end while</em>
+<a name="630" href="#630">630</a>             <em class="comment">//If we encountered an exception while looping through,</em>
+<a name="631" href="#631">631</a>             <em class="comment">//throw the last MessagingException we caught.  We only</em>
+<a name="632" href="#632">632</a>             <em class="comment">//do this if we were unable to send the message to any</em>
+<a name="633" href="#633">633</a>             <em class="comment">//server.  If sending eventually succeeded, we exit</em>
+<a name="634" href="#634">634</a>             <em class="comment">//deliver() though the return at the end of the try</em>
+<a name="635" href="#635">635</a>             <em class="comment">//block.</em>
+<a name="636" href="#636">636</a>             <strong>if</strong> (lastError != <strong>null</strong>) {
+<a name="637" href="#637">637</a>                 <strong>throw</strong> lastError;
+<a name="638" href="#638">638</a>             }
+<a name="639" href="#639">639</a>         } <strong>catch</strong> (SendFailedException sfe) {
+<a name="640" href="#640">640</a>         logSendFailedException(sfe);
+<a name="641" href="#641">641</a> 
+<a name="642" href="#642">642</a>             Collection recipients = mail.getRecipients();
+<a name="643" href="#643">643</a> 
+<a name="644" href="#644">644</a>             <strong>boolean</strong> deleteMessage = false;
+<a name="645" href="#645">645</a> 
+<a name="646" href="#646">646</a>             <em class="comment">/*</em>
+<a name="647" href="#647">647</a> <em class="comment">             * If you send a message that has multiple invalid</em>
+<a name="648" href="#648">648</a> <em class="comment">             * addresses, you'll get a top-level SendFailedException</em>
+<a name="649" href="#649">649</a> <em class="comment">             * that that has the valid, valid-unsent, and invalid</em>
+<a name="650" href="#650">650</a> <em class="comment">             * address lists, with all of the server response messages</em>
+<a name="651" href="#651">651</a> <em class="comment">             * will be contained within the nested exceptions.  [Note:</em>
+<a name="652" href="#652">652</a> <em class="comment">             * the content of the nested exceptions is implementation</em>
+<a name="653" href="#653">653</a> <em class="comment">             * dependent.]</em>
+<a name="654" href="#654">654</a> <em class="comment">             *</em>
+<a name="655" href="#655">655</a> <em class="comment">             * sfe.getInvalidAddresses() should be considered permanent.</em>
+<a name="656" href="#656">656</a> <em class="comment">             * sfe.getValidUnsentAddresses() should be considered temporary.</em>
+<a name="657" href="#657">657</a> <em class="comment">             *</em>
+<a name="658" href="#658">658</a> <em class="comment">             * JavaMail v1.3 properly populates those collections based</em>
+<a name="659" href="#659">659</a> <em class="comment">             * upon the 4xx and 5xx response codes to RCPT TO.  Some</em>
+<a name="660" href="#660">660</a> <em class="comment">             * servers, such as Yahoo! don't respond to the RCPT TO,</em>
+<a name="661" href="#661">661</a> <em class="comment">             * and provide a 5xx reply after DATA.  In that case, we</em>
+<a name="662" href="#662">662</a> <em class="comment">             * will pick up the failure from SMTPSendFailedException.</em>
+<a name="663" href="#663">663</a> <em class="comment">             *</em>
+<a name="664" href="#664">664</a> <em class="comment">             */</em>
+<a name="665" href="#665">665</a> 
+<a name="666" href="#666">666</a>             <em class="comment">/*<em class="comment"> SMTPSendFailedException introduced in JavaMail 1.3.2, and provides detailed protocol reply code for the operation */</em></em>
+<a name="667" href="#667">667</a>             <strong>if</strong> (sfe instanceof SMTPSendFailedException) {
+<a name="668" href="#668">668</a>                 <em class="comment">// If we got an SMTPSendFailedException, use its RetCode to determine default permanent/temporary failure</em>
+<a name="669" href="#669">669</a>                 SMTPSendFailedException ssfe = (SMTPSendFailedException) sfe;
+<a name="670" href="#670">670</a>                 deleteMessage = (ssfe.getReturnCode() >= 500 &amp;&amp; ssfe.getReturnCode() &lt;= 599);
+<a name="671" href="#671">671</a>             } <strong>else</strong> {
+<a name="672" href="#672">672</a>                 <em class="comment">// Sometimes we'll get a normal SendFailedException with nested SMTPAddressFailedException, so use the latter RetCode</em>
+<a name="673" href="#673">673</a>                 MessagingException me = sfe;
+<a name="674" href="#674">674</a>                 Exception ne;
+<a name="675" href="#675">675</a>                 <strong>while</strong> ((ne = me.getNextException()) != <strong>null</strong> &amp;&amp; ne instanceof MessagingException) {
+<a name="676" href="#676">676</a>                     me = (MessagingException)ne;
+<a name="677" href="#677">677</a>                     <strong>if</strong> (me instanceof SMTPAddressFailedException) {
+<a name="678" href="#678">678</a>                         SMTPAddressFailedException ssfe = (SMTPAddressFailedException)me;
+<a name="679" href="#679">679</a>                         deleteMessage = (ssfe.getReturnCode() >= 500 &amp;&amp; ssfe.getReturnCode() &lt;= 599);
+<a name="680" href="#680">680</a>                     }
+<a name="681" href="#681">681</a>                 }
+<a name="682" href="#682">682</a>             }
+<a name="683" href="#683">683</a> 
+<a name="684" href="#684">684</a>             <em class="comment">// log the original set of intended recipients</em>
+<a name="685" href="#685">685</a>             <strong>if</strong> (isDebug) log(<span class="string">"Recipients: "</span> + recipients);
+<a name="686" href="#686">686</a> 
+<a name="687" href="#687">687</a>             <strong>if</strong> (sfe.getInvalidAddresses() != <strong>null</strong>) {
+<a name="688" href="#688">688</a>                 Address[] address = sfe.getInvalidAddresses();
+<a name="689" href="#689">689</a>                 <strong>if</strong> (address.length > 0) {
+<a name="690" href="#690">690</a>                     recipients.clear();
+<a name="691" href="#691">691</a>                     <strong>for</strong> (<strong>int</strong> i = 0; i &lt; address.length; i++) {
+<a name="692" href="#692">692</a>                         <strong>try</strong> {
+<a name="693" href="#693">693</a>                             recipients.add(<strong>new</strong> <a href="../../../../../org/apache/mailet/MailAddress.html">MailAddress</a>(address[i].toString()));
+<a name="694" href="#694">694</a>                         } <strong>catch</strong> (ParseException pe) {
+<a name="695" href="#695">695</a>                             <em class="comment">// this should never happen ... we should have</em>
+<a name="696" href="#696">696</a>                             <em class="comment">// caught malformed addresses long before we</em>
+<a name="697" href="#697">697</a>                             <em class="comment">// got to this code.</em>
+<a name="698" href="#698">698</a>                             log(<span class="string">"Can't parse invalid address: "</span> + pe.getMessage());
+<a name="699" href="#699">699</a>                         }
+<a name="700" href="#700">700</a>                     }
+<a name="701" href="#701">701</a>                     <strong>if</strong> (isDebug) log(<span class="string">"Invalid recipients: "</span> + recipients);
+<a name="702" href="#702">702</a>                     deleteMessage = failMessage(mail, sfe, <strong>true</strong>);
+<a name="703" href="#703">703</a>                 }
+<a name="704" href="#704">704</a>             }
+<a name="705" href="#705">705</a> 
+<a name="706" href="#706">706</a>             <strong>if</strong> (sfe.getValidUnsentAddresses() != <strong>null</strong>) {
+<a name="707" href="#707">707</a>                 Address[] address = sfe.getValidUnsentAddresses();
+<a name="708" href="#708">708</a>                 <strong>if</strong> (address.length > 0) {
+<a name="709" href="#709">709</a>                     recipients.clear();
+<a name="710" href="#710">710</a>                     <strong>for</strong> (<strong>int</strong> i = 0; i &lt; address.length; i++) {
+<a name="711" href="#711">711</a>                         <strong>try</strong> {
+<a name="712" href="#712">712</a>                             recipients.add(<strong>new</strong> <a href="../../../../../org/apache/mailet/MailAddress.html">MailAddress</a>(address[i].toString()));
+<a name="713" href="#713">713</a>                         } <strong>catch</strong> (ParseException pe) {
+<a name="714" href="#714">714</a>                             <em class="comment">// this should never happen ... we should have</em>
+<a name="715" href="#715">715</a>                             <em class="comment">// caught malformed addresses long before we</em>
+<a name="716" href="#716">716</a>                             <em class="comment">// got to this code.</em>
+<a name="717" href="#717">717</a>                             log(<span class="string">"Can't parse unsent address: "</span> + pe.getMessage());
+<a name="718" href="#718">718</a>                         }
+<a name="719" href="#719">719</a>                     }
+<a name="720" href="#720">720</a>                     <strong>if</strong> (isDebug) log(<span class="string">"Unsent recipients: "</span> + recipients);
+<a name="721" href="#721">721</a>                     <strong>if</strong> (sfe instanceof SMTPSendFailedException) {
+<a name="722" href="#722">722</a>                         SMTPSendFailedException ssfe = (SMTPSendFailedException) sfe;
+<a name="723" href="#723">723</a>                         deleteMessage = failMessage(mail, sfe, ssfe.getReturnCode() >= 500 &amp;&amp; ssfe.getReturnCode() &lt;= 599);
+<a name="724" href="#724">724</a>                     } <strong>else</strong> {
+<a name="725" href="#725">725</a>                         deleteMessage = failMessage(mail, sfe, false);
+<a name="726" href="#726">726</a>                     }
+<a name="727" href="#727">727</a>                 }
+<a name="728" href="#728">728</a>             }
+<a name="729" href="#729">729</a> 
+<a name="730" href="#730">730</a>             <strong>return</strong> deleteMessage;
+<a name="731" href="#731">731</a>         } <strong>catch</strong> (MessagingException ex) {
+<a name="732" href="#732">732</a>             <em class="comment">// We should do a better job checking this... if the failure is a general</em>
+<a name="733" href="#733">733</a>             <em class="comment">// connect exception, this is less descriptive than more specific SMTP command</em>
+<a name="734" href="#734">734</a>             <em class="comment">// failure... have to lookup and see what are the various Exception</em>
+<a name="735" href="#735">735</a>             <em class="comment">// possibilities</em>
+<a name="736" href="#736">736</a> 
+<a name="737" href="#737">737</a>             <em class="comment">// Unable to deliver message after numerous tries... fail accordingly</em>
+<a name="738" href="#738">738</a> 
+<a name="739" href="#739">739</a>             <em class="comment">// We check whether this is a 5xx error message, which</em>
+<a name="740" href="#740">740</a>             <em class="comment">// indicates a permanent failure (like account doesn't exist</em>
+<a name="741" href="#741">741</a>             <em class="comment">// or mailbox is full or domain is setup wrong).</em>
+<a name="742" href="#742">742</a>             <em class="comment">// We fail permanently if this was a 5xx error</em>
+<a name="743" href="#743">743</a>             <strong>return</strong> failMessage(mail, ex, ('5' == ex.getMessage().charAt(0)));
+<a name="744" href="#744">744</a>         }
+<a name="745" href="#745">745</a> 
+<a name="746" href="#746">746</a>         <em class="comment">/*<em class="comment"> If we get here, we've exhausted the loop of servers without</em></em>
+<a name="747" href="#747">747</a> <em class="comment">         * sending the message or throwing an exception.  One case</em>
+<a name="748" href="#748">748</a> <em class="comment">         * where this might happen is if we get a MessagingException on</em>
+<a name="749" href="#749">749</a> <em class="comment">         * each transport.connect(), e.g., if there is only one server</em>
+<a name="750" href="#750">750</a> <em class="comment">         * and we get a connect exception.</em>
+<a name="751" href="#751">751</a> <em class="comment">         */</em>
+<a name="752" href="#752">752</a>         <strong>return</strong> failMessage(mail, <strong>new</strong> MessagingException(<span class="string">"No mail server(s) available at this time."</span>), false);
+<a name="753" href="#753">753</a>     }
+<a name="754" href="#754">754</a> 
+<a name="755" href="#755">755</a>     <em>/**<em>*</em></em>
+<a name="756" href="#756">756</a> <em>     * Converts a message to 7 bit.</em>
+<a name="757" href="#757">757</a> <em>     * </em>
+<a name="758" href="#758">758</a> <em>     * @param message</em>
+<a name="759" href="#759">759</a> <em>     * @return</em>
+<a name="760" href="#760">760</a> <em>     */</em>
+<a name="761" href="#761">761</a>     <strong>private</strong> <strong>void</strong> convertTo7Bit(MimePart part) throws MessagingException, IOException {
+<a name="762" href="#762">762</a>         <strong>if</strong> (part.isMimeType(<span class="string">"multipart/*"</span>)) {
+<a name="763" href="#763">763</a>             MimeMultipart parts = (MimeMultipart) part.getContent();
+<a name="764" href="#764">764</a>             <strong>int</strong> count = parts.getCount();
+<a name="765" href="#765">765</a>             <strong>for</strong> (<strong>int</strong> i = 0; i &lt; count; i++) {
+<a name="766" href="#766">766</a>                 convertTo7Bit((MimePart)parts.getBodyPart(i));
+<a name="767" href="#767">767</a>             }
+<a name="768" href="#768">768</a>         } <strong>else</strong> {
+<a name="769" href="#769">769</a>             <strong>if</strong> (part.isMimeType(<span class="string">"text/*"</span>)) {
+<a name="770" href="#770">770</a>                 part.setHeader(<span class="string">"Content-Transfer-Encoding"</span>, <span class="string">"quoted-printable"</span>);
+<a name="771" href="#771">771</a>                 part.addHeader(<span class="string">"X-MIME-Autoconverted"</span>, <span class="string">"from 8bit to quoted-printable by "</span>+getMailetContext().getServerInfo());
+<a name="772" href="#772">772</a>             } <strong>else</strong> {
+<a name="773" href="#773">773</a>                 <em class="comment">// if the part doesn't contain text it will be base64 encoded.</em>
+<a name="774" href="#774">774</a>                 part.setHeader(<span class="string">"Content-Transfer-Encoding"</span>, <span class="string">"base64"</span>);
+<a name="775" href="#775">775</a>                 part.addHeader(<span class="string">"X-MIME-Autoconverted"</span>, <span class="string">"from 8bit to base64 by "</span>+getMailetContext().getServerInfo());
+<a name="776" href="#776">776</a>             }
+<a name="777" href="#777">777</a>         }
+<a name="778" href="#778">778</a>     }
+<a name="779" href="#779">779</a>     
+<a name="780" href="#780">780</a>     <em>/**<em>*</em></em>
+<a name="781" href="#781">781</a> <em>     * Adds an encoding information to each text mime part. This is a workaround</em>
+<a name="782" href="#782">782</a> <em>     * for a javamail 1.3.2 bug: if a message is sent without encoding</em>
+<a name="783" href="#783">783</a> <em>     * information a null pointer exception is thrown during the message</em>
+<a name="784" href="#784">784</a> <em>     * delivery.</em>
+<a name="785" href="#785">785</a> <em>     * </em>
+<a name="786" href="#786">786</a> <em>     * @param part</em>
+<a name="787" href="#787">787</a> <em>     * @throws MessagingException</em>
+<a name="788" href="#788">788</a> <em>     * @throws IOException</em>
+<a name="789" href="#789">789</a> <em>     */</em>
+<a name="790" href="#790">790</a>     <strong>private</strong> <strong>void</strong> setEncodingIfMissing(MimePart part) throws MessagingException, IOException {
+<a name="791" href="#791">791</a>         <strong>if</strong> (part.isMimeType(<span class="string">"text/*"</span>)) {
+<a name="792" href="#792">792</a>             String enc = part.getEncoding();
+<a name="793" href="#793">793</a>             <strong>if</strong> (enc == <strong>null</strong>) part.setHeader(<span class="string">"Content-Transfer-Encoding"</span>, <span class="string">"7bit"</span>);
+<a name="794" href="#794">794</a>         } <strong>else</strong> <strong>if</strong> (part.isMimeType(<span class="string">"multipart/*"</span>)) {
+<a name="795" href="#795">795</a>             Object content = part.getContent();
+<a name="796" href="#796">796</a>             <strong>if</strong> (content instanceof MimeMultipart) {
+<a name="797" href="#797">797</a>                 MimeMultipart parts = (MimeMultipart) content;
+<a name="798" href="#798">798</a>                 <strong>int</strong> count = parts.getCount();
+<a name="799" href="#799">799</a>                 <strong>for</strong> (<strong>int</strong> i = 0; i &lt; count; i++) {
+<a name="800" href="#800">800</a>                     setEncodingIfMissing((MimePart)parts.getBodyPart(i));
+<a name="801" href="#801">801</a>                 }
+<a name="802" href="#802">802</a>             }
+<a name="803" href="#803">803</a>         }
+<a name="804" href="#804">804</a>     }
+<a name="805" href="#805">805</a>     
+<a name="806" href="#806">806</a>     <em>/**<em>*</em></em>
+<a name="807" href="#807">807</a> <em>     * Insert the method's description here.</em>
+<a name="808" href="#808">808</a> <em>     * Creation date: (2/25/00 1:14:18 AM)</em>
+<a name="809" href="#809">809</a> <em>     * @param mail org.apache.james.core.MailImpl</em>
+<a name="810" href="#810">810</a> <em>     * @param exception javax.mail.MessagingException</em>
+<a name="811" href="#811">811</a> <em>     * @param boolean permanent</em>
+<a name="812" href="#812">812</a> <em>     * @return boolean Whether the message failed fully and can be deleted</em>
+<a name="813" href="#813">813</a> <em>     */</em>
+<a name="814" href="#814">814</a>     <strong>private</strong> <strong>boolean</strong> failMessage(<a href="../../../../../org/apache/mailet/Mail.html">Mail</a> mail, MessagingException ex, <strong>boolean</strong> permanent) {
+<a name="815" href="#815">815</a>         StringWriter sout = <strong>new</strong> StringWriter();
+<a name="816" href="#816">816</a>         PrintWriter out = <strong>new</strong> PrintWriter(sout, <strong>true</strong>);
+<a name="817" href="#817">817</a>         <strong>if</strong> (permanent) {
+<a name="818" href="#818">818</a>             out.print(<span class="string">"Permanent"</span>);
+<a name="819" href="#819">819</a>         } <strong>else</strong> {
+<a name="820" href="#820">820</a>             out.print(<span class="string">"Temporary"</span>);
+<a name="821" href="#821">821</a>         }
+<a name="822" href="#822">822</a>         StringBuffer logBuffer =
+<a name="823" href="#823">823</a>             <strong>new</strong> StringBuffer(64)
+<a name="824" href="#824">824</a>                 .append(<span class="string">" exception delivering mail ("</span>)
+<a name="825" href="#825">825</a>                 .append(mail.getName())
+<a name="826" href="#826">826</a>                 .append(<span class="string">": "</span>);
+<a name="827" href="#827">827</a>         out.print(logBuffer.toString());
+<a name="828" href="#828">828</a>         <strong>if</strong> (isDebug) ex.printStackTrace(out);
+<a name="829" href="#829">829</a>         log(sout.toString());
+<a name="830" href="#830">830</a>         <strong>if</strong> (!permanent) {
+<a name="831" href="#831">831</a>             <strong>if</strong> (!mail.getState().equals(Mail.ERROR)) {
+<a name="832" href="#832">832</a>                 mail.setState(Mail.ERROR);
+<a name="833" href="#833">833</a>                 mail.setErrorMessage(<span class="string">"0"</span>);
+<a name="834" href="#834">834</a>                 mail.setLastUpdated(<strong>new</strong> Date());
+<a name="835" href="#835">835</a>             }
+<a name="836" href="#836">836</a>             <strong>int</strong> retries = Integer.parseInt(mail.getErrorMessage());
+<a name="837" href="#837">837</a>             <strong>if</strong> (retries &lt; maxRetries) {
+<a name="838" href="#838">838</a>                 logBuffer =
+<a name="839" href="#839">839</a>                     <strong>new</strong> StringBuffer(128)
+<a name="840" href="#840">840</a>                             .append(<span class="string">"Storing message "</span>)
+<a name="841" href="#841">841</a>                             .append(mail.getName())
+<a name="842" href="#842">842</a>                             .append(<span class="string">" into outgoing after "</span>)
+<a name="843" href="#843">843</a>                             .append(retries)
+<a name="844" href="#844">844</a>                             .append(<span class="string">" retries"</span>);
+<a name="845" href="#845">845</a>                 log(logBuffer.toString());
+<a name="846" href="#846">846</a>                 ++retries;
+<a name="847" href="#847">847</a>                 mail.setErrorMessage(retries + <span class="string">""</span>);
+<a name="848" href="#848">848</a>                 mail.setLastUpdated(<strong>new</strong> Date());
+<a name="849" href="#849">849</a>                 <strong>return</strong> false;
+<a name="850" href="#850">850</a>             } <strong>else</strong> {
+<a name="851" href="#851">851</a>                 logBuffer =
+<a name="852" href="#852">852</a>                     <strong>new</strong> StringBuffer(128)
+<a name="853" href="#853">853</a>                             .append(<span class="string">"Bouncing message "</span>)
+<a name="854" href="#854">854</a>                             .append(mail.getName())
+<a name="855" href="#855">855</a>                             .append(<span class="string">" after "</span>)
+<a name="856" href="#856">856</a>                             .append(retries)
+<a name="857" href="#857">857</a>                             .append(<span class="string">" retries"</span>);
+<a name="858" href="#858">858</a>                 log(logBuffer.toString());
+<a name="859" href="#859">859</a>             }
 <a name="860" href="#860">860</a>         }
 <a name="861" href="#861">861</a> 
-<a name="862" href="#862">862</a>         <strong>if</strong> (bounceProcessor != <strong>null</strong>) {
-<a name="863" href="#863">863</a>             <em class="comment">// do the new DSN bounce</em>
-<a name="864" href="#864">864</a>             <em class="comment">// setting attributes for DSN mailet</em>
-<a name="865" href="#865">865</a>             mail.setAttribute(<span class="string">"delivery-error"</span>, ex);
-<a name="866" href="#866">866</a>             mail.setState(bounceProcessor);
-<a name="867" href="#867">867</a>             <em class="comment">// re-insert the mail into the spool for getting it passed to the dsn-processor</em>
-<a name="868" href="#868">868</a>             <a href="../../../../../org/apache/mailet/MailetContext.html">MailetContext</a> mc = getMailetContext();
-<a name="869" href="#869">869</a>             <strong>try</strong> {
-<a name="870" href="#870">870</a>                 mc.sendMail(mail);
-<a name="871" href="#871">871</a>             } <strong>catch</strong> (MessagingException e) {
-<a name="872" href="#872">872</a>                 <em class="comment">// we shouldn't get an exception, because the mail was already processed</em>
-<a name="873" href="#873">873</a>                 log(<span class="string">"Exception re-inserting failed mail: "</span>, e);
-<a name="874" href="#874">874</a>             }
-<a name="875" href="#875">875</a>         } <strong>else</strong> {
-<a name="876" href="#876">876</a>             <em class="comment">// do an old style bounce</em>
-<a name="877" href="#877">877</a>             bounce(mail, ex);
-<a name="878" href="#878">878</a>         }
-<a name="879" href="#879">879</a>         <strong>return</strong> <strong>true</strong>;
-<a name="880" href="#880">880</a>     }
-<a name="881" href="#881">881</a> 
-<a name="882" href="#882">882</a>     <strong>private</strong> <strong>void</strong> bounce(<a href="../../../../../org/apache/mailet/Mail.html">Mail</a> mail, MessagingException ex) {
-<a name="883" href="#883">883</a>         StringWriter sout = <strong>new</strong> StringWriter();
-<a name="884" href="#884">884</a>         PrintWriter out = <strong>new</strong> PrintWriter(sout, <strong>true</strong>);
-<a name="885" href="#885">885</a>         String machine = <span class="string">"[unknown]"</span>;
-<a name="886" href="#886">886</a>         <strong>try</strong> {
-<a name="887" href="#887">887</a>             InetAddress me = InetAddress.getLocalHost();
-<a name="888" href="#888">888</a>             machine = me.getHostName();
-<a name="889" href="#889">889</a>         } <strong>catch</strong>(Exception e){
-<a name="890" href="#890">890</a>             machine = <span class="string">"[address unknown]"</span>;
-<a name="891" href="#891">891</a>         }
-<a name="892" href="#892">892</a>         StringBuffer bounceBuffer =
-<a name="893" href="#893">893</a>             <strong>new</strong> StringBuffer(128)
-<a name="894" href="#894">894</a>                     .append(<span class="string">"Hi. This is the James mail server at "</span>)
-<a name="895" href="#895">895</a>                     .append(machine)
-<a name="896" href="#896">896</a>                     .append(<span class="string">"."</span>);
-<a name="897" href="#897">897</a>         out.println(bounceBuffer.toString());
-<a name="898" href="#898">898</a>         out.println(<span class="string">"I'm afraid I wasn't able to deliver your message to the following addresses."</span>);
-<a name="899" href="#899">899</a>         out.println(<span class="string">"This is a permanent error; I've given up. Sorry it didn't work out.  Below"</span>);
-<a name="900" href="#900">900</a>         out.println(<span class="string">"I include the list of recipients and the reason why I was unable to deliver"</span>);
-<a name="901" href="#901">901</a>         out.println(<span class="string">"your message."</span>);
-<a name="902" href="#902">902</a>         out.println();
-<a name="903" href="#903">903</a>         <strong>for</strong> (Iterator i = mail.getRecipients().iterator(); i.hasNext(); ) {
-<a name="904" href="#904">904</a>             out.println(i.next());
-<a name="905" href="#905">905</a>         }
-<a name="906" href="#906">906</a>         <strong>if</strong> (ex.getNextException() == <strong>null</strong>) {
-<a name="907" href="#907">907</a>             out.println(ex.getMessage().trim());
-<a name="908" href="#908">908</a>         } <strong>else</strong> {
-<a name="909" href="#909">909</a>             Exception ex1 = ex.getNextException();
-<a name="910" href="#910">910</a>             <strong>if</strong> (ex1 instanceof SendFailedException) {
-<a name="911" href="#911">911</a>                 out.println(<span class="string">"Remote mail server told me: "</span> + ex1.getMessage().trim());
-<a name="912" href="#912">912</a>             } <strong>else</strong> <strong>if</strong> (ex1 instanceof UnknownHostException) {
-<a name="913" href="#913">913</a>                 out.println(<span class="string">"Unknown host: "</span> + ex1.getMessage().trim());
-<a name="914" href="#914">914</a>                 out.println(<span class="string">"This could be a DNS server error, a typo, or a problem with the recipient's mail server."</span>);
-<a name="915" href="#915">915</a>             } <strong>else</strong> <strong>if</strong> (ex1 instanceof ConnectException) {
-<a name="916" href="#916">916</a>                 <em class="comment">//Already formatted as "Connection timed out: connect"</em>
-<a name="917" href="#917">917</a>                 out.println(ex1.getMessage().trim());
-<a name="918" href="#918">918</a>             } <strong>else</strong> <strong>if</strong> (ex1 instanceof SocketException) {
-<a name="919" href="#919">919</a>                 out.println(<span class="string">"Socket exception: "</span> + ex1.getMessage().trim());
-<a name="920" href="#920">920</a>             } <strong>else</strong> {
-<a name="921" href="#921">921</a>                 out.println(ex1.getMessage().trim());
-<a name="922" href="#922">922</a>             }
-<a name="923" href="#923">923</a>         }
-<a name="924" href="#924">924</a>         out.println();
-<a name="925" href="#925">925</a> 
-<a name="926" href="#926">926</a>         log(<span class="string">"Sending failure message "</span> + mail.getName());
-<a name="927" href="#927">927</a>         <strong>try</strong> {
-<a name="928" href="#928">928</a>             getMailetContext().bounce(mail, sout.toString());
-<a name="929" href="#929">929</a>         } <strong>catch</strong> (MessagingException me) {
-<a name="930" href="#930">930</a>             log(<span class="string">"Encountered unexpected messaging exception while bouncing message: "</span> + me.getMessage());
-<a name="931" href="#931">931</a>         } <strong>catch</strong> (Exception e) {
-<a name="932" href="#932">932</a>             log(<span class="string">"Encountered unexpected exception while bouncing message: "</span> + e.getMessage());
-<a name="933" href="#933">933</a>         }
-<a name="934" href="#934">934</a>     }
-<a name="935" href="#935">935</a> 
-<a name="936" href="#936">936</a>     <strong>public</strong> String getMailetInfo() {
-<a name="937" href="#937">937</a>         <strong>return</strong> <span class="string">"RemoteDelivery Mailet"</span>;
-<a name="938" href="#938">938</a>     }
-<a name="939" href="#939">939</a> 
-<a name="940" href="#940">940</a>     <em>/**<em>*</em></em>
-<a name="941" href="#941">941</a> <em>     * For this message, we take the list of recipients, organize these into distinct</em>
-<a name="942" href="#942">942</a> <em>     * servers, and duplicate the message for each of these servers, and then call</em>
-<a name="943" href="#943">943</a> <em>     * the deliver (messagecontainer) method for each server-specific</em>
-<a name="944" href="#944">944</a> <em>     * messagecontainer ... that will handle storing it in the outgoing queue if needed.</em>
-<a name="945" href="#945">945</a> <em>     *</em>
-<a name="946" href="#946">946</a> <em>     * @param mail org.apache.mailet.Mail</em>
-<a name="947" href="#947">947</a> <em>     */</em>
-<a name="948" href="#948">948</a>     <strong>public</strong> <strong>void</strong> service(<a href="../../../../../org/apache/mailet/Mail.html">Mail</a> mail) throws MessagingException{
-<a name="949" href="#949">949</a>         <em class="comment">// Do I want to give the internal key, or the message's Message ID</em>
-<a name="950" href="#950">950</a>         <strong>if</strong> (isDebug) {
-<a name="951" href="#951">951</a>             log(<span class="string">"Remotely delivering mail "</span> + mail.getName());
-<a name="952" href="#952">952</a>         }
-<a name="953" href="#953">953</a>         Collection recipients = mail.getRecipients();
-<a name="954" href="#954">954</a> 
-<a name="955" href="#955">955</a>         <strong>if</strong> (gatewayServer == <strong>null</strong>) {
-<a name="956" href="#956">956</a>             <em class="comment">// Must first organize the recipients into distinct servers (name made case insensitive)</em>
-<a name="957" href="#957">957</a>             Hashtable targets = <strong>new</strong> Hashtable();
-<a name="958" href="#958">958</a>             <strong>for</strong> (Iterator i = recipients.iterator(); i.hasNext();) {
-<a name="959" href="#959">959</a>                 <a href="../../../../../org/apache/mailet/MailAddress.html">MailAddress</a> target = (MailAddress)i.next();
-<a name="960" href="#960">960</a>                 String targetServer = target.getHost().toLowerCase(Locale.US);
-<a name="961" href="#961">961</a>                 Collection temp = (Collection)targets.get(targetServer);
-<a name="962" href="#962">962</a>                 <strong>if</strong> (temp == <strong>null</strong>) {
-<a name="963" href="#963">963</a>                     temp = <strong>new</strong> ArrayList();
-<a name="964" href="#964">964</a>                     targets.put(targetServer, temp);
-<a name="965" href="#965">965</a>                 }
-<a name="966" href="#966">966</a>                 temp.add(target);
-<a name="967" href="#967">967</a>             }
-<a name="968" href="#968">968</a> 
-<a name="969" href="#969">969</a>             <em class="comment">//We have the recipients organized into distinct servers... put them into the</em>
-<a name="970" href="#970">970</a>             <em class="comment">//delivery store organized like this... this is ultra inefficient I think...</em>
-<a name="971" href="#971">971</a> 
-<a name="972" href="#972">972</a>             <em class="comment">// Store the new message containers, organized by server, in the outgoing mail repository</em>
-<a name="973" href="#973">973</a>             String name = mail.getName();
-<a name="974" href="#974">974</a>             <strong>for</strong> (Iterator i = targets.keySet().iterator(); i.hasNext(); ) {
-<a name="975" href="#975">975</a>                 String host = (String) i.next();
-<a name="976" href="#976">976</a>                 Collection rec = (Collection) targets.get(host);
-<a name="977" href="#977">977</a>                 <strong>if</strong> (isDebug) {
-<a name="978" href="#978">978</a>                     StringBuffer logMessageBuffer =
-<a name="979" href="#979">979</a>                         <strong>new</strong> StringBuffer(128)
-<a name="980" href="#980">980</a>                                 .append(<span class="string">"Sending mail to "</span>)
-<a name="981" href="#981">981</a>                                 .append(rec)
-<a name="982" href="#982">982</a>                                 .append(<span class="string">" on host "</span>)
-<a name="983" href="#983">983</a>                                 .append(host);
-<a name="984" href="#984">984</a>                     log(logMessageBuffer.toString());
-<a name="985" href="#985">985</a>                 }
-<a name="986" href="#986">986</a>                 mail.setRecipients(rec);
-<a name="987" href="#987">987</a>                 StringBuffer nameBuffer =
-<a name="988" href="#988">988</a>                     <strong>new</strong> StringBuffer(128)
-<a name="989" href="#989">989</a>                             .append(name)
-<a name="990" href="#990">990</a>                             .append(<span class="string">"-to-"</span>)
-<a name="991" href="#991">991</a>                             .append(host);
-<a name="992" href="#992">992</a>                 mail.setName(nameBuffer.toString());
-<a name="993" href="#993">993</a>                 outgoing.store(mail);
-<a name="994" href="#994">994</a>                 <em class="comment">//Set it to try to deliver (in a separate thread) immediately (triggered by storage)</em>
-<a name="995" href="#995">995</a>             }
-<a name="996" href="#996">996</a>         } <strong>else</strong> {
-<a name="997" href="#997">997</a>             <em class="comment">// Store the mail unaltered for processing by the gateway server(s)</em>
-<a name="998" href="#998">998</a>             <strong>if</strong> (isDebug) {
-<a name="999" href="#999">999</a>                 StringBuffer logMessageBuffer =
-<a name="1000" href="#1000">1000</a>                     <strong>new</strong> StringBuffer(128)
-<a name="1001" href="#1001">1001</a>                         .append(<span class="string">"Sending mail to "</span>)
-<a name="1002" href="#1002">1002</a>                         .append(mail.getRecipients())
-<a name="1003" href="#1003">1003</a>                         .append(<span class="string">" via "</span>)
-<a name="1004" href="#1004">1004</a>                         .append(gatewayServer);
-<a name="1005" href="#1005">1005</a>                 log(logMessageBuffer.toString());
-<a name="1006" href="#1006">1006</a>             }
-<a name="1007" href="#1007">1007</a> 
-<a name="1008" href="#1008">1008</a>              <em class="comment">//Set it to try to deliver (in a separate thread) immediately (triggered by storage)</em>
-<a name="1009" href="#1009">1009</a>             outgoing.store(mail);
-<a name="1010" href="#1010">1010</a>         }
-<a name="1011" href="#1011">1011</a>         mail.setState(Mail.GHOST);
-<a name="1012" href="#1012">1012</a>     }
-<a name="1013" href="#1013">1013</a> 
-<a name="1014" href="#1014">1014</a>     <em class="comment">// Need to synchronize to get object monitor for notifyAll()</em>
-<a name="1015" href="#1015">1015</a>     <strong>public</strong> <strong>synchronized</strong> <strong>void</strong> destroy() {
-<a name="1016" href="#1016">1016</a>         <em class="comment">//Mark flag so threads from this mailet stop themselves</em>
-<a name="1017" href="#1017">1017</a>         destroyed = <strong>true</strong>;
-<a name="1018" href="#1018">1018</a>         <em class="comment">//Wake up all threads from waiting for an accept</em>
-<a name="1019" href="#1019">1019</a>         <strong>for</strong> (Iterator i = deliveryThreads.iterator(); i.hasNext(); ) {
-<a name="1020" href="#1020">1020</a>             Thread t = (Thread)i.next();
-<a name="1021" href="#1021">1021</a>             t.interrupt();
-<a name="1022" href="#1022">1022</a>         }
-<a name="1023" href="#1023">1023</a>         notifyAll();
-<a name="1024" href="#1024">1024</a>     }
-<a name="1025" href="#1025">1025</a> 
-<a name="1026" href="#1026">1026</a>     <em>/**<em>*</em></em>
-<a name="1027" href="#1027">1027</a> <em>     * Handles checking the outgoing spool for new mail and delivering them if</em>
-<a name="1028" href="#1028">1028</a> <em>     * there are any</em>
-<a name="1029" href="#1029">1029</a> <em>     */</em>
-<a name="1030" href="#1030">1030</a>     <strong>public</strong> <strong>void</strong> run() {
-<a name="1031" href="#1031">1031</a> 
-<a name="1032" href="#1032">1032</a>         <em class="comment">/*<em class="comment"> TODO: CHANGE ME!!! The problem is that we need to wait for James to</em></em>
-<a name="1033" href="#1033">1033</a> <em class="comment">         * finish initializing.  We expect the HELLO_NAME to be put into</em>
-<a name="1034" href="#1034">1034</a> <em class="comment">         * the MailetContext, but in the current configuration we get</em>
-<a name="1035" href="#1035">1035</a> <em class="comment">         * started before the SMTP Server, which establishes the value.</em>
-<a name="1036" href="#1036">1036</a> <em class="comment">         * Since there is no contractual guarantee that there will be a</em>

[... 849 lines stripped ...]