List of usage examples for javax.mail.internet MimeUtility encodeText
public static String encodeText(String text, String charset, String encoding) throws UnsupportedEncodingException
From source file:com.stimulus.archiva.presentation.DownloadMessageBean.java
@Override protected StreamInfo getStreamInfo(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { String fileName = request.getParameter("name"); //String fileName = ((MessageBean)form).getOriginalMessageFileName(); logger.debug("download original email {fileName='" + fileName + "'}"); String agent = request.getHeader("USER-AGENT"); if (null != agent && -1 != agent.indexOf("MSIE")) { String codedfilename = URLEncoder.encode(fileName, "UTF8"); response.setContentType("application/x-download"); response.setHeader("Content-Disposition", "attachment;filename=" + codedfilename); } else if (null != agent && -1 != agent.indexOf("Mozilla")) { String codedfilename = MimeUtility.encodeText(fileName, "UTF8", "B"); response.setContentType("application/x-download"); response.setHeader("Content-Disposition", "attachment;filename=" + codedfilename); } else {//w w w .jav a 2s . co m response.setHeader("Content-Disposition", "attachment;filename=" + fileName); } String contentType = "message/rfc822"; //String filePath = ((MessageBean)form).getOriginalMessageFilePath(); String filePath = Config.getFileSystem().getViewPath() + File.separatorChar + fileName; File file = new File(filePath); response.setContentLength((int) file.length()); Config.getFileSystem().getTempFiles().markForDeletion(file); return new FileStreamInfo(contentType, file); }
From source file:com.stimulus.archiva.presentation.DownloadLogBean.java
@Override protected StreamInfo getStreamInfo(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { String fileName = ((ConfigBean) form).getLogFile(); if (fileName == null) { logger.error("failed to download log file as the filename is null"); return null; }/*from w ww . ja v a 2 s . com*/ String agent = request.getHeader("USER-AGENT"); if (null != agent && -1 != agent.indexOf("MSIE")) { String codedfilename = URLEncoder.encode(fileName, "UTF8"); response.setContentType("application/x-download"); response.setHeader("Content-Disposition", "attachment;filename=" + codedfilename); } else if (null != agent && -1 != agent.indexOf("Mozilla")) { String codedfilename = MimeUtility.encodeText(fileName, "UTF8", "B"); response.setContentType("application/x-download"); response.setHeader("Content-Disposition", "attachment;filename=" + codedfilename); } else { response.setHeader("Content-Disposition", "attachment;filename=" + fileName); } File file = ConfigurationService.exportLog(fileName); String viewName = fileName.replace(' ', '_') + ".zip"; logger.debug("download attachment {fileName='" + viewName + "'"); String contentType = "application/download"; response.setContentLength((int) file.length()); Config.getFileSystem().getTempFiles().markForDeletion(file); return new FileStreamInfo(contentType, file); }
From source file:com.stimulus.archiva.presentation.DownloadBean.java
@Override protected StreamInfo getStreamInfo(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { String fileName = request.getParameter("attachment"); //String fileName = ((MessageBean)form).getAttachment(); //File file = new File(((MessageBean)form).getAttachmentFilePath()); String filePath = Config.getFileSystem().getViewPath() + File.separatorChar + fileName; File file = new File(filePath); logger.debug("download attachment {fileName='" + file.getPath() + "'"); String agent = request.getHeader("USER-AGENT"); if (null != agent && -1 != agent.indexOf("MSIE")) { String codedfilename = URLEncoder.encode(fileName, "UTF8"); response.setContentType("application/x-download"); response.setHeader("Content-Disposition", "attachment;filename=" + codedfilename); } else if (null != agent && -1 != agent.indexOf("Mozilla")) { String codedfilename = MimeUtility.encodeText(fileName, "UTF8", "B"); response.setContentType("application/x-download"); response.setHeader("Content-Disposition", "attachment;filename=" + codedfilename); } else {//from ww w .ja v a 2 s .c o m response.setHeader("Content-Disposition", "attachment;filename=" + fileName); } String contentType = "application/download"; response.setContentLength((int) file.length()); Config.getFileSystem().getTempFiles().markForDeletion(file); return new FileStreamInfo(contentType, file); }
From source file:com.stimulus.archiva.presentation.ExportBean.java
@Override protected StreamInfo getStreamInfo(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { SearchBean searchBean = (SearchBean) form; String outputDir = Config.getFileSystem().getViewPath() + File.separatorChar; SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); String zipFileName = "export-" + sdf.format(new Date()) + ".zip"; File zipFile = new File(outputDir + zipFileName); String agent = request.getHeader("USER-AGENT"); if (null != agent && -1 != agent.indexOf("MSIE")) { String codedfilename = URLEncoder.encode(zipFileName, "UTF8"); response.setContentType("application/x-download"); response.setHeader("Content-Disposition", "attachment;filename=" + codedfilename); } else if (null != agent && -1 != agent.indexOf("Mozilla")) { String codedfilename = MimeUtility.encodeText(zipFileName, "UTF8", "B"); response.setContentType("application/x-download"); response.setHeader("Content-Disposition", "attachment;filename=" + codedfilename); } else {// w w w . j a va 2 s.co m response.setHeader("Content-Disposition", "attachment;filename=" + zipFileName); } logger.debug("size of searchResult = " + searchBean.getSearchResults().size()); //MessageBean.viewMessage List<File> files = new ArrayList<File>(); for (SearchResultBean searchResult : searchBean.getSearchResults()) { if (searchResult.getSelected()) { Email email = MessageService.getMessageByID(searchResult.getVolumeID(), searchResult.getUniqueID(), false); HttpServletRequest hsr = ActionContext.getActionContext().getRequest(); String baseURL = hsr.getRequestURL().substring(0, hsr.getRequestURL().lastIndexOf(hsr.getServletPath())); MessageExtraction messageExtraction = MessageService.extractMessage(email, baseURL, true); // can take a while to extract message // MessageBean mbean = new MessageBean(); // mbean.setMessageID(searchResult.getUniqueID()); // mbean.setVolumeID(searchResult.getVolumeID()); // writer.println(searchResult.toString()); // writer.println(messageExtraction.getFileName()); File fileToAdd = new File(outputDir, messageExtraction.getFileName()); if (!files.contains(fileToAdd)) { files.add(fileToAdd); } } } ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zipFile)); try { byte[] buf = new byte[1024]; for (File f : files) { ZipEntry ze = new ZipEntry(f.getName()); logger.debug("Adding file " + f.getName()); zos.putNextEntry(ze); InputStream is = new BufferedInputStream(new FileInputStream(f)); for (;;) { int len = is.read(buf); if (len < 0) break; zos.write(buf, 0, len); } is.close(); Config.getFileSystem().getTempFiles().markForDeletion(f); } } finally { zos.close(); } logger.debug("download zipped emails {fileName='" + zipFileName + "'}"); String contentType = "application/zip"; Config.getFileSystem().getTempFiles().markForDeletion(zipFile); return new FileStreamInfo(contentType, zipFile); }
From source file:br.com.itfox.utils.SendHtmlFormatedEmail.java
public void sendingHtml(String orderDetails, String orderNumber, String toName, String toEmail) { try {/* w w w . j a v a 2 s . c o m*/ // Create the email message HtmlEmail email = new HtmlEmail(); email.setHostName("smtp.gmail.com"); email.setSmtpPort(587); email.setAuthenticator(new DefaultAuthenticator("belchiorpalma@gmail.com", "xp2002b5")); email.setSSLOnConnect(true); email.setTLS(true); email.setFrom("contato@itfox.com.br"); //email.setSubject("TestMail"); email.addTo(toEmail, toName); //email.setFrom("belchiorpalma@me.com", "Me"); //email.setSubject("Test email with inline image"); email.setSubject(MimeUtility.encodeText("Thank you for your order", "UTF-8", "B")); // embed the image and get the content id //URL url = new URL("http://boutiquecellars.com/img/white-wines.jpg"); //String cid = email.embed(url, "BoutiqueCellars.com"); // set the html message email.setHtmlMsg("Thank you for your order\n<br/><br/>" + "\n" + "We received your order #" + orderNumber + " and we are working on it now.\n<br/>" + "We will e-mail you an update as soon as your order is processed.\n<br/>" + "\n<br/>" + "Boutique Cellars team\n" + "\n<br/><br/><img src='http://boutiquecellars.com/img/logoemail.jpg'/> \n" + //orderDetails + "<br/><br/>BOUTIQUE CELLARS SUPPORTS THE RESPONSIBLE SERVICE OF ALCOHOL. NSW: UNDER THE LIQUOR\n<br/>" + "ACT 2007 IT IS AGAINST THE LAW TO SELL OR SUPPLY ALCOHOL TO, OR TO OBTAIN ALCOHOL ON\n<br/>" + "BEHALF OF, A PERSON UNDER THE AGE OF 18 YEARS. NSW PACKAGED LIQUOR LICENCE NUMBER\n<br/>" + "LIQP770016947. YOUR CONTRACT OF SALE IS WITH THE RELEVANT LICENSEE AT THE RELEVANT\n<br/>" + "PREMISES FROM WHICH YOU ORDER IS ACCEPTED AND FULFILLED. LIQUOR IS SOLD FROM OUR\n<br/>" + "PLATFORM ON BEHALF OF THE RELEVANT LICENSEE. ACCORDINGLY, YOUR OFFER TO PURCHASE IS\n<br/>" + "SUBJECT TO ACCEPTANCE OF YOUR OFFER BY THE HOLDER OF THE LIQUOR LICENCE, CERTIFICATION\n<br/>" + "AND EVIDENCE OF YOU BEING OVER 18 YEARS OF AGE, THE AVAILABILITY OF STOCK AND THE\n<br/>" + "LIQUOR WHICH IS THE SUBJECT MATTER OF YOUR OFFER BEING ASCERTAINED AND APPROPRIATED\n<br/>" + "AT THE ABOVE MENTIONED LICENSED PREMISES.<br/><br/>" + " Boutique Cellar Imports Pty Ltd | ABN 69 607 265 618"); // set the alternative message email.setTextMsg( "Thank you for your order, We received your order #18765 and we are working on it now.\n" + "We will e-mail you an update as soon as your order is processed.\n" + "\n" + "Boutique Cellars team"); // send the email email.send(); } catch (EmailException ex) { Logger.getLogger(SendHtmlFormatedEmail.class.getName()).log(Level.SEVERE, null, ex); } catch (UnsupportedEncodingException ex) { Logger.getLogger(SendHtmlFormatedEmail.class.getName()).log(Level.SEVERE, null, ex); } /*} catch (MalformedURLException ex) { Logger.getLogger(SendHtmlFormatedEmail.class.getName()).log(Level.SEVERE, null, ex); }*/ }
From source file:br.com.itfox.beans.SendHtmlFormatedEmail.java
public void sendingHtml() { try {//from www . j a va 2 s . c om // Create the email message HtmlEmail email = new HtmlEmail(); email.setHostName("mail.congressotrt15.com.br"); email.setSmtpPort(587); email.setAuthenticator(new DefaultAuthenticator("congresso@congressotrt15.com.br", "admtrt15xx")); email.setSSLOnConnect(false); //email.setTLS(true); email.setFrom("congresso@congressotrt15.com.br"); email.setSubject("TestMail"); email.addTo("belchiorpalma@gmail.com", "Belchior Palma"); //email.setFrom("belchiorpalma@me.com", "Me"); email.setSubject("Test email with inline image"); email.setSubject(MimeUtility.encodeText("Test email with inline image", "UTF-8", "B")); // embed the image and get the content id URL url = new URL("http://www.apache.org/images/asf_logo_wide.gif"); String cid = email.embed(url, "Apache logo"); // set the html message email.setHtmlMsg("<html>The apache logo - <img src=\"cid:" + cid + "\"></html>"); // set the alternative message email.setTextMsg("Your email client does not support HTML messages"); // send the email email.send(); } catch (EmailException ex) { Logger.getLogger(SendHtmlFormatedEmail.class.getName()).log(Level.SEVERE, null, ex); } catch (UnsupportedEncodingException ex) { Logger.getLogger(SendHtmlFormatedEmail.class.getName()).log(Level.SEVERE, null, ex); } catch (MalformedURLException ex) { Logger.getLogger(SendHtmlFormatedEmail.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:net.duckling.ddl.service.mail.impl.MailServiceImpl.java
private MimeMessage getMessage(Address[] addressArray, String from, String content, String title) throws MessagingException { Session session = Session.getInstance(m_bag.m_mailProperties, m_bag.m_authenticator); session.setDebug(false);/*from ww w . ja v a2 s . c o m*/ SMTPMessage msg = new SMTPMessage(session); if (StringUtils.isNotEmpty(from)) { InternetAddress ss; try { ss = new InternetAddress(m_bag.m_fromAddress.getAddress(), MimeUtility.encodeText(from, "gb2312", "b")); msg.setFrom(ss); } catch (UnsupportedEncodingException e) { msg.setFrom(m_bag.m_fromAddress); } msg.setReplyTo(new InternetAddress[] { new InternetAddress(from) }); } else { msg.setFrom(m_bag.m_fromAddress); } msg.setRecipients(Message.RecipientType.TO, addressArray); try { msg.setSubject(MimeUtility.encodeText(title, UTF_8, "B")); } catch (UnsupportedEncodingException e) { LOG.error(e.getMessage(), e); } msg.setSentDate(new Date()); msg.setContent(content, EMAIL_CONTENT_TYPE); return msg; }
From source file:com.twosigma.beaker.core.module.elfinder.impl.commands.FileCommand.java
private String getAttachementFileName(String fileName, String userAgent) throws UnsupportedEncodingException { if (userAgent != null) { userAgent = userAgent.toLowerCase(); if (userAgent.contains("msie")) { return "filename=\"" + URLEncoder.encode(fileName, "UTF8") + "\""; }/* w w w . j a va 2 s . co m*/ if (userAgent.contains("opera")) { return "filename*=UTF-8''" + URLEncoder.encode(fileName, "UTF8"); } if (userAgent.contains("safari")) { return "filename=\"" + new String(fileName.getBytes("UTF-8"), "ISO8859-1") + "\""; } if (userAgent.contains("applewebkit")) { return "filename=\"" + MimeUtility.encodeText(fileName, "UTF8", "B") + "\""; } if (userAgent.contains("mozilla")) { return "filename*=UTF-8''" + URLEncoder.encode(fileName, "UTF8"); } } return "filename=\"" + URLEncoder.encode(fileName, "UTF8") + "\""; }
From source file:com.mnt.base.mail.MailHelper.java
public static void sendMail(String mailType, String mailTos, Map<String, Object> infoMap) { String[] mailtemplate = loadMailTemplate(mailType); if (mailtemplate != null && mailtemplate.length == 2) { String from = BaseConfiguration.getProperty("mail_server_email"); String subject = buildMailContent(mailtemplate[0], infoMap, false); String mailContent = buildMailContent(mailtemplate[1], infoMap, true); Message msg = new MimeMessage(smtpSession); try {//w w w . j a v a2 s .c om msg.setFrom(new InternetAddress(from)); msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(mailTos, false)); msg.setSubject(MimeUtility.encodeText(subject, "UTF-8", "B")); msg.setContent(mailContent, "text/html;charset=UTF-8"); msg.setSentDate(new Date()); Transport.send(msg); } catch (Exception e) { log.error("fail to send the mail: " + msg, e); } } }
From source file:com.zlfun.framework.misc.UploadUtils.java
public static String getContentDisposition(HttpServletRequest request, String fileName) { String contentDisposition = ""; String browser = getBrowser(request); try {// www .ja v a 2 s .co m if ("IE".equals(browser)) { contentDisposition = "attachment; filename=" + URLEncoder.encode(fileName, "UTF-8").replace("+", "%20"); } else if ("CH".equals(browser)) { contentDisposition = "attachment; filename=" + MimeUtility.encodeText(fileName, "UTF8", "B"); } else if ("SF".equals(browser)) { contentDisposition = "attachment; filename=" + new String(fileName.getBytes("UTF-8"), "ISO8859-1"); } else { contentDisposition = "attachment; filename*=UTF-8''" + URLEncoder.encode(fileName, "UTF-8").replace("+", "%20"); } } catch (UnsupportedEncodingException ex) { Logger.getLogger(UploadUtils.class.getName()).log(Level.SEVERE, null, ex); } return contentDisposition; }