List of usage examples for javax.mail.internet MimeMessage getInputStream
@Override public InputStream getInputStream() throws IOException, MessagingException
From source file:org.smigo.config.DevelopmentConfiguration.java
@Bean public JavaMailSenderImpl javaMailSender() { return new JavaMailSenderImpl() { @Override/*from w w w .j a v a 2s . co m*/ public String getDefaultEncoding() { return "UTF-8"; } @Override public void send(SimpleMailMessage simpleMessage) throws MailException { try { //Thread.sleep(2000); String text = simpleMessage.getText(); String subject = simpleMessage.getSubject(); FileUtils.writeStringToFile(MAIL_FILE, text, Charset.defaultCharset()); FileUtils.writeStringToFile(MAIL_FILE_TXT, subject + System.lineSeparator() + text, Charset.defaultCharset()); } catch (Exception e) { throw new MailSendException("Error sending email to " + simpleMessage.getFrom(), e); } } @Override public void send(MimeMessage mimeMessage) throws MailException { try { final String s = IOUtils.toString(mimeMessage.getInputStream()); FileUtils.writeStringToFile(MAIL_FILE, s, Charset.defaultCharset()); } catch (IOException | MessagingException e) { throw new MailSendException("Error sending email: " + mimeMessage.toString(), e); } } @Override public void send(SimpleMailMessage[] simpleMessages) throws MailException { throw new MailPreparationException("Method not supported"); } }; }
From source file:com.joshlong.lazyblogger.integrations.EmailToBlogTransformer.java
public Message<?> transformFromMimeMessageToBlogPost(Message<?> msg) { Message<?> response = null; // if this is null, the message will just get dropped. BlogPost blogPost = new BlogPost(); try {//from ww w .j av a 2 s. c o m MimeMessage mimeMessage = (MimeMessage) msg.getPayload(); blogPost.setSubject(mimeMessage.getSubject()); blogPost.setDate(mimeMessage.getSentDate()); blogPost.setBody(IOUtils.toString(mimeMessage.getInputStream())); if (mimeMessage.getSender() != null) blogPost.addSender(emailFromAddress(mimeMessage.getSender())); if (mimeMessage.getFrom() != null) for (Address address : mimeMessage.getFrom()) blogPost.addSender(emailFromAddress(address)); response = MessageBuilder.withPayload(blogPost).copyHeadersIfAbsent(msg.getHeaders()).build(); } catch (Throwable e) { utilities.log(ExceptionUtils.getFullStackTrace(e)); } return response; }
From source file:com.zimbra.qa.unittest.TestUserServlet.java
private void verifyZipFile(ZMailbox mbox, String relativePath, boolean hasBody) throws Exception { InputStream in = mbox.getRESTResource(relativePath); ZipInputStream zipIn = new ZipInputStream(in); ZipEntry entry;/*from w w w . j ava 2s .c o m*/ boolean foundMessage = false; while ((entry = zipIn.getNextEntry()) != null) { if (entry.getName().endsWith(".eml")) { ByteArrayOutputStream buf = new ByteArrayOutputStream(); ByteUtil.copy(zipIn, false, buf, true); byte[] content = buf.toByteArray(); MimeMessage message = new ZMimeMessage(JMSession.getSession(), new SharedByteArrayInputStream(content)); byte[] body = ByteUtil.getContent(message.getInputStream(), 0); if (hasBody) { assertTrue(entry.getName() + " has no body", body.length > 0); } else { assertEquals(entry.getName() + " has a body", 0, body.length); } foundMessage = true; } } zipIn.close(); assertTrue(foundMessage); }
From source file:com.zimbra.qa.unittest.TestUserServlet.java
private void verifyTarball(ZMailbox mbox, String relativePath, boolean hasMeta, boolean hasBody) throws Exception { InputStream in = mbox.getRESTResource(relativePath); TarInputStream tarIn = new TarInputStream(new GZIPInputStream(in), "UTF-8"); TarEntry entry = null;//from w w w.j a v a 2s . c om boolean foundMeta = false; boolean foundMessage = false; while ((entry = tarIn.getNextEntry()) != null) { if (entry.getName().endsWith(".meta")) { assertTrue("Fround " + entry.getName(), hasMeta); foundMeta = true; } if (entry.getName().endsWith(".eml")) { byte[] content = new byte[(int) entry.getSize()]; assertEquals(content.length, tarIn.read(content)); MimeMessage message = new ZMimeMessage(JMSession.getSession(), new SharedByteArrayInputStream(content)); byte[] body = ByteUtil.getContent(message.getInputStream(), 0); if (hasBody) { assertTrue(entry.getName() + " has no body", body.length > 0); } else { assertEquals(entry.getName() + " has a body", 0, body.length); } foundMessage = true; } } tarIn.close(); assertTrue(foundMessage); if (hasMeta) { assertTrue(foundMeta); } }
From source file:com.zimbra.cs.mime.MimeTest.java
@Test public void fixBase64LineWrapping() throws Exception { String textPlain = "Line 1 This is base64 encoded text message part. It does not have line folding. \r\n" + "Line 2 This is base64 encoded text message part. It does not have line folding. \r\n" + "Line 3 This is base64 encoded text message part. It does not have line folding. \r\n"; String textHtml = "<html>\r\n" + "<body>\r\n" + "Line 1 This is base64 encoded html message part. It does not have line folding. </ br>" + "Line 2 This is base64 encoded html message part. It does not have line folding. </ br>\r\n" + "Line 3 This is base64 encoded html message part. It does not have line folding. \r\n" + "</ br>\r\n" + "</body>\r\n" + "</html>"; InputStream is = getClass().getResourceAsStream("base64mime.txt"); MimeMessage mm = new Mime.FixedMimeMessage(JMSession.getSession(), is); mm.saveChanges();// w ww .j av a 2 s .c o m String dataBeforeFix = IOUtils.toString(mm.getInputStream()); Mime.fixBase64MimePartLineFolding(mm); mm.saveChanges(); String dataAfterFix = IOUtils.toString(mm.getInputStream()); MPartInfo mpiText = Mime.getTextBody(Mime.getParts(mm), false); MPartInfo mpiHtml = Mime.getTextBody(Mime.getParts(mm), true); Assert.assertFalse("Line folding should take place.", dataAfterFix.equals(dataBeforeFix)); Assert.assertTrue("Text Part Content-Transfer-Encoding header should be preserved", mpiText.getMimePart().getHeader("Content-Transfer-Encoding", ":").equals("base64")); Assert.assertTrue("HTML Part Content-Transfer-Encoding header should be preserved", mpiHtml.getMimePart().getHeader("Content-Transfer-Encoding", ":").equals("base64")); Assert.assertTrue("Text Part Content-Disposition header should be preserved", mpiText.mDisposition.equals("inline")); Assert.assertTrue("HTML Part Content-Disposition header should be preserved", mpiHtml.mDisposition.equals("inline")); Assert.assertTrue("Text data should not be modified", TestUtil.bytesEqual(textPlain.getBytes(), mpiText.getMimePart().getInputStream())); Assert.assertTrue("Html data should not be modified", TestUtil.bytesEqual(textHtml.getBytes(), mpiHtml.getMimePart().getInputStream())); }
From source file:com.zimbra.cs.mime.MimeTest.java
@Test public void fixBase64LineWrappingAttachments() throws Exception { InputStream is = getClass().getResourceAsStream("bug95114.txt"); InputStream expectedIs = getClass().getResourceAsStream("bug95114_expected.txt"); String expected = IOUtils.toString(expectedIs); MimeMessage mm = new Mime.FixedMimeMessage(JMSession.getSession(), is); mm.saveChanges();/* ww w . j a v a 2s . c o m*/ Mime.fixBase64MimePartLineFolding(mm); mm.saveChanges(); String actual = IOUtils.toString(mm.getInputStream()); Assert.assertEquals("Content altered.", expected, actual); }
From source file:mitm.application.djigzo.james.mailets.BlackberrySMIMEAdapter.java
private void replaceSMIMEAttachment(MimeMessage containerMessage, MimeMessage sourceMessage) throws MessagingException, IOException, PartException { Part smimePart = findAttachment(containerMessage); if (sourceMessage.getSize() > directSizeLimit) { /*// www. j av a2 s.c o m * The message is too large to be sent to the BB directly so we should * sent it as an attachment that can be downloaded and handled using * a content handler on the BB */ String filename = downloadAttachmentName + DOWNLOAD_ATTACHMENT_EXTENSION; smimePart.setFileName(filename); } smimePart.setDataHandler(new DataHandler( new ByteArrayDataSource(sourceMessage.getInputStream(), "application/octet-stream"))); }
From source file:de.mendelson.comm.as2.message.AS2MessageParser.java
/**Writes a passed payload data to the passed message object. Could be called from either the MDN * processing or the message processing/*from w ww .j a v a 2s . c o m*/ */ public void writePayloadsToMessage(byte[] data, AS2Message message, Properties header) throws Exception { ByteArrayOutputStream payloadOut = new ByteArrayOutputStream(); MimeMessage testMessage = new MimeMessage(Session.getInstance(System.getProperties()), new ByteArrayInputStream(data)); //multiple attachments? if (testMessage.isMimeType("multipart/*")) { this.writePayloadsToMessage(testMessage, message, header); return; } InputStream payloadIn = null; AS2Info info = message.getAS2Info(); if (info instanceof AS2MessageInfo && info.getSignType() == AS2Message.SIGNATURE_NONE && ((AS2MessageInfo) info).getCompressionType() == AS2Message.COMPRESSION_NONE) { payloadIn = new ByteArrayInputStream(data); } else if (testMessage.getSize() > 0) { payloadIn = testMessage.getInputStream(); } else { payloadIn = new ByteArrayInputStream(data); } this.copyStreams(payloadIn, payloadOut); payloadOut.flush(); payloadOut.close(); byte[] payloadData = payloadOut.toByteArray(); AS2Payload as2Payload = new AS2Payload(); as2Payload.setData(payloadData); String contentIdHeader = header.getProperty("content-id"); if (contentIdHeader != null) { as2Payload.setContentId(contentIdHeader); } String contentTypeHeader = header.getProperty("content-type"); if (contentTypeHeader != null) { as2Payload.setContentType(contentTypeHeader); } try { as2Payload.setOriginalFilename(testMessage.getFileName()); } catch (MessagingException e) { if (this.logger != null) { this.logger.log(Level.WARNING, this.rb.getResourceString("filename.extraction.error", new Object[] { info.getMessageId(), e.getMessage(), }), info); } } if (as2Payload.getOriginalFilename() == null) { String filenameHeader = header.getProperty("content-disposition"); if (filenameHeader != null) { //test part for convinience: extract file name MimeBodyPart filenamePart = new MimeBodyPart(); filenamePart.setHeader("content-disposition", filenameHeader); try { as2Payload.setOriginalFilename(filenamePart.getFileName()); } catch (MessagingException e) { if (this.logger != null) { this.logger.log(Level.WARNING, this.rb.getResourceString("filename.extraction.error", new Object[] { info.getMessageId(), e.getMessage(), }), info); } } } } message.addPayload(as2Payload); }
From source file:com.sonicle.webtop.mail.Service.java
private String getTextContentAsString(Part p) throws IOException, MessagingException { java.io.InputStream istream = null; String charset = MailUtils.getCharsetOrDefault(p.getContentType()); if (!java.nio.charset.Charset.isSupported(charset)) { charset = "ISO-8859-1"; }/*from w ww.j av a2s . com*/ try { if (p instanceof javax.mail.internet.MimeMessage) { javax.mail.internet.MimeMessage mm = (javax.mail.internet.MimeMessage) p; istream = mm.getInputStream(); } else if (p instanceof javax.mail.internet.MimeBodyPart) { javax.mail.internet.MimeBodyPart mm = (javax.mail.internet.MimeBodyPart) p; istream = mm.getInputStream(); } } catch (Exception exc) { //unhandled format, get Raw data if (p instanceof javax.mail.internet.MimeMessage) { javax.mail.internet.MimeMessage mm = (javax.mail.internet.MimeMessage) p; istream = mm.getRawInputStream(); } else if (p instanceof javax.mail.internet.MimeBodyPart) { javax.mail.internet.MimeBodyPart mm = (javax.mail.internet.MimeBodyPart) p; istream = mm.getRawInputStream(); } } if (istream == null) { throw new IOException("Unknown message class " + p.getClass().getName()); } java.io.BufferedReader br = new java.io.BufferedReader(new java.io.InputStreamReader(istream, charset)); String line = null; StringBuffer sb = new StringBuffer(); while ((line = br.readLine()) != null) { sb.append(line); sb.append("\n"); } br.close(); return sb.toString(); }
From source file:fr.gouv.culture.vitam.eml.EmlExtract.java
public static String extractInfoMessage(MimeMessage message, Element root, VitamArgument argument, ConfigLoader config) {/*from www. j a va 2s.c o m*/ File oldDir = argument.currentOutputDir; if (argument.currentOutputDir == null) { if (config.outputDir != null) { argument.currentOutputDir = new File(config.outputDir); } } Element keywords = XmlDom.factory.createElement(EMAIL_FIELDS.keywords.name); Element metadata = XmlDom.factory.createElement(EMAIL_FIELDS.metadata.name); String skey = ""; String id = config.addRankId(root); Address[] from = null; Element sub2 = null; try { from = message.getFrom(); } catch (MessagingException e1) { String[] partialResult; try { partialResult = message.getHeader("From"); if (partialResult != null && partialResult.length > 0) { sub2 = XmlDom.factory.createElement(EMAIL_FIELDS.from.name); Element add = XmlDom.factory.createElement(EMAIL_FIELDS.fromUnit.name); add.setText(partialResult[0]); sub2.add(add); } } catch (MessagingException e) { } } Address sender = null; try { sender = message.getSender(); } catch (MessagingException e1) { String[] partialResult; try { partialResult = message.getHeader("Sender"); if (partialResult != null && partialResult.length > 0) { if (sub2 == null) { sub2 = XmlDom.factory.createElement(EMAIL_FIELDS.from.name); Element add = XmlDom.factory.createElement(EMAIL_FIELDS.fromUnit.name); add.setText(partialResult[0]); sub2.add(add); } } } catch (MessagingException e) { } } if (from != null && from.length > 0) { String value0 = null; Element sub = (sub2 != null ? sub2 : XmlDom.factory.createElement(EMAIL_FIELDS.from.name)); if (sender != null) { value0 = addAddress(sub, EMAIL_FIELDS.fromUnit.name, sender, null); } for (Address address : from) { addAddress(sub, EMAIL_FIELDS.fromUnit.name, address, value0); } metadata.add(sub); } else if (sender != null) { Element sub = (sub2 != null ? sub2 : XmlDom.factory.createElement(EMAIL_FIELDS.from.name)); addAddress(sub, EMAIL_FIELDS.fromUnit.name, sender, null); metadata.add(sub); } else { if (sub2 != null) { metadata.add(sub2); } } Address[] replyTo = null; try { replyTo = message.getReplyTo(); if (replyTo != null && replyTo.length > 0) { Element sub = XmlDom.factory.createElement(EMAIL_FIELDS.replyTo.name); for (Address address : replyTo) { addAddress(sub, EMAIL_FIELDS.fromUnit.name, address, null); } metadata.add(sub); } } catch (MessagingException e1) { String[] partialResult; try { partialResult = message.getHeader("ReplyTo"); if (partialResult != null && partialResult.length > 0) { sub2 = XmlDom.factory.createElement(EMAIL_FIELDS.replyTo.name); addAddress(sub2, EMAIL_FIELDS.fromUnit.name, partialResult, null); /*Element add = XmlDom.factory.createElement(EMAIL_FIELDS.fromUnit.name); add.setText(partialResult[0]); sub2.add(add);*/ metadata.add(sub2); } } catch (MessagingException e) { } } Address[] toRecipients = null; try { toRecipients = message.getRecipients(Message.RecipientType.TO); if (toRecipients != null && toRecipients.length > 0) { Element sub = XmlDom.factory.createElement(EMAIL_FIELDS.toRecipients.name); for (Address address : toRecipients) { addAddress(sub, EMAIL_FIELDS.toUnit.name, address, null); } metadata.add(sub); } } catch (MessagingException e1) { String[] partialResult; try { partialResult = message.getHeader("To"); if (partialResult != null && partialResult.length > 0) { sub2 = XmlDom.factory.createElement(EMAIL_FIELDS.toRecipients.name); addAddress(sub2, EMAIL_FIELDS.toUnit.name, partialResult, null); /*for (String string : partialResult) { Element add = XmlDom.factory.createElement(EMAIL_FIELDS.toUnit.name); add.setText(string); sub2.add(add); }*/ metadata.add(sub2); } } catch (MessagingException e) { } } Address[] ccRecipients; try { ccRecipients = message.getRecipients(Message.RecipientType.CC); if (ccRecipients != null && ccRecipients.length > 0) { Element sub = XmlDom.factory.createElement(EMAIL_FIELDS.ccRecipients.name); for (Address address : ccRecipients) { addAddress(sub, EMAIL_FIELDS.ccUnit.name, address, null); } metadata.add(sub); } } catch (MessagingException e1) { String[] partialResult; try { partialResult = message.getHeader("Cc"); if (partialResult != null && partialResult.length > 0) { sub2 = XmlDom.factory.createElement(EMAIL_FIELDS.ccRecipients.name); addAddress(sub2, EMAIL_FIELDS.ccUnit.name, partialResult, null); /*for (String string : partialResult) { Element add = XmlDom.factory.createElement(EMAIL_FIELDS.ccUnit.name); add.setText(string); sub2.add(add); }*/ metadata.add(sub2); } } catch (MessagingException e) { } } Address[] bccRecipients; try { bccRecipients = message.getRecipients(Message.RecipientType.BCC); if (bccRecipients != null && bccRecipients.length > 0) { Element sub = XmlDom.factory.createElement(EMAIL_FIELDS.bccRecipients.name); for (Address address : bccRecipients) { addAddress(sub, EMAIL_FIELDS.bccUnit.name, address, null); } metadata.add(sub); } } catch (MessagingException e1) { String[] partialResult; try { partialResult = message.getHeader("Cc"); if (partialResult != null && partialResult.length > 0) { sub2 = XmlDom.factory.createElement(EMAIL_FIELDS.bccRecipients.name); addAddress(sub2, EMAIL_FIELDS.bccUnit.name, partialResult, null); /*for (String string : partialResult) { Element add = XmlDom.factory.createElement(EMAIL_FIELDS.bccUnit.name); add.setText(string); sub2.add(add); }*/ metadata.add(sub2); } } catch (MessagingException e) { } } try { String subject = message.getSubject(); if (subject != null) { Element sub = XmlDom.factory.createElement(EMAIL_FIELDS.subject.name); sub.setText(StringUtils.unescapeHTML(subject, true, false)); metadata.add(sub); } Date sentDate = message.getSentDate(); if (sentDate != null) { Element sub = XmlDom.factory.createElement(EMAIL_FIELDS.sentDate.name); sub.setText(sentDate.toString()); metadata.add(sub); } Date receivedDate = message.getReceivedDate(); if (receivedDate != null) { Element sub = XmlDom.factory.createElement(EMAIL_FIELDS.receivedDate.name); sub.setText(receivedDate.toString()); metadata.add(sub); } String[] headers = message.getHeader("Received"); if (headers != null) { Element sub = XmlDom.factory.createElement(EMAIL_FIELDS.receptionTrace.name); MailDateFormat mailDateFormat = null; long maxTime = 0; if (receivedDate == null) { mailDateFormat = new MailDateFormat(); } for (String string : headers) { Element sub3 = XmlDom.factory.createElement(EMAIL_FIELDS.trace.name); sub3.setText(StringUtils.unescapeHTML(string, true, false)); sub.add(sub3); if (receivedDate == null) { int pos = string.lastIndexOf(';'); if (pos > 0) { String recvdate = string.substring(pos + 2).replaceAll("\t\n\r\f", "").trim(); try { Date date = mailDateFormat.parse(recvdate); if (date.getTime() > maxTime) { maxTime = date.getTime(); } } catch (ParseException e) { } } } } if (receivedDate == null) { Element subdate = XmlDom.factory.createElement(EMAIL_FIELDS.receivedDate.name); Date date = new Date(maxTime); subdate.setText(date.toString()); metadata.add(subdate); } metadata.add(sub); } int internalSize = message.getSize(); if (internalSize > 0) { Element sub = XmlDom.factory.createElement(EMAIL_FIELDS.emailSize.name); sub.setText(Integer.toString(internalSize)); metadata.add(sub); } String encoding = message.getEncoding(); if (encoding != null) { Element sub = XmlDom.factory.createElement(EMAIL_FIELDS.encoding.name); sub.setText(StringUtils.unescapeHTML(encoding, true, false)); metadata.add(sub); } String description = message.getDescription(); if (description != null) { Element sub = XmlDom.factory.createElement(EMAIL_FIELDS.description.name); sub.setText(StringUtils.unescapeHTML(description, true, false)); metadata.add(sub); } String contentType = message.getContentType(); if (contentType != null) { Element sub = XmlDom.factory.createElement(EMAIL_FIELDS.contentType.name); sub.setText(StringUtils.unescapeHTML(contentType, true, false)); metadata.add(sub); } headers = message.getHeader("Content-Transfer-Encoding"); if (headers != null) { Element sub = XmlDom.factory.createElement(EMAIL_FIELDS.contentTransferEncoding.name); StringBuilder builder = new StringBuilder(); for (String string : headers) { builder.append(StringUtils.unescapeHTML(string, true, false)); builder.append(' '); } sub.setText(builder.toString()); metadata.add(sub); } String[] contentLanguage = message.getContentLanguage(); if (contentLanguage != null) { Element sub = XmlDom.factory.createElement(EMAIL_FIELDS.contentLanguage.name); StringBuilder builder = new StringBuilder(); for (String string : contentLanguage) { builder.append(StringUtils.unescapeHTML(string, true, false)); builder.append(' '); } sub.setText(builder.toString()); metadata.add(sub); } String contentId = message.getContentID(); if (contentId != null) { Element sub = XmlDom.factory.createElement(EMAIL_FIELDS.contentId.name); sub.setText(StringUtils.removeChevron(StringUtils.unescapeHTML(contentId, true, false))); metadata.add(sub); } String disposition = message.getDisposition(); if (disposition != null) { Element sub = XmlDom.factory.createElement(EMAIL_FIELDS.disposition.name); sub.setText(StringUtils.removeChevron(StringUtils.unescapeHTML(disposition, true, false))); metadata.add(sub); } headers = message.getHeader("Keywords"); if (headers != null) { Element sub = XmlDom.factory.createElement(EMAIL_FIELDS.msgKeywords.name); StringBuilder builder = new StringBuilder(); for (String string : headers) { builder.append(StringUtils.unescapeHTML(string, true, false)); builder.append(' '); } sub.setText(builder.toString()); metadata.add(sub); } String messageId = message.getMessageID(); if (messageId != null) { messageId = StringUtils.removeChevron(StringUtils.unescapeHTML(messageId, true, false)).trim(); if (messageId.length() > 1) { Element sub = XmlDom.factory.createElement(EMAIL_FIELDS.messageId.name); sub.setText(messageId); metadata.add(sub); } } headers = message.getHeader("In-Reply-To"); String inreplyto = null; if (headers != null) { StringBuilder builder = new StringBuilder(); for (String string : headers) { builder.append(StringUtils.removeChevron(StringUtils.unescapeHTML(string, true, false))); builder.append(' '); } inreplyto = builder.toString().trim(); if (inreplyto.length() > 0) { Element sub = XmlDom.factory.createElement(EMAIL_FIELDS.inReplyTo.name); sub.setText(inreplyto); if (messageId != null && messageId.length() > 1) { String old = filEmls.get(inreplyto); if (old == null) { old = messageId; } else { old += "," + messageId; } filEmls.put(inreplyto, old); } metadata.add(sub); } } headers = message.getHeader("References"); if (headers != null) { Element sub = XmlDom.factory.createElement(EMAIL_FIELDS.references.name); StringBuilder builder = new StringBuilder(); for (String string : headers) { builder.append(StringUtils.removeChevron(StringUtils.unescapeHTML(string, true, false))); builder.append(' '); } String[] refs = builder.toString().trim().split(" "); for (String string : refs) { if (string.length() > 0) { Element ref = XmlDom.factory.createElement(EMAIL_FIELDS.reference.name); ref.setText(string); sub.add(ref); } } metadata.add(sub); } Element prop = XmlDom.factory.createElement(EMAIL_FIELDS.properties.name); headers = message.getHeader("X-Priority"); if (headers == null) { headers = message.getHeader("Priority"); if (headers != null && headers.length > 0) { prop.addAttribute(EMAIL_FIELDS.priority.name, headers[0]); } } else if (headers != null && headers.length > 0) { String imp = headers[0]; try { int Priority = Integer.parseInt(imp); switch (Priority) { case 5: imp = "LOWEST"; break; case 4: imp = "LOW"; break; case 3: imp = "NORMAL"; break; case 2: imp = "HIGH"; break; case 1: imp = "HIGHEST"; break; default: imp = "LEV" + Priority; } } catch (NumberFormatException e) { // ignore since imp will be used as returned } prop.addAttribute(EMAIL_FIELDS.priority.name, imp); } headers = message.getHeader("Sensitivity"); if (headers != null && headers.length > 0) { prop.addAttribute(EMAIL_FIELDS.sensitivity.name, headers[0]); } headers = message.getHeader("X-RDF"); if (headers != null && headers.length > 0) { System.err.println("Found X-RDF"); StringBuilder builder = new StringBuilder(); for (String string : headers) { builder.append(string); builder.append("\n"); } try { byte[] decoded = org.apache.commons.codec.binary.Base64.decodeBase64(builder.toString()); String rdf = new String(decoded); Document tempDocument = DocumentHelper.parseText(rdf); Element xrdf = prop.addElement("x-rdf"); xrdf.add(tempDocument.getRootElement()); } catch (Exception e) { System.err.println("Cannot decode X-RDF: " + e.getMessage()); } } try { File old = argument.currentOutputDir; if (config.extractFile) { File newOutDir = new File(argument.currentOutputDir, id); newOutDir.mkdirs(); argument.currentOutputDir = newOutDir; } if (argument.extractKeyword) { skey = handleMessage(message, metadata, prop, id, argument, config); // should have hasAttachment if (prop.hasContent()) { metadata.add(prop); } if (metadata.hasContent()) { root.add(metadata); } ExtractInfo.exportMetadata(keywords, skey, "", config, null); if (keywords.hasContent()) { root.add(keywords); } } else { handleMessage(message, metadata, prop, id, argument, config); // should have hasAttachment if (prop.hasContent()) { metadata.add(prop); } if (metadata.hasContent()) { root.add(metadata); } } argument.currentOutputDir = old; } catch (IOException e) { System.err.println(StaticValues.LBL.error_error.get() + e.toString()); } try { message.getInputStream().close(); } catch (IOException e) { System.err.println(StaticValues.LBL.error_error.get() + e.toString()); } root.addAttribute(EMAIL_FIELDS.status.name, "ok"); } catch (MessagingException e) { System.err.println(StaticValues.LBL.error_error.get() + e.toString()); e.printStackTrace(); String status = "Error during identification"; root.addAttribute(EMAIL_FIELDS.status.name, status); } catch (Exception e) { System.err.println(StaticValues.LBL.error_error.get() + e.toString()); e.printStackTrace(); String status = "Error during identification"; root.addAttribute(EMAIL_FIELDS.status.name, status); } argument.currentOutputDir = oldDir; return skey; }