[Yanel-dev] Re: Yanel Patch für MailUtil

Michael Wechner michael.wechner at wyona.com
Tue Sep 7 00:34:08 CEST 2010


done

Sending        src/core/java/org/wyona/yanel/core/util/MailUtil.java
Transmitting file data .
Committed revision 53027.

Thanks again for the patch

Michael

Michael Wechner wrote:
> Michael Wechner wrote:
>> Dear Balz
>>
>> Thanks for your patch, whereas I am not sure if it is a bug or a 
>> feature. I first need to check the history of this class
>
> it seems like this method was modified when we have added a reply-to 
> address:
>
> svn diff -r47277 src/core/java/org/wyona/yanel/core/util/MailUtil.java
> Index: src/core/java/org/wyona/yanel/core/util/MailUtil.java
> ===================================================================
> --- src/core/java/org/wyona/yanel/core/util/MailUtil.java    (revision 
> 47277)
> +++ src/core/java/org/wyona/yanel/core/util/MailUtil.java    (working 
> copy)
> @@ -21,18 +21,46 @@
>
>     /**
>      * @param from From address
> -     * @param from To address
> +     * @param to To address
>      * @param subject Subject of email
>      * @param content Body of email
>      */
>     public static void send(String from, String to, String subject, 
> String content) throws AddressException, MessagingException {
> -        send(null, -1, from, to, subject, content);
> +        send(null, -1, from, null, to, subject, content);
>     }
>
>     /**
> +     * @param from From address
> +     * @param replyTo email address (if null, then no reply-to will 
> be set)
> +     * @param to To address
> +     * @param subject Subject of email
> +     * @param content Body of email
> +     */
> +    public static void send(String from, String replyTo, String to, 
> String subject, String content) throws AddressException, 
> MessagingException {
> +        send(null, -1, from, replyTo, to, subject, content);
> +    }
> +
> +    /**
>      *
>      */
>     public static void send(String smtpHost, int smtpPort, String 
> from, String to, String subject, String content) throws 
> AddressException, MessagingException {
> +        send(null, -1, from, null, to, subject, content);
> +    }
> +
> +    /**
> +     * Send e-mail with a MIME type of "text/plain" and as encoding 
> the platform's default charset
> +     * @param replyTo email address (if null, then no reply-to will 
> be set)
> +     */
> +    public static void send(String smtpHost, int smtpPort, String 
> from, String replyTo, String to, String subject, String content) 
> throws AddressException, MessagingException {
> +        send(smtpHost, smtpPort, from, replyTo, to, subject, content, 
> java.nio.charset.Charset.defaultCharset().name(), "plain");
> +    }
> +
> +    /**
> +     * @param replyTo email address (if null, then no reply-to will 
> be set)
> +     * @param charset Charset, e.g. utf-8
> +     * @param mimeSubType Mime sub-type, e.g. "html" or "plain"
> +     */
> +    public static void send(String smtpHost, int smtpPort, String 
> from, String replyTo, String to, String subject, String content, 
> String charset, String mimeSubType) throws AddressException, 
> MessagingException {
>         // Create a mail session
>         Session session = null;
>         if (smtpHost != null && smtpPort >= 0) {
> @@ -45,16 +73,21 @@
>             java.util.Properties props = new java.util.Properties();
>             props.put("mail.smtp.host", "mail.foo.bar"); // Dummy value
>             props.put("mail.smtp.port", "37"); // Dummy value
> -            session = Session.getDefaultInstance(props, null);
> +            session = Session.getDefaultInstance(props, null); // 
> INFO: The dummy values will be ignored, because Yanel 
> (org.wyona.yanel.core.Yanel) sets during initialization the default 
> session!
>             log.warn("Use default mail session: " + 
> session.getProperty("mail.smtp.host") + ":" + 
> session.getProperty("mail.smtp.port"));
>         }
>
>         // Construct the message
> -        Message msg = new MimeMessage(session);
> +        MimeMessage msg = new MimeMessage(session);
>         msg.setFrom(new InternetAddress(from));
> +        if (replyTo != null) {
> +            InternetAddress[] replyToAddresses = new InternetAddress[1];
> +            replyToAddresses[0] = new InternetAddress(replyTo);
> +            msg.setReplyTo(replyToAddresses);
> +        }
>         msg.setRecipient(Message.RecipientType.TO, new 
> InternetAddress(to));
>         msg.setSubject(subject);
> -        msg.setText(content);
> +        msg.setText(content, charset, mimeSubType);
>
>         // Send the message
>         Transport.send(msg);
>
>
> So yes I would say this is a bug, but which we never noticed, because 
> it was using the mail settings configured within (local.)yanel.xml ...
>
> I will fix it tomorrow after a sleeping cycle ;-)
>
> Cheers
>
> Michael
>>
>> -----
>> svn log src/core/java/org/wyona/yanel/core/util/MailUtil.java
>> ------------------------------------------------------------------------
>> r52649 | michi | 2010-08-24 10:09:58 +0200 (Tue, 24 Aug 2010) | 1 line
>>
>> note about default session added
>> ------------------------------------------------------------------------
>> r52643 | michi | 2010-08-24 09:49:07 +0200 (Tue, 24 Aug 2010) | 1 line
>>
>> enhanced with charset and mime sub-type
>> ------------------------------------------------------------------------
>> r47278 | michi | 2010-01-27 12:13:58 +0100 (Wed, 27 Jan 2010) | 1 line
>>
>> reply to address added
>> ------------------------------------------------------------------------
>> r47265 | michi | 2010-01-27 10:25:38 +0100 (Wed, 27 Jan 2010) | 1 line
>>
>> mail utility class added
>> -------
>>
>> in order to make a decision.
>>
>> Cheers
>>
>> Michael
>>
>> Balz Schreier wrote:
>>> Hallo Michi,
>>>
>>> ich habe einen Patch für MailUtil, siehe Attachment.
>>>
>>> Diff:
>>>
>>> basZeros-MacBook-Pro:trunk baszero$ cat MailUtil_Patch_Balz.diff 
>>> Index: src/core/java/org/wyona/yanel/core/util/MailUtil.java
>>> ===================================================================
>>> --- src/core/java/org/wyona/yanel/core/util/MailUtil.java (revision 
>>> 52939)
>>> +++ src/core/java/org/wyona/yanel/core/util/MailUtil.java (working 
>>> copy)
>>> @@ -44,7 +44,7 @@
>>>       *
>>>       */
>>>      public static void send(String smtpHost, int smtpPort, String 
>>> from, String to, String subject, String content) throws 
>>> AddressException, MessagingException {
>>> -        send(null, -1, from, null, to, subject, content);
>>> +        send(smtpHost, smtpPort, from, null, to, subject, content);
>>>      }
>>>  
>>>      /**
>>>
>>>
>>> Kannst du mir sagen, sobald der Patch im Trunk ist? Ich werde das 
>>> für Zwischengas sicherlich tracken.
>>>
>>> Gruss
>>> Balz
>>
>



More information about the Yanel-development mailing list