javax.activation.MailcapCommandMap Java Examples

The following examples show how to use javax.activation.MailcapCommandMap. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BindingImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static void initializeJavaActivationHandlers() {
    // DataHandler.writeTo() may search for DCH. So adding some default ones.
    try {
        CommandMap map = CommandMap.getDefaultCommandMap();
        if (map instanceof MailcapCommandMap) {
            MailcapCommandMap mailMap = (MailcapCommandMap) map;

            // registering our DCH since javamail's DCH doesn't handle
            if (!cmdMapInitialized(mailMap)) {
                mailMap.addMailcap("text/xml;;x-java-content-handler=com.sun.xml.internal.ws.encoding.XmlDataContentHandler");
                mailMap.addMailcap("application/xml;;x-java-content-handler=com.sun.xml.internal.ws.encoding.XmlDataContentHandler");
                mailMap.addMailcap("image/*;;x-java-content-handler=com.sun.xml.internal.ws.encoding.ImageDataContentHandler");
                mailMap.addMailcap("text/plain;;x-java-content-handler=com.sun.xml.internal.ws.encoding.StringDataContentHandler");
            }
        }
    } catch (Throwable t) {
        // ignore the exception.
    }
}
 
Example #2
Source File: BindingImpl.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private static boolean cmdMapInitialized(MailcapCommandMap mailMap) {
    CommandInfo[] commands = mailMap.getAllCommands("text/xml");
    if (commands == null || commands.length == 0) {
        return false;
    }

    // SAAJ RI implements it's own DataHandlers which can be used for JAX-WS too;
    // see com.sun.xml.internal.messaging.saaj.soap.AttachmentPartImpl#initializeJavaActivationHandlers
    // so if found any of SAAJ or our own handler registered, we are ok; anyway using SAAJ directly here
    // is not good idea since we don't want standalone JAX-WS to depend on specific SAAJ impl.
    // This is also reason for duplication of Handler's code by JAX-WS
    String saajClassName = "com.sun.xml.internal.messaging.saaj.soap.XmlDataContentHandler";
    String jaxwsClassName = "com.sun.xml.internal.ws.encoding.XmlDataContentHandler";
    for (CommandInfo command : commands) {
        String commandClass = command.getCommandClass();
        if (saajClassName.equals(commandClass) ||
                jaxwsClassName.equals(commandClass)) {
            return true;
        }
    }
    return false;
}
 
Example #3
Source File: BindingImpl.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public static void initializeJavaActivationHandlers() {
    // DataHandler.writeTo() may search for DCH. So adding some default ones.
    try {
        CommandMap map = CommandMap.getDefaultCommandMap();
        if (map instanceof MailcapCommandMap) {
            MailcapCommandMap mailMap = (MailcapCommandMap) map;

            // registering our DCH since javamail's DCH doesn't handle
            if (!cmdMapInitialized(mailMap)) {
                mailMap.addMailcap("text/xml;;x-java-content-handler=com.sun.xml.internal.ws.encoding.XmlDataContentHandler");
                mailMap.addMailcap("application/xml;;x-java-content-handler=com.sun.xml.internal.ws.encoding.XmlDataContentHandler");
                mailMap.addMailcap("image/*;;x-java-content-handler=com.sun.xml.internal.ws.encoding.ImageDataContentHandler");
                mailMap.addMailcap("text/plain;;x-java-content-handler=com.sun.xml.internal.ws.encoding.StringDataContentHandler");
            }
        }
    } catch (Throwable t) {
        // ignore the exception.
    }
}
 
Example #4
Source File: BindingImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static boolean cmdMapInitialized(MailcapCommandMap mailMap) {
    CommandInfo[] commands = mailMap.getAllCommands("text/xml");
    if (commands == null || commands.length == 0) {
        return false;
    }

    // SAAJ RI implements it's own DataHandlers which can be used for JAX-WS too;
    // see com.sun.xml.internal.messaging.saaj.soap.AttachmentPartImpl#initializeJavaActivationHandlers
    // so if found any of SAAJ or our own handler registered, we are ok; anyway using SAAJ directly here
    // is not good idea since we don't want standalone JAX-WS to depend on specific SAAJ impl.
    // This is also reason for duplication of Handler's code by JAX-WS
    String saajClassName = "com.sun.xml.internal.messaging.saaj.soap.XmlDataContentHandler";
    String jaxwsClassName = "com.sun.xml.internal.ws.encoding.XmlDataContentHandler";
    for (CommandInfo command : commands) {
        String commandClass = command.getCommandClass();
        if (saajClassName.equals(commandClass) ||
                jaxwsClassName.equals(commandClass)) {
            return true;
        }
    }
    return false;
}
 
Example #5
Source File: BindingImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void initializeJavaActivationHandlers() {
    // DataHandler.writeTo() may search for DCH. So adding some default ones.
    try {
        CommandMap map = CommandMap.getDefaultCommandMap();
        if (map instanceof MailcapCommandMap) {
            MailcapCommandMap mailMap = (MailcapCommandMap) map;

            // registering our DCH since javamail's DCH doesn't handle
            if (!cmdMapInitialized(mailMap)) {
                mailMap.addMailcap("text/xml;;x-java-content-handler=com.sun.xml.internal.ws.encoding.XmlDataContentHandler");
                mailMap.addMailcap("application/xml;;x-java-content-handler=com.sun.xml.internal.ws.encoding.XmlDataContentHandler");
                mailMap.addMailcap("image/*;;x-java-content-handler=com.sun.xml.internal.ws.encoding.ImageDataContentHandler");
                mailMap.addMailcap("text/plain;;x-java-content-handler=com.sun.xml.internal.ws.encoding.StringDataContentHandler");
            }
        }
    } catch (Throwable t) {
        // ignore the exception.
    }
}
 
Example #6
Source File: BindingImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private static boolean cmdMapInitialized(MailcapCommandMap mailMap) {
    CommandInfo[] commands = mailMap.getAllCommands("text/xml");
    if (commands == null || commands.length == 0) {
        return false;
    }

    // SAAJ RI implements it's own DataHandlers which can be used for JAX-WS too;
    // see com.sun.xml.internal.messaging.saaj.soap.AttachmentPartImpl#initializeJavaActivationHandlers
    // so if found any of SAAJ or our own handler registered, we are ok; anyway using SAAJ directly here
    // is not good idea since we don't want standalone JAX-WS to depend on specific SAAJ impl.
    // This is also reason for duplication of Handler's code by JAX-WS
    String saajClassName = "com.sun.xml.internal.messaging.saaj.soap.XmlDataContentHandler";
    String jaxwsClassName = "com.sun.xml.internal.ws.encoding.XmlDataContentHandler";
    for (CommandInfo command : commands) {
        String commandClass = command.getCommandClass();
        if (saajClassName.equals(commandClass) ||
                jaxwsClassName.equals(commandClass)) {
            return true;
        }
    }
    return false;
}
 
Example #7
Source File: BindingImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public static void initializeJavaActivationHandlers() {
    // DataHandler.writeTo() may search for DCH. So adding some default ones.
    try {
        CommandMap map = CommandMap.getDefaultCommandMap();
        if (map instanceof MailcapCommandMap) {
            MailcapCommandMap mailMap = (MailcapCommandMap) map;

            // registering our DCH since javamail's DCH doesn't handle
            if (!cmdMapInitialized(mailMap)) {
                mailMap.addMailcap("text/xml;;x-java-content-handler=com.sun.xml.internal.ws.encoding.XmlDataContentHandler");
                mailMap.addMailcap("application/xml;;x-java-content-handler=com.sun.xml.internal.ws.encoding.XmlDataContentHandler");
                mailMap.addMailcap("image/*;;x-java-content-handler=com.sun.xml.internal.ws.encoding.ImageDataContentHandler");
                mailMap.addMailcap("text/plain;;x-java-content-handler=com.sun.xml.internal.ws.encoding.StringDataContentHandler");
            }
        }
    } catch (Throwable t) {
        // ignore the exception.
    }
}
 
Example #8
Source File: InitJCE.java    From james-project with Apache License 2.0 6 votes vote down vote up
/**
 * Method that registers the security provider BouncyCastle as a system
 * security provider. The provider class is dinamically loaded on runtime so
 * there is no need to include the bouncycastle jar in the James
 * distribution. It can be downloaded and installed by the user if she needs
 * it.
 */        
public static void init() throws InstantiationException, IllegalAccessException, ClassNotFoundException {
    if (!initialized) {
        String bouncyCastleProviderClassName = "org.bouncycastle.jce.provider.BouncyCastleProvider";
        Security.addProvider((Provider)Class.forName(bouncyCastleProviderClassName).newInstance());
        
        MailcapCommandMap mailcap = (MailcapCommandMap) CommandMap.getDefaultCommandMap();

        mailcap.addMailcap("application/pkcs7-signature;; x-java-content-handler=org.bouncycastle.mail.smime.handlers.pkcs7_signature");
        mailcap.addMailcap("application/pkcs7-mime;; x-java-content-handler=org.bouncycastle.mail.smime.handlers.pkcs7_mime");
        mailcap.addMailcap("application/x-pkcs7-signature;; x-java-content-handler=org.bouncycastle.mail.smime.handlers.x_pkcs7_signature");
        mailcap.addMailcap("application/x-pkcs7-mime;; x-java-content-handler=org.bouncycastle.mail.smime.handlers.x_pkcs7_mime");
        mailcap.addMailcap("multipart/signed;; x-java-content-handler=org.bouncycastle.mail.smime.handlers.multipart_signed");

        CommandMap.setDefaultCommandMap(mailcap);
        
        initialized = true;
    }
}
 
Example #9
Source File: BindingImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private static boolean cmdMapInitialized(MailcapCommandMap mailMap) {
    CommandInfo[] commands = mailMap.getAllCommands("text/xml");
    if (commands == null || commands.length == 0) {
        return false;
    }

    // SAAJ RI implements it's own DataHandlers which can be used for JAX-WS too;
    // see com.sun.xml.internal.messaging.saaj.soap.AttachmentPartImpl#initializeJavaActivationHandlers
    // so if found any of SAAJ or our own handler registered, we are ok; anyway using SAAJ directly here
    // is not good idea since we don't want standalone JAX-WS to depend on specific SAAJ impl.
    // This is also reason for duplication of Handler's code by JAX-WS
    String saajClassName = "com.sun.xml.internal.messaging.saaj.soap.XmlDataContentHandler";
    String jaxwsClassName = "com.sun.xml.internal.ws.encoding.XmlDataContentHandler";
    for (CommandInfo command : commands) {
        String commandClass = command.getCommandClass();
        if (saajClassName.equals(commandClass) ||
                jaxwsClassName.equals(commandClass)) {
            return true;
        }
    }
    return false;
}
 
Example #10
Source File: Mail.java    From mobikul-standalone-pos with MIT License 6 votes vote down vote up
public Mail() {
        _host = ApplicationConstants.HOST_FOR_MAIL; // default smtp server
        _port = "465"; // default smtp port
        _sport = "587"; // default socketfactory port

        _user = ""; // username
        _pass = ""; // password
        _from = ""; // email sent from
        _subject = ""; // email subject
        _body = ""; // email body

        _debuggable = false; // debug mode on or off - default off
        _auth = true; // smtp authentication - default on

        _multipart = new MimeMultipart();

// There is something wrong with MailCap, javamail can not find a handler for the multipart
// /mixed part, so this bit needs to be added.
        MailcapCommandMap mc = (MailcapCommandMap) CommandMap.getDefaultCommandMap();
        mc.addMailcap("text/html;; x-java-content-handler=com.sun.mail.handlers.text_html");
        mc.addMailcap("text/xml;; x-java-content-handler=com.sun.mail.handlers.text_xml");
        mc.addMailcap("text/plain;; x-java-content-handler=com.sun.mail.handlers.text_plain");
        mc.addMailcap("multipart/*;; x-java-content-handler=com.sun.mail.handlers.multipart_mixed");
        mc.addMailcap("message/rfc822;; x-java-content-handler=com.sun.mail.handlers.message_rfc822");
        CommandMap.setDefaultCommandMap(mc);
    }
 
Example #11
Source File: BindingImpl.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private static boolean cmdMapInitialized(MailcapCommandMap mailMap) {
    CommandInfo[] commands = mailMap.getAllCommands("text/xml");
    if (commands == null || commands.length == 0) {
        return false;
    }

    // SAAJ RI implements it's own DataHandlers which can be used for JAX-WS too;
    // see com.sun.xml.internal.messaging.saaj.soap.AttachmentPartImpl#initializeJavaActivationHandlers
    // so if found any of SAAJ or our own handler registered, we are ok; anyway using SAAJ directly here
    // is not good idea since we don't want standalone JAX-WS to depend on specific SAAJ impl.
    // This is also reason for duplication of Handler's code by JAX-WS
    String saajClassName = "com.sun.xml.internal.messaging.saaj.soap.XmlDataContentHandler";
    String jaxwsClassName = "com.sun.xml.internal.ws.encoding.XmlDataContentHandler";
    for (CommandInfo command : commands) {
        String commandClass = command.getCommandClass();
        if (saajClassName.equals(commandClass) ||
                jaxwsClassName.equals(commandClass)) {
            return true;
        }
    }
    return false;
}
 
Example #12
Source File: BindingImpl.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public static void initializeJavaActivationHandlers() {
    // DataHandler.writeTo() may search for DCH. So adding some default ones.
    try {
        CommandMap map = CommandMap.getDefaultCommandMap();
        if (map instanceof MailcapCommandMap) {
            MailcapCommandMap mailMap = (MailcapCommandMap) map;

            // registering our DCH since javamail's DCH doesn't handle
            if (!cmdMapInitialized(mailMap)) {
                mailMap.addMailcap("text/xml;;x-java-content-handler=com.sun.xml.internal.ws.encoding.XmlDataContentHandler");
                mailMap.addMailcap("application/xml;;x-java-content-handler=com.sun.xml.internal.ws.encoding.XmlDataContentHandler");
                mailMap.addMailcap("image/*;;x-java-content-handler=com.sun.xml.internal.ws.encoding.ImageDataContentHandler");
                mailMap.addMailcap("text/plain;;x-java-content-handler=com.sun.xml.internal.ws.encoding.StringDataContentHandler");
            }
        }
    } catch (Throwable t) {
        // ignore the exception.
    }
}
 
Example #13
Source File: GMailSender.java    From vocefiscal-android with Apache License 2.0 6 votes vote down vote up
public GMailSender() 
{ 
  host = "smtp.gmail.com"; // default smtp server 
  port = "465"; // default smtp port 
  sport = "465"; // default socketfactory port 

  user = ""; // username 
  pass = ""; // password 
  from = ""; // email sent from 
  subject = ""; // email subject 
  body = ""; // email body 

  debuggable = false; // debug mode on or off - default off 
  auth = true; // smtp authentication - default on 

  multipart = new MimeMultipart(); 

  // There is something wrong with MailCap, javamail can not find a handler for the multipart/mixed part, so this bit needs to be added. 
  MailcapCommandMap mc = (MailcapCommandMap) CommandMap.getDefaultCommandMap(); 
  mc.addMailcap("text/html;; x-java-content-handler=com.sun.mail.handlers.text_html"); 
  mc.addMailcap("text/xml;; x-java-content-handler=com.sun.mail.handlers.text_xml"); 
  mc.addMailcap("text/plain;; x-java-content-handler=com.sun.mail.handlers.text_plain"); 
  mc.addMailcap("multipart/*;; x-java-content-handler=com.sun.mail.handlers.multipart_mixed"); 
  mc.addMailcap("message/rfc822;; x-java-content-handler=com.sun.mail.handlers.message_rfc822"); 
  CommandMap.setDefaultCommandMap(mc); 
}
 
Example #14
Source File: BindingImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static boolean cmdMapInitialized(MailcapCommandMap mailMap) {
    CommandInfo[] commands = mailMap.getAllCommands("text/xml");
    if (commands == null || commands.length == 0) {
        return false;
    }

    // SAAJ RI implements it's own DataHandlers which can be used for JAX-WS too;
    // see com.sun.xml.internal.messaging.saaj.soap.AttachmentPartImpl#initializeJavaActivationHandlers
    // so if found any of SAAJ or our own handler registered, we are ok; anyway using SAAJ directly here
    // is not good idea since we don't want standalone JAX-WS to depend on specific SAAJ impl.
    // This is also reason for duplication of Handler's code by JAX-WS
    String saajClassName = "com.sun.xml.internal.messaging.saaj.soap.XmlDataContentHandler";
    String jaxwsClassName = "com.sun.xml.internal.ws.encoding.XmlDataContentHandler";
    for (CommandInfo command : commands) {
        String commandClass = command.getCommandClass();
        if (saajClassName.equals(commandClass) ||
                jaxwsClassName.equals(commandClass)) {
            return true;
        }
    }
    return false;
}
 
Example #15
Source File: BindingImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void initializeJavaActivationHandlers() {
    // DataHandler.writeTo() may search for DCH. So adding some default ones.
    try {
        CommandMap map = CommandMap.getDefaultCommandMap();
        if (map instanceof MailcapCommandMap) {
            MailcapCommandMap mailMap = (MailcapCommandMap) map;

            // registering our DCH since javamail's DCH doesn't handle
            if (!cmdMapInitialized(mailMap)) {
                mailMap.addMailcap("text/xml;;x-java-content-handler=com.sun.xml.internal.ws.encoding.XmlDataContentHandler");
                mailMap.addMailcap("application/xml;;x-java-content-handler=com.sun.xml.internal.ws.encoding.XmlDataContentHandler");
                mailMap.addMailcap("image/*;;x-java-content-handler=com.sun.xml.internal.ws.encoding.ImageDataContentHandler");
                mailMap.addMailcap("text/plain;;x-java-content-handler=com.sun.xml.internal.ws.encoding.StringDataContentHandler");
            }
        }
    } catch (Throwable t) {
        // ignore the exception.
    }
}
 
Example #16
Source File: EMailService.java    From sailfish-core with Apache License 2.0 5 votes vote down vote up
public EMailService() {
    this.settings = new EMailServiceSettings();

    MailcapCommandMap mailcapCommandMap = new MailcapCommandMap();

    mailcapCommandMap.addMailcap("text/html;; x-java-content-handler=com.sun.mail.handlers.text_html");
    mailcapCommandMap.addMailcap("text/xml;; x-java-content-handler=com.sun.mail.handlers.text_xml");
    mailcapCommandMap.addMailcap("text/plain;; x-java-content-handler=com.sun.mail.handlers.text_plain");
    mailcapCommandMap.addMailcap("multipart/*;; x-java-content-handler=com.sun.mail.handlers.multipart_mixed");
    mailcapCommandMap.addMailcap("message/rfc822;; x-java-content-handler=com.sun.mail.handlers.message_rfc822");

    CommandMap.setDefaultCommandMap(mailcapCommandMap);
}
 
Example #17
Source File: SendMailTask.java    From FlexibleLogin with MIT License 5 votes vote down vote up
@Override
public void run() {
    ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
    try (Transport transport = session.getTransport()) {
        // Prevent UnsupportedDataTypeException: no object DCH for MIME type multipart/alternative
        // cf. https://stackoverflow.com/questions/21856211/unsupporteddatatypeexception-no-object-dch-for-mime-type
        Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
        MailcapCommandMap mc = (MailcapCommandMap) CommandMap.getDefaultCommandMap();
        mc.addMailcap("text/html;; x-java-content-handler=flexiblelogin.mail.handlers.text_html");
        mc.addMailcap("text/xml;; x-java-content-handler=flexiblelogin.mail.handlers.text_xml");
        mc.addMailcap("text/plain;; x-java-content-handler=flexiblelogin.mail.handlers.text_plain");
        mc.addMailcap("multipart/*;; x-java-content-handler=flexiblelogin.mail.handlers.multipart_mixed");
        mc.addMailcap("message/rfc822;; x-java-content- handler=flexiblelogin.mail.handlers.message_rfc822");

        MailConfig mailConfig = plugin.getConfigManager().getGeneral().getMail();

        //connect to host and send message
        if (!transport.isConnected()) {
            String password = mailConfig.getPassword();
            transport.connect(mailConfig.getHost(), mailConfig.getAccount(), password);
        }

        transport.sendMessage(mail, mail.getAllRecipients());
        player.sendMessage(plugin.getConfigManager().getText().getMailSent());
    } catch (NoSuchProviderException providerEx) {
        plugin.getLogger().error("Transport provider not found", providerEx);
        plugin.getLogger().error("Registered providers: {}", Arrays.asList(session.getProviders()));

        player.sendMessage(plugin.getConfigManager().getText().getErrorExecutingCommand());
    } catch (MessagingException messagingEx) {
        plugin.getLogger().error("Error sending mail", messagingEx);
        player.sendMessage(plugin.getConfigManager().getText().getErrorExecutingCommand());
    } finally {
        Thread.currentThread().setContextClassLoader(oldClassLoader);
    }
}
 
Example #18
Source File: BCCryptoHelper.java    From OpenAs2App with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void initialize() {
    Security.addProvider(new BouncyCastleProvider());

    MailcapCommandMap mc = (MailcapCommandMap) CommandMap.getDefaultCommandMap();
    mc.addMailcap("application/pkcs7-signature;; x-java-content-handler=org.bouncycastle.mail.smime.handlers.pkcs7_signature");
    mc.addMailcap("application/pkcs7-mime;; x-java-content-handler=org.bouncycastle.mail.smime.handlers.pkcs7_mime");
    mc.addMailcap("application/x-pkcs7-signature;; x-java-content-handler=org.bouncycastle.mail.smime.handlers.x_pkcs7_signature");
    mc.addMailcap("application/x-pkcs7-mime;; x-java-content-handler=org.bouncycastle.mail.smime.handlers.x_pkcs7_mime");
    mc.addMailcap("multipart/signed;; x-java-content-handler=org.bouncycastle.mail.smime.handlers.multipart_signed");
    CommandMap.setDefaultCommandMap(mc);
}
 
Example #19
Source File: Mail.java    From AccelerationAlert with Apache License 2.0 5 votes vote down vote up
public Mail()
{
	_host = "smtp.gmail.com"; // default smtp server
	_port = "465"; // default smtp port
	_sport = "465"; // default socketfactory port

	_user = ""; // username
	_pass = ""; // password
	_from = ""; // email sent from
	_subject = ""; // email subject
	_body = ""; // email body

	_debuggable = false; // debug mode on or off - default off
	_auth = true; // smtp authentication - default on

	_multipart = new MimeMultipart();

	// There is something wrong with MailCap, javamail can not find a
	// handler for the multipart/mixed part, so this bit needs to be added.
	MailcapCommandMap mc = (MailcapCommandMap) CommandMap
			.getDefaultCommandMap();
	mc.addMailcap("text/html;; x-java-content-handler=com.sun.mail.handlers.text_html");
	mc.addMailcap("text/xml;; x-java-content-handler=com.sun.mail.handlers.text_xml");
	mc.addMailcap("text/plain;; x-java-content-handler=com.sun.mail.handlers.text_plain");
	mc.addMailcap("multipart/*;; x-java-content-handler=com.sun.mail.handlers.multipart_mixed");
	mc.addMailcap("message/rfc822;; x-java-content-handler=com.sun.mail.handlers.message_rfc822");
	CommandMap.setDefaultCommandMap(mc);
}
 
Example #20
Source File: MailClient.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
@Activate
private void activate(){
	MailcapCommandMap mc = (MailcapCommandMap) CommandMap.getDefaultCommandMap();
	mc.addMailcap("text/html;; x-java-content-handler=com.sun.mail.handlers.text_html");
	mc.addMailcap("text/xml;; x-java-content-handler=com.sun.mail.handlers.text_xml");
	mc.addMailcap("text/plain;; x-java-content-handler=com.sun.mail.handlers.text_plain");
	mc.addMailcap("multipart/*;; x-java-content-handler=com.sun.mail.handlers.multipart_mixed");
	mc.addMailcap(
		"message/rfc822;; x-java-content- handler=com.sun.mail.handlers.message_rfc822");
}
 
Example #21
Source File: MailTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
static void workaroundJAFSetup() {
    MailcapCommandMap mailMap = (MailcapCommandMap) CommandMap.getDefaultCommandMap();
    mailMap.addMailcap("multipart/mixed;;x-java-content-handler=com.sun.mail.handlers.multipart_mixed");
}
 
Example #22
Source File: MailTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
static void workaroundJAFSetup() {
    MailcapCommandMap mailMap = (MailcapCommandMap) CommandMap.getDefaultCommandMap();
    mailMap.addMailcap("multipart/mixed;;x-java-content-handler=com.sun.mail.handlers.multipart_mixed");
}
 
Example #23
Source File: MailTest.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
static void workaroundJAFSetup() {
    MailcapCommandMap mailMap = (MailcapCommandMap) CommandMap.getDefaultCommandMap();
    mailMap.addMailcap("multipart/mixed;;x-java-content-handler=com.sun.mail.handlers.multipart_mixed");
}
 
Example #24
Source File: MailTest.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
static void workaroundJAFSetup() {
    MailcapCommandMap mailMap = (MailcapCommandMap) CommandMap.getDefaultCommandMap();
    mailMap.addMailcap("multipart/mixed;;x-java-content-handler=com.sun.mail.handlers.multipart_mixed");
}
 
Example #25
Source File: MailTest.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
static void workaroundJAFSetup() {
    MailcapCommandMap mailMap = (MailcapCommandMap) CommandMap.getDefaultCommandMap();
    mailMap.addMailcap("multipart/mixed;;x-java-content-handler=com.sun.mail.handlers.multipart_mixed");
}
 
Example #26
Source File: MailTest.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
static void workaroundJAFSetup() {
    MailcapCommandMap mailMap = (MailcapCommandMap) CommandMap.getDefaultCommandMap();
    mailMap.addMailcap("multipart/mixed;;x-java-content-handler=com.sun.mail.handlers.multipart_mixed");
}
 
Example #27
Source File: MailDaemon.java    From Open-Lowcode with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * sends invitation
 * 
 * @param session     session connection to the SMTP server
 * @param toemails    list of recipient e-mails
 * @param subject     invitation subject
 * @param body        invitation start
 * @param fromemail   user sending the invitation
 * @param startdate   start date of the invitation
 * @param enddate     end date of the invitation
 * @param location    location of the invitation
 * @param uid         unique id
 * @param cancelation true if this is a cancelation
 */
private void sendInvitation(Session session, String[] toemails, String subject, String body, String fromemail,
		Date startdate, Date enddate, String location, String uid, boolean cancelation) {
	try {
		// prepare mail mime message
		MimetypesFileTypeMap mimetypes = (MimetypesFileTypeMap) MimetypesFileTypeMap.getDefaultFileTypeMap();
		mimetypes.addMimeTypes("text/calendar ics ICS");
		// register the handling of text/calendar mime type
		MailcapCommandMap mailcap = (MailcapCommandMap) MailcapCommandMap.getDefaultCommandMap();
		mailcap.addMailcap("text/calendar;; x-java-content-handler=com.sun.mail.handlers.text_plain");

		MimeMessage msg = new MimeMessage(session);
		// set message headers

		msg.addHeader("Content-type", "text/HTML; charset=UTF-8");
		msg.addHeader("format", "flowed");
		msg.addHeader("Content-Transfer-Encoding", "8bit");
		InternetAddress fromemailaddress = new InternetAddress(fromemail);
		msg.setFrom(fromemailaddress);
		msg.setReplyTo(InternetAddress.parse(fromemail, false));
		msg.setSubject(subject, "UTF-8");
		msg.setSentDate(new Date());

		// set recipient

		InternetAddress[] recipients = new InternetAddress[toemails.length + 1];

		String attendeesinvcalendar = "";
		for (int i = 0; i < toemails.length; i++) {
			recipients[i] = new InternetAddress(toemails[i]);
			attendeesinvcalendar += "ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE:MAILTO:"
					+ toemails[i] + "\n";
		}

		recipients[toemails.length] = fromemailaddress;
		msg.setRecipients(Message.RecipientType.TO, recipients);

		Multipart multipart = new MimeMultipart("alternative");
		// set body
		MimeBodyPart descriptionPart = new MimeBodyPart();
		descriptionPart.setContent(body, "text/html; charset=utf-8");
		multipart.addBodyPart(descriptionPart);

		// set invitation
		BodyPart calendarPart = new MimeBodyPart();

		String method = "METHOD:REQUEST\n";
		if (cancelation)
			method = "METHOD:CANCEL\n";

		String calendarContent = "BEGIN:VCALENDAR\n" + method + "PRODID: BCP - Meeting\n" + "VERSION:2.0\n"
				+ "BEGIN:VEVENT\n" + "DTSTAMP:" + iCalendarDateFormat.format(new Date()) + "\n" + "DTSTART:"
				+ iCalendarDateFormat.format(startdate) + "\n" + "DTEND:" + iCalendarDateFormat.format(enddate)
				+ "\n" + "SUMMARY:" + subject + "\n" + "UID:" + uid + "\n" + attendeesinvcalendar
				+ "ORGANIZER:MAILTO:" + fromemail + "\n" + "LOCATION:" + location + "\n" + "DESCRIPTION:" + subject
				+ "\n" + "SEQUENCE:0\n" + "PRIORITY:5\n" + "CLASS:PUBLIC\n" + "STATUS:CONFIRMED\n"
				+ "TRANSP:OPAQUE\n" + "BEGIN:VALARM\n" + "ACTION:DISPLAY\n" + "DESCRIPTION:REMINDER\n"
				+ "TRIGGER;RELATED=START:-PT00H15M00S\n" + "END:VALARM\n" + "END:VEVENT\n" + "END:VCALENDAR";

		calendarPart.addHeader("Content-Class", "urn:content-classes:calendarmessage");
		calendarPart.setContent(calendarContent, "text/calendar;method=CANCEL");
		multipart.addBodyPart(calendarPart);
		msg.setContent(multipart);
		logger.severe("Invitation is ready");
		Transport.send(msg);

		logger.severe("EMail Invitation Sent Successfully!! to " + attendeesinvcalendar);
	} catch (Exception e) {
		logger.severe(
				"--- Exception in sending invitation --- " + e.getClass().toString() + " - " + e.getMessage());
		if (e.getCause() != null)
			logger.severe(" cause  " + e.getCause().getClass().toString() + " - " + e.getCause().getMessage());
		throw new RuntimeException("email sending error " + e.getMessage() + " for server = server:"
				+ this.smtpserver + " - port:" + this.port + " - user:" + this.user);
	}

}
 
Example #28
Source File: MailTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
static void workaroundJAFSetup() {
    MailcapCommandMap mailMap = (MailcapCommandMap) CommandMap.getDefaultCommandMap();
    mailMap.addMailcap("multipart/mixed;;x-java-content-handler=com.sun.mail.handlers.multipart_mixed");
}
 
Example #29
Source File: MailTest.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
static void workaroundJAFSetup() {
    MailcapCommandMap mailMap = (MailcapCommandMap) CommandMap.getDefaultCommandMap();
    mailMap.addMailcap("multipart/mixed;;x-java-content-handler=com.sun.mail.handlers.multipart_mixed");
}
 
Example #30
Source File: MailTest.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
static void workaroundJAFSetup() {
    MailcapCommandMap mailMap = (MailcapCommandMap) CommandMap.getDefaultCommandMap();
    mailMap.addMailcap("multipart/mixed;;x-java-content-handler=com.sun.mail.handlers.multipart_mixed");
}