List of usage examples for javax.mail.internet InternetHeaders InternetHeaders
public InternetHeaders()
From source file:es.pode.administracion.presentacion.estructuraseducativas.arboles.alta.AltaArbolesControllerImpl.java
public final void nuevoArbol(ActionMapping mapping, NuevoArbolForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { VdexVO[] resultado = null;// w w w. j ava2 s . co m List ficheros = new ArrayList(); if (form.getFichero1() != null && form.getFichero1().getFileName() != null && !form.getFichero1().getFileName().equals(""))//&& form.getFichero1().getFileSize()>0 ficheros.add(form.getFichero1()); if (form.getFichero2() != null && form.getFichero2().getFileName() != null && !form.getFichero2().getFileName().equals("")) ficheros.add(form.getFichero2()); if (form.getFichero3() != null && form.getFichero3().getFileName() != null && !form.getFichero3().getFileName().equals("")) ficheros.add(form.getFichero3()); if (form.getFichero4() != null && form.getFichero4().getFileName() != null && !form.getFichero4().getFileName().equals("")) ficheros.add(form.getFichero4()); if (form.getFichero5() != null && form.getFichero5().getFileName() != null && !form.getFichero5().getFileName().equals("")) ficheros.add(form.getFichero5()); if (ficheros.size() == 0) { throw new ValidatorException("{estructuras.arboles.error.fichero.vacio}"); } List arrayParam = new ArrayList(); InternetHeaders ih = new InternetHeaders(); MimeBodyPart mbp = null; DataSource source = null; DataHandler dh = null; for (int i = 0; i < ficheros.size(); i++) { try { FormFile ff = (FormFile) ficheros.get(i); mbp = new MimeBodyPart(ih, ff.getFileData()); source = new MimePartDataSource(mbp); dh = new DataHandler(source); arrayParam.add(new ParamVdexVO(dh, ff.getFileName())); } catch (Exception e) { if (logger.isDebugEnabled()) { logger.debug("error al cargar la lista de paramVDEXVO"); } } } try { SrvEstructurasEducativasService servicio = this.getSrvEstructurasEducativasService(); resultado = servicio.subirArbolesCurriculares((ParamVdexVO[]) arrayParam.toArray(new ParamVdexVO[0])); for (int i = 0; i < resultado.length; i++) { String[] nombreVdex = new String[1]; nombreVdex[0] = ((FormFile) ficheros.get(i)).getFileName(); if (resultado[i].getCodigoError() != null && !resultado[i].getCodigoError().equals("")) { logger.debug("hubo un error al crear el nuevo arbol, se muestra el error en la jsp"); this.saveErrorMessage(request, "estructuras.error.alta." + resultado[i].getCodigoError(), nombreVdex); } else { this.saveSuccessMessage(request, "estructuras.arboles.alta.exito", nombreVdex); } } } catch (Exception e) { if (logger.isDebugEnabled()) { logger.debug("error al dar de alta lista de arboles"); } this.saveErrorMessage(request, "estructuras.error.alta.0"); } }
From source file:mitm.common.mail.BodyPartUtils.java
/** * This is the only way I know of to create a new MimeBodyPart from another MimeBodyPart which is safe * for signed email. All other methods break the signature when quoted printable soft breaks are used. * //from www .ja v a 2s. c o m * example of quoted printable soft breaks: * * Content-Transfer-Encoding: quoted-printable * soft break example = * another line = * * All other methods will re-encode and removes the soft breaks. * * @param sourceMessage * @param matcher * @return * @throws IOException * @throws MessagingException */ @SuppressWarnings("unchecked") public static MimeBodyPart makeContentBodyPartRawBytes(MimeBodyPart sourceMessage, HeaderMatcher matcher) throws IOException, MessagingException { /* * getRawInputStream() can throw a MessagingException when the source message is a MimeMessage * that is created in code (ie. not from a stream) */ InputStream messageStream = sourceMessage.getRawInputStream(); byte[] rawMessage = IOUtils.toByteArray(messageStream); InternetHeaders destinationHeaders = new InternetHeaders(); Enumeration<Header> sourceHeaders = sourceMessage.getAllHeaders(); HeaderUtils.copyHeaders(sourceHeaders, destinationHeaders, matcher); MimeBodyPart newBodyPart = new MimeBodyPart(destinationHeaders, rawMessage); return newBodyPart; }
From source file:com.adaptris.http.HttpHeaders.java
/** Read the header portion of a HTTP converstion. * @see DataTransfer#load(InputStream)/* ww w . java2 s . c o m*/ */ public void load(InputStream in) throws HttpException { headers = new InternetHeaders(); synchronized (in) { try { headers.load(in); } catch (Exception e) { throw new HttpException(e); } } return; }
From source file:com.adaptris.core.services.aggregator.MimeAggregator.java
protected MimeBodyPart createBodyPart(AdaptrisMessage msg) throws MessagingException, IOException { InternetHeaders hdrs = new InternetHeaders(); byte[] encodedData = encodeData(msg.getPayload(), getEncoding(), hdrs); hdrs.addHeader(HEADER_CONTENT_TYPE,//from w w w.j av a 2 s . c o m getMetadataValue(msg, getPartContentTypeMetadataKey(), "application/octet-stream")); return new MimeBodyPart(hdrs, encodedData); }
From source file:es.pode.catalogadorWeb.presentacion.importar.ImportarControllerImpl.java
public String submit(ActionMapping mapping, SubmitForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { String resultado = ""; String action = form.getAccion(); //String idiomaLocale=((Locale)request.getSession().getAttribute(ConstantesAgrega.DEFAULT_LOCALE)).getLanguage(); ResourceBundle i18n = I18n.getInstance().getResource("application-resources", (Locale) request.getSession().getAttribute(ConstantesAgrega.DEFAULT_LOCALE)); if (action != null) { if (action.equals(i18n.getString("catalogadorAvanzado.importar.aceptar"))) { resultado = "Aceptar"; if (form.getFichero() == null || form.getFichero().getFileName().equals("") || form.getFichero().getFileSize() == 0) throw new ValidatorException("{catalogadorAvanzado.importar.error.ficherovacio}"); //crear el datahandler InternetHeaders ih = new InternetHeaders(); MimeBodyPart mbp = null;/* ww w . j a va 2 s . c o m*/ DataSource source = null; DataHandler dh = null; try { FormFile ff = (FormFile) form.getFichero(); mbp = new MimeBodyPart(ih, ff.getFileData()); source = new MimePartDataSource(mbp); dh = new DataHandler(source); } catch (Exception e) { if (logger.isDebugEnabled()) { logger.debug("error al crear el datahandler"); } throw new ValidatorException("{catalogadorAvanzado.importar.error}"); } //validar el fichero Boolean valido = new Boolean(false); try { valido = this.getSrvValidadorService().obtenerValidacionLomes(dh); } catch (Exception e) { if (logger.isDebugEnabled()) { logger.debug("error al llamar al servicio de validacin"); } throw new ValidatorException("{catalogadorAvanzado.importar.error.novalido}"); } if (!valido.booleanValue()) throw new ValidatorException("{catalogadorAvanzado.importar.error.novalido}"); //agregar el datahandler a sesion this.getCatalogadorAvSession(request).setLomesImportado(dh); } else if (action.equals(i18n.getString("catalogadorAvanzado.importar.cancelar"))) resultado = "Cancelar"; } return resultado; }
From source file:com.threewks.thundr.mail.JavaMailMailer.java
private void addAttachments(Multipart multipart, List<Attachment> attachments) throws MessagingException { for (Attachment attachment : attachments) { BasicViewRenderer response = render(attachment.view()); byte[] base64Encoded = Base64.encodeToByte(response.getOutputAsBytes()); InternetHeaders headers = new InternetHeaders(); headers.addHeader(Header.ContentType, response.getContentType()); headers.addHeader(Header.ContentTransferEncoding, "base64"); MimeBodyPart part = new MimeBodyPart(headers, base64Encoded); part.setFileName(attachment.name()); part.setDisposition(attachment.disposition().value()); if (attachment.isInline()) { part.setContentID(attachment.contentId()); }//ww w .ja v a2 s . c o m multipart.addBodyPart(part); } }
From source file:com.adaptris.util.text.mime.MultiPartOutput.java
/** * Add a new part to the mime multipart. * /*from w ww . j ava2 s .c o m*/ * @param payload the data. * @param encoding the encoding to apply * @param contentId the id to set the content with. * @throws MessagingException if there was a failure adding the part. MimeMultiPart * @throws IOException if there was an IOException */ public void addPart(String payload, String encoding, String contentId) throws MessagingException, IOException { InternetHeaders header = new InternetHeaders(); byte[] encodedBytes = encodeData(payload, encoding, header); MimeBodyPart part = new MimeBodyPart(header, encodedBytes); this.addPart(part, contentId); }
From source file:mitm.common.mail.BodyPartUtils.java
/** * This is the only way I know of to create a new MimeBodyPart from another Message which is safe * for signed email. All other methods break the signature when quoted printable soft breaks are used. * /*www . j a v a 2s . c o m*/ * example of quoted printable soft breaks: * * Content-Transfer-Encoding: quoted-printable * soft break example = * another line = * * All other methods will re-encode and removes the soft breaks. * * @param sourceMessage * @param matcher * @return * @throws IOException * @throws MessagingException */ @SuppressWarnings("unchecked") public static MimeBodyPart makeContentBodyPartRawBytes(MimeMessage sourceMessage, HeaderMatcher matcher) throws IOException, MessagingException { /* * getRawInputStream() can throw a MessagingException when the source message is a MimeMessage * that is created in code (ie. not from a stream) */ InputStream messageStream = sourceMessage.getRawInputStream(); byte[] rawMessage = IOUtils.toByteArray(messageStream); InternetHeaders destinationHeaders = new InternetHeaders(); Enumeration<Header> sourceHeaders = sourceMessage.getAllHeaders(); HeaderUtils.copyHeaders(sourceHeaders, destinationHeaders, matcher); MimeBodyPart newBodyPart = new MimeBodyPart(destinationHeaders, rawMessage); return newBodyPart; }
From source file:com.adaptris.util.text.mime.MultiPartOutput.java
/** * Add a new part to the mime multipart. * //from w w w .j av a 2 s . c o m * @param payload the data. * @param encoding the encoding to apply * @param contentId the id to set the content with. * @throws MessagingException on error manipulating the bodypart * @throws IOException on general IO error. */ public void addPart(byte[] payload, String encoding, String contentId) throws MessagingException, IOException { InternetHeaders header = new InternetHeaders(); byte[] encodedBytes = encodeData(payload, encoding, header); MimeBodyPart part = new MimeBodyPart(header, encodedBytes); this.addPart(part, contentId); }
From source file:com.adaptris.mail.MailSenderImp.java
private void addAttachmentsToMessage(MimeMultipart multipart) throws MailException { try {/* w ww. j a v a2 s . com*/ for (Attachment a : attachments) { MimeBodyPart part = create(a.getBytes(), new InternetHeaders(), a.getEncoding()); part.setHeader(Mail.CONTENT_TYPE, a.getContentType()); ContentDisposition cd = new ContentDisposition(); cd.setDisposition(Mail.DISPOSITION_TYPE_ATTACHMENT); if (a.getFilename() != null) { cd.setParameter(Mail.DISPOSITION_PARAM_FILENAME, a.getFilename()); } part.setDisposition(cd.toString()); multipart.addBodyPart(part); } } catch (Exception e) { throw new MailException(e); } }