//# 0 errors, 179 messages
//#
/*
    //#mailutils.java:1:1: class: net.sourceforge.pebble.util.MailUtils$SendMailRunnable
    //#mailutils.java:1:1: method: net.sourceforge.pebble.util.MailUtils$SendMailRunnable.net.sourceforge.pebble.util.MailUtils$SendMailRunnable__static_init
    //#mailutils.java:1:1: class: net.sourceforge.pebble.util.MailUtils
 * Copyright (c) 2003-2006, Simon Brown
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *   - Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *
 *   - Redistributions in binary form must reproduce the above copyright
 *     notice, this list of conditions and the following disclaimer in
 *     the documentation and/or other materials provided with the
 *     distribution.
 *
 *   - Neither the name of Pebble nor the names of its contributors may
 *     be used to endorse or promote products derived from this software
 *     without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */
package net.sourceforge.pebble.util;

import net.sourceforge.pebble.domain.Blog;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import net.sourceforge.pebble.web.validation.ValidationContext;
import net.sourceforge.pebble.PebbleContext;

import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeUtility;
import javax.naming.Context;
import javax.naming.InitialContext;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Utilities for e-mail related functions.
 *
 * @author    Simon Brown
 */
public class MailUtils {
    //#mailutils.java:58: method: void net.sourceforge.pebble.util.MailUtils.net.sourceforge.pebble.util.MailUtils()
    //#mailutils.java:58: end of method: void net.sourceforge.pebble.util.MailUtils.net.sourceforge.pebble.util.MailUtils()

  /** the log used by this class */
  private static Log log = LogFactory.getLog(MailUtils.class);
    //#mailutils.java:61: method: net.sourceforge.pebble.util.MailUtils.net.sourceforge.pebble.util.MailUtils__static_init
    //#mailutils.java:61: Warning: method not available
    //#    -- call on Log org.apache.commons.logging.LogFactory:getLog(Class)
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.util.MailUtils
    //#    method: net.sourceforge.pebble.util.MailUtils__static_init
    //#    unanalyzed callee: Log org.apache.commons.logging.LogFactory:getLog(Class)
    //#output(net.sourceforge.pebble.util.MailUtils__static_init): ENCODING
    //#output(net.sourceforge.pebble.util.MailUtils__static_init): __Descendant_Table[net/sourceforge/pebble/util/MailUtils]
    //#output(net.sourceforge.pebble.util.MailUtils__static_init): log
    //#output(net.sourceforge.pebble.util.MailUtils__static_init): pool
    //#post(net.sourceforge.pebble.util.MailUtils__static_init): ENCODING == &"UTF-8"
    //#post(net.sourceforge.pebble.util.MailUtils__static_init): __Descendant_Table[net/sourceforge/pebble/util/MailUtils] == &__Dispatch_Table
    //#post(net.sourceforge.pebble.util.MailUtils__static_init): init'ed(log)
    //#post(net.sourceforge.pebble.util.MailUtils__static_init): init'ed(pool)
    //#mailutils.java:61: method: Log net.sourceforge.pebble.util.MailUtils.access$1()
    //#input(Log access$1()): log
    //#output(Log access$1()): return_value
    //#pre[1] (Log access$1()): init'ed(log)
    //#post(Log access$1()): return_value == log
    //#post(Log access$1()): init'ed(return_value)
    //#mailutils.java:61: end of method: Log net.sourceforge.pebble.util.MailUtils.access$1()
  private static String ENCODING = "UTF-8";
    //#mailutils.java:62: method: String net.sourceforge.pebble.util.MailUtils.access$0()
    //#input(String access$0()): ENCODING
    //#output(String access$0()): return_value
    //#pre[1] (String access$0()): init'ed(ENCODING)
    //#post(String access$0()): return_value == ENCODING
    //#post(String access$0()): init'ed(return_value)
    //#mailutils.java:62: end of method: String net.sourceforge.pebble.util.MailUtils.access$0()

  /** thread pool used to send e-mail */
  private static ExecutorService pool = Executors.newFixedThreadPool(1);
    //#mailutils.java:65: end of method: net.sourceforge.pebble.util.MailUtils.net.sourceforge.pebble.util.MailUtils__static_init

  /**
   * Sends an e-mail.
   *
   * @param blog    the notifying blog
   * @param to     the e-mail addresses of the recipients in the TO field
   * @param subject       the subject of the e-mail
   * @param message       the body of the e-mail
   */
  public static void sendMail(Session session, Blog blog, String to, String subject, String message) {
    Collection set = new HashSet();
    //#mailutils.java:76: method: void net.sourceforge.pebble.util.MailUtils.sendMail(Session, Blog, String, String, String)
    //#input(void sendMail(Session, Blog, String, String, String)): blog
    //#input(void sendMail(Session, Blog, String, String, String)): message
    //#input(void sendMail(Session, Blog, String, String, String)): pool
    //#input(void sendMail(Session, Blog, String, String, String)): session
    //#input(void sendMail(Session, Blog, String, String, String)): subject
    //#input(void sendMail(Session, Blog, String, String, String)): to
    //#pre[3] (void sendMail(Session, Blog, String, String, String)): pool != null
    //#unanalyzed(void sendMail(Session, Blog, String, String, String)): Effects-of-calling:java.util.concurrent.ExecutorService:execute
    set.add(to);
    sendMail(session, blog, set, new HashSet(), new HashSet(), subject, message);
  }
    //#mailutils.java:79: end of method: void net.sourceforge.pebble.util.MailUtils.sendMail(Session, Blog, String, String, String)

  /**
   * Sends an e-mail.
   *
   * @param blog    the notifying blog
   * @param to     the e-mail addresses of the recipients in the TO field
   * @param subject       the subject of the e-mail
   * @param message       the body of the e-mail
   */
  public static void sendMail(Session session, Blog blog, Collection to, String subject, String message) {
    sendMail(session, blog, to, new HashSet(), new HashSet(), subject, message);
    //#mailutils.java:90: method: void net.sourceforge.pebble.util.MailUtils.sendMail(Session, Blog, Collection, String, String)
    //#input(void sendMail(Session, Blog, Collection, String, String)): blog
    //#input(void sendMail(Session, Blog, Collection, String, String)): message
    //#input(void sendMail(Session, Blog, Collection, String, String)): pool
    //#input(void sendMail(Session, Blog, Collection, String, String)): session
    //#input(void sendMail(Session, Blog, Collection, String, String)): subject
    //#input(void sendMail(Session, Blog, Collection, String, String)): to
    //#pre[3] (void sendMail(Session, Blog, Collection, String, String)): pool != null
    //#unanalyzed(void sendMail(Session, Blog, Collection, String, String)): Effects-of-calling:java.util.concurrent.ExecutorService:execute
  }
    //#mailutils.java:91: end of method: void net.sourceforge.pebble.util.MailUtils.sendMail(Session, Blog, Collection, String, String)

  /**
   * Sends an e-mail.
   *
   * @param blog    the notifying blog
   * @param to     the e-mail addresses of the recipients in the TO field
   * @param cc     the e-mail addresses of the recipients in the CC field
   * @param subject       the subject of the e-mail
   * @param message       the body of the e-mail
   */
  public static void sendMail(Session session, Blog blog, Collection to, Collection cc, String subject, String message) {
    sendMail(session, blog, to, cc, new HashSet(), subject, message);
    //#mailutils.java:103: method: void net.sourceforge.pebble.util.MailUtils.sendMail(Session, Blog, Collection, Collection, String, String)
    //#input(void sendMail(Session, Blog, Collection, Collection, String, String)): blog
    //#input(void sendMail(Session, Blog, Collection, Collection, String, String)): cc
    //#input(void sendMail(Session, Blog, Collection, Collection, String, String)): message
    //#input(void sendMail(Session, Blog, Collection, Collection, String, String)): pool
    //#input(void sendMail(Session, Blog, Collection, Collection, String, String)): session
    //#input(void sendMail(Session, Blog, Collection, Collection, String, String)): subject
    //#input(void sendMail(Session, Blog, Collection, Collection, String, String)): to
    //#pre[4] (void sendMail(Session, Blog, Collection, Collection, String, String)): pool != null
    //#unanalyzed(void sendMail(Session, Blog, Collection, Collection, String, String)): Effects-of-calling:java.util.concurrent.ExecutorService:execute
  }
    //#mailutils.java:104: end of method: void net.sourceforge.pebble.util.MailUtils.sendMail(Session, Blog, Collection, Collection, String, String)

  /**
   * Sends an e-mail.
   *
   * @param blog    the notifying blog
   * @param to     the e-mail addresses of the recipients in the TO field
   * @param cc     the e-mail addresses of the recipients in the CC field
   * @param bcc     the e-mail addresses of the recipients in the BCC field
   * @param subject       the subject of the e-mail
   * @param message       the body of the e-mail
   */
  public static void sendMail(Session session, Blog blog, Collection to, Collection cc, Collection bcc, String subject, String message) {
    Runnable r = new SendMailRunnable(session, blog, to, cc, bcc, subject, message);
    //#mailutils.java:117: method: void net.sourceforge.pebble.util.MailUtils.sendMail(Session, Blog, Collection, Collection, Collection, String, String)
    //#input(void sendMail(Session, Blog, Collection, Collection, Collection, String, String)): bcc
    //#input(void sendMail(Session, Blog, Collection, Collection, Collection, String, String)): blog
    //#input(void sendMail(Session, Blog, Collection, Collection, Collection, String, String)): cc
    //#input(void sendMail(Session, Blog, Collection, Collection, Collection, String, String)): message
    //#input(void sendMail(Session, Blog, Collection, Collection, Collection, String, String)): pool
    //#input(void sendMail(Session, Blog, Collection, Collection, Collection, String, String)): session
    //#input(void sendMail(Session, Blog, Collection, Collection, Collection, String, String)): subject
    //#input(void sendMail(Session, Blog, Collection, Collection, Collection, String, String)): to
    //#pre[5] (void sendMail(Session, Blog, Collection, Collection, Collection, String, String)): pool != null
    pool.execute(r);
  }
    //#mailutils.java:119: end of method: void net.sourceforge.pebble.util.MailUtils.sendMail(Session, Blog, Collection, Collection, Collection, String, String)

  /**
   * A thread allowing the e-mail to be sent asynchronously, so the requesting
   * thread (and therefore the user) isn't held up.
   */
  static class SendMailRunnable implements Runnable {

    /** the JavaMail session */
    private Session session;

    /** the notifying blog */
    private Blog blog;

    /** the e-mail addresses of the recipients in the TO field */
    private Collection to;

    /** the e-mail addresses of the recipients in the CC field */
    private Collection cc;

    /** the e-mail addresses of the recipients in the BCC field */
    private Collection bcc;

    /** the subject of the e-mail */
    private String subject;

    /** the body of the e-mail */
    private String message;

    /**
     * Creates a new thread to send a new e-mail.
     *
     * @param session   a JavaMail Session instance
     * @param blog    the notifying blog
     * @param to     the e-mail addresses of the recipients in the TO field
     * @param cc     the e-mail addresses of the recipients in the CC field
     * @param bcc     the e-mail addresses of the recipients in the BCC field
     * @param subject       the subject of the e-mail
     * @param message       the body of the e-mail
     */
    public SendMailRunnable(Session session, Blog blog, Collection to, Collection cc, Collection bcc, String subject, String message) {
    //#mailutils.java:159: method: void net.sourceforge.pebble.util.MailUtils$SendMailRunnable.net.sourceforge.pebble.util.MailUtils$SendMailRunnable(Session, Blog, Collection, Collection, Collection, String, String)
    //#input(void net.sourceforge.pebble.util.MailUtils$SendMailRunnable(Session, Blog, Collection, Collection, Collection, String, String)): bcc
    //#input(void net.sourceforge.pebble.util.MailUtils$SendMailRunnable(Session, Blog, Collection, Collection, Collection, String, String)): blog
    //#input(void net.sourceforge.pebble.util.MailUtils$SendMailRunnable(Session, Blog, Collection, Collection, Collection, String, String)): cc
    //#input(void net.sourceforge.pebble.util.MailUtils$SendMailRunnable(Session, Blog, Collection, Collection, Collection, String, String)): message
    //#input(void net.sourceforge.pebble.util.MailUtils$SendMailRunnable(Session, Blog, Collection, Collection, Collection, String, String)): session
    //#input(void net.sourceforge.pebble.util.MailUtils$SendMailRunnable(Session, Blog, Collection, Collection, Collection, String, String)): subject
    //#input(void net.sourceforge.pebble.util.MailUtils$SendMailRunnable(Session, Blog, Collection, Collection, Collection, String, String)): this
    //#input(void net.sourceforge.pebble.util.MailUtils$SendMailRunnable(Session, Blog, Collection, Collection, Collection, String, String)): to
    //#output(void net.sourceforge.pebble.util.MailUtils$SendMailRunnable(Session, Blog, Collection, Collection, Collection, String, String)): this.bcc
    //#output(void net.sourceforge.pebble.util.MailUtils$SendMailRunnable(Session, Blog, Collection, Collection, Collection, String, String)): this.blog
    //#output(void net.sourceforge.pebble.util.MailUtils$SendMailRunnable(Session, Blog, Collection, Collection, Collection, String, String)): this.cc
    //#output(void net.sourceforge.pebble.util.MailUtils$SendMailRunnable(Session, Blog, Collection, Collection, Collection, String, String)): this.message
    //#output(void net.sourceforge.pebble.util.MailUtils$SendMailRunnable(Session, Blog, Collection, Collection, Collection, String, String)): this.session
    //#output(void net.sourceforge.pebble.util.MailUtils$SendMailRunnable(Session, Blog, Collection, Collection, Collection, String, String)): this.subject
    //#output(void net.sourceforge.pebble.util.MailUtils$SendMailRunnable(Session, Blog, Collection, Collection, Collection, String, String)): this.to
    //#post(void net.sourceforge.pebble.util.MailUtils$SendMailRunnable(Session, Blog, Collection, Collection, Collection, String, String)): this.bcc == bcc
    //#post(void net.sourceforge.pebble.util.MailUtils$SendMailRunnable(Session, Blog, Collection, Collection, Collection, String, String)): init'ed(this.bcc)
    //#post(void net.sourceforge.pebble.util.MailUtils$SendMailRunnable(Session, Blog, Collection, Collection, Collection, String, String)): this.blog == blog
    //#post(void net.sourceforge.pebble.util.MailUtils$SendMailRunnable(Session, Blog, Collection, Collection, Collection, String, String)): init'ed(this.blog)
    //#post(void net.sourceforge.pebble.util.MailUtils$SendMailRunnable(Session, Blog, Collection, Collection, Collection, String, String)): this.cc == cc
    //#post(void net.sourceforge.pebble.util.MailUtils$SendMailRunnable(Session, Blog, Collection, Collection, Collection, String, String)): init'ed(this.cc)
    //#post(void net.sourceforge.pebble.util.MailUtils$SendMailRunnable(Session, Blog, Collection, Collection, Collection, String, String)): this.message == message
    //#post(void net.sourceforge.pebble.util.MailUtils$SendMailRunnable(Session, Blog, Collection, Collection, Collection, String, String)): init'ed(this.message)
    //#post(void net.sourceforge.pebble.util.MailUtils$SendMailRunnable(Session, Blog, Collection, Collection, Collection, String, String)): this.session == session
    //#post(void net.sourceforge.pebble.util.MailUtils$SendMailRunnable(Session, Blog, Collection, Collection, Collection, String, String)): init'ed(this.session)
    //#post(void net.sourceforge.pebble.util.MailUtils$SendMailRunnable(Session, Blog, Collection, Collection, Collection, String, String)): this.subject == subject
    //#post(void net.sourceforge.pebble.util.MailUtils$SendMailRunnable(Session, Blog, Collection, Collection, Collection, String, String)): init'ed(this.subject)
    //#post(void net.sourceforge.pebble.util.MailUtils$SendMailRunnable(Session, Blog, Collection, Collection, Collection, String, String)): this.to == to
    //#post(void net.sourceforge.pebble.util.MailUtils$SendMailRunnable(Session, Blog, Collection, Collection, Collection, String, String)): init'ed(this.to)
      this.session = session;
      this.blog = blog;
      this.to = to;
      this.cc = cc;
      this.bcc = bcc;
      this.subject = subject;
      this.message = message;
    }
    //#mailutils.java:167: end of method: void net.sourceforge.pebble.util.MailUtils$SendMailRunnable.net.sourceforge.pebble.util.MailUtils$SendMailRunnable(Session, Blog, Collection, Collection, Collection, String, String)

    /**
     * Performs the processing associated with this thread.
     */
    public void run() {
      try {
        // create a message and try to send it
        Message msg = new MimeMessage(session);
    //#mailutils.java:175: method: void net.sourceforge.pebble.util.MailUtils$SendMailRunnable.run()
    //#input(void run()): javax.mail.Message$RecipientType.BCC
    //#input(void run()): javax.mail.Message$RecipientType.CC
    //#input(void run()): javax.mail.Message$RecipientType.TO
    //#input(void run()): net/sourceforge/pebble/util/MailUtils.ENCODING
    //#input(void run()): net/sourceforge/pebble/util/MailUtils.log
    //#input(void run()): this
    //#input(void run()): this.bcc
    //#input(void run()): this.blog
    //#input(void run()): this.cc
    //#input(void run()): this.message
    //#input(void run()): this.session
    //#input(void run()): this.subject
    //#input(void run()): this.to
    //#pre[2] (void run()): net/sourceforge/pebble/util/MailUtils.log != null
    //#pre[1] (void run()): (soft) init'ed(net/sourceforge/pebble/util/MailUtils.ENCODING)
    //#pre[4] (void run()): (soft) this.bcc != null
    //#pre[5] (void run()): (soft) this.blog != null
    //#pre[6] (void run()): (soft) this.cc != null
    //#pre[7] (void run()): (soft) init'ed(this.message)
    //#pre[8] (void run()): (soft) init'ed(this.session)
    //#pre[9] (void run()): (soft) init'ed(this.subject)
    //#pre[10] (void run()): (soft) this.to != null
    //#presumption(void run()): java.util.Iterator:next(...)@180 != null
    //#presumption(void run()): java.util.Iterator:next(...)@187 != null
    //#presumption(void run()): java.util.Iterator:next(...)@194 != null
    //#presumption(void run()): init'ed(javax.mail.Message$RecipientType.BCC)
    //#presumption(void run()): init'ed(javax.mail.Message$RecipientType.CC)
    //#presumption(void run()): init'ed(javax.mail.Message$RecipientType.TO)
    //#test_vector(void run()): java.util.Iterator:hasNext(...)@179: {1}, {0}
    //#test_vector(void run()): java.util.Iterator:hasNext(...)@186: {1}, {0}
    //#test_vector(void run()): java.util.Iterator:hasNext(...)@193: {1}, {0}
        msg.setFrom(new InternetAddress(blog.getFirstEmailAddress(), MimeUtility.encodeText(blog.getName(), ENCODING, "B")));
    //#mailutils.java:176: Warning: method not available
    //#    -- call on String net.sourceforge.pebble.domain.Blog:getFirstEmailAddress()
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.util.MailUtils$SendMailRunnable
    //#    method: void run()
    //#    unanalyzed callee: String net.sourceforge.pebble.domain.Blog:getFirstEmailAddress()
    //#mailutils.java:176: Warning: method not available
    //#    -- call on String net.sourceforge.pebble.domain.Blog:getName()
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.util.MailUtils$SendMailRunnable
    //#    method: void run()
    //#    unanalyzed callee: String net.sourceforge.pebble.domain.Blog:getName()
        Collection internetAddresses = new HashSet();
        Iterator it = to.iterator();
        while (it.hasNext()) {
          internetAddresses.add(new InternetAddress(it.next().toString()));
        }
        msg.addRecipients(Message.RecipientType.TO, (InternetAddress[])internetAddresses.toArray(new InternetAddress[]{}));

        internetAddresses = new HashSet();
        it = cc.iterator();
        while (it.hasNext()) {
          internetAddresses.add(new InternetAddress(it.next().toString()));
        }
        msg.addRecipients(Message.RecipientType.CC, (InternetAddress[])internetAddresses.toArray(new InternetAddress[]{}));

        internetAddresses = new HashSet();
        it = bcc.iterator();
        while (it.hasNext()) {
          internetAddresses.add(new InternetAddress(it.next().toString()));
        }
        msg.addRecipients(Message.RecipientType.BCC, (InternetAddress[])internetAddresses.toArray(new InternetAddress[]{}));

        msg.setSubject(MimeUtility.encodeText(subject, ENCODING, "B"));
        msg.setSentDate(new Date());
        msg.setContent(message, "text/html; charset=" + ENCODING);

        log.debug("From : " + blog.getName() + " (" + blog.getFirstEmailAddress() + ")");
    //#mailutils.java:202: Warning: method not available
    //#    -- call on String net.sourceforge.pebble.domain.Blog:getName()
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.util.MailUtils$SendMailRunnable
    //#    method: void run()
    //#    unanalyzed callee: String net.sourceforge.pebble.domain.Blog:getName()
    //#mailutils.java:202: Warning: method not available
    //#    -- call on String net.sourceforge.pebble.domain.Blog:getFirstEmailAddress()
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.util.MailUtils$SendMailRunnable
    //#    method: void run()
    //#    unanalyzed callee: String net.sourceforge.pebble.domain.Blog:getFirstEmailAddress()
    //#mailutils.java:202: Warning: method not available
    //#    -- call on void org.apache.commons.logging.Log:debug(Object)
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.util.MailUtils$SendMailRunnable
    //#    method: void run()
    //#    unanalyzed callee: void org.apache.commons.logging.Log:debug(Object)
        log.debug("Subject : " + subject);
    //#mailutils.java:203: Warning: method not available
    //#    -- call on void org.apache.commons.logging.Log:debug(Object)
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.util.MailUtils$SendMailRunnable
    //#    method: void run()
    //#    unanalyzed callee: void org.apache.commons.logging.Log:debug(Object)
        log.debug("Message : " + message);
    //#mailutils.java:204: Warning: method not available
    //#    -- call on void org.apache.commons.logging.Log:debug(Object)
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.util.MailUtils$SendMailRunnable
    //#    method: void run()
    //#    unanalyzed callee: void org.apache.commons.logging.Log:debug(Object)

        Transport.send(msg);
      } catch (Exception e) {
        log.error("Notification e-mail could not be sent", e);
    //#mailutils.java:208: Warning: method not available
    //#    -- call on void org.apache.commons.logging.Log:error(Object, Throwable)
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.util.MailUtils$SendMailRunnable
    //#    method: void run()
    //#    unanalyzed callee: void org.apache.commons.logging.Log:error(Object, Throwable)
      }
    }
    //#mailutils.java:210: end of method: void net.sourceforge.pebble.util.MailUtils$SendMailRunnable.run()

  }

  /**
   * Creates a reference to a JavaMail Session.
   *
   * @return  a Session instance
   * @throws Exception    if something goes wrong creating a session
   */
  public static Session createSession() throws Exception {
    String ref = PebbleContext.getInstance().getConfiguration().getSmtpHost();
    //#mailutils.java:221: method: Session net.sourceforge.pebble.util.MailUtils.createSession()
    //#mailutils.java:221: Warning: method not available
    //#    -- call on String net.sourceforge.pebble.Configuration:getSmtpHost()
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.util.MailUtils
    //#    method: Session createSession()
    //#    unanalyzed callee: String net.sourceforge.pebble.Configuration:getSmtpHost()
    //#input(Session createSession()): net.sourceforge.pebble.PebbleContext__static_init.new PebbleContext(PebbleContext__static_init#1).__Tag
    //#input(Session createSession()): net.sourceforge.pebble.PebbleContext__static_init.new PebbleContext(PebbleContext__static_init#1).configuration
    //#input(Session createSession()): net/sourceforge/pebble/PebbleContext.__Descendant_Table[net/sourceforge/pebble/PebbleContext]
    //#input(Session createSession()): net/sourceforge/pebble/PebbleContext.__Dispatch_Table.getConfiguration()Lnet/sourceforge/pebble/Configuration;
    //#input(Session createSession()): net/sourceforge/pebble/PebbleContext.instance
    //#output(Session createSession()): return_value
    //#pre[1] (Session createSession()): net.sourceforge.pebble.PebbleContext__static_init.new PebbleContext(PebbleContext__static_init#1).configuration != null
    //#presumption(Session createSession()): net.sourceforge.pebble.Configuration:getSmtpHost(...)@221 != null
    //#post(Session createSession()): init'ed(return_value)
    //#test_vector(Session createSession()): java.lang.String:startsWith(...)@222: {0}, {1}
    if (ref.startsWith("java:comp/env")) {
      // this is a JNDI based mail session
      Context ctx = new InitialContext();
      return (Session)ctx.lookup(ref);
    } else {
      // this is a simple SMTP hostname based session
      Properties props = new Properties();
      props.put("mail.smtp.host", ref);
      return Session.getDefaultInstance(props, null);
    //#mailutils.java:230: end of method: Session net.sourceforge.pebble.util.MailUtils.createSession()
    }
  }

  /**
   * Validates the given comment.
   *
   * @param email   the Comment instance to validate
   * @param context   the context in which to perform validation
   */
  public static void validate(String email, ValidationContext context) {
    if (email != null) {
    //#mailutils.java:241: method: void net.sourceforge.pebble.util.MailUtils.validate(String, ValidationContext)
    //#input(void validate(String, ValidationContext)): context
    //#input(void validate(String, ValidationContext)): context.__Tag
    //#input(void validate(String, ValidationContext)): context.errors
    //#input(void validate(String, ValidationContext)): email
    //#input(void validate(String, ValidationContext)): net/sourceforge/pebble/web/validation/ValidationContext.__Descendant_Table[net/sourceforge/pebble/web/validation/ValidationContext]
    //#input(void validate(String, ValidationContext)): net/sourceforge/pebble/web/validation/ValidationContext.__Descendant_Table[others]
    //#input(void validate(String, ValidationContext)): net/sourceforge/pebble/web/validation/ValidationContext.__Dispatch_Table.addError(Ljava/lang/String;)V
    //#input(void validate(String, ValidationContext)): net/sourceforge/pebble/web/validation/ValidationContext.__Dispatch_Table.addError(Lnet/sourceforge/pebble/web/validation/ValidationError;)V
    //#pre[1] (void validate(String, ValidationContext)): (soft) context != null
    //#pre[2] (void validate(String, ValidationContext)): (soft) context.__Tag == net/sourceforge/pebble/web/validation/ValidationContext
    //#pre[3] (void validate(String, ValidationContext)): (soft) context.errors != null
    //#unanalyzed(void validate(String, ValidationContext)): Effects-of-calling:java.util.List:add
    //#test_vector(void validate(String, ValidationContext)): email: Addr_Set{null}, Inverse{null}
      try {
        InternetAddress ia = new InternetAddress(email, true);
        ia.validate();
      } catch (AddressException aex) {
        context.addError(aex.getMessage() + ": " + email);
      }
    }
  }
    //#mailutils.java:249: end of method: void net.sourceforge.pebble.util.MailUtils.validate(String, ValidationContext)

}
    //#output(net.sourceforge.pebble.util.MailUtils$SendMailRunnable__static_init): __Descendant_Table[net/sourceforge/pebble/util/MailUtils$SendMailRunnable]
    //#output(net.sourceforge.pebble.util.MailUtils$SendMailRunnable__static_init): __Dispatch_Table.run()V
    //#post(net.sourceforge.pebble.util.MailUtils$SendMailRunnable__static_init): __Descendant_Table[net/sourceforge/pebble/util/MailUtils$SendMailRunnable] == &__Dispatch_Table
    //#post(net.sourceforge.pebble.util.MailUtils$SendMailRunnable__static_init): __Dispatch_Table.run()V == &run
    //#mailutils.java:: end of method: net.sourceforge.pebble.util.MailUtils$SendMailRunnable.net.sourceforge.pebble.util.MailUtils$SendMailRunnable__static_init
    //#mailutils.java:: end of class: net.sourceforge.pebble.util.MailUtils$SendMailRunnable
    //#mailutils.java:: end of class: net.sourceforge.pebble.util.MailUtils
