Example usage for javax.mail Header getName

List of usage examples for javax.mail Header getName

Introduction

In this page you can find the example usage for javax.mail Header getName.

Prototype

public String getName() 

Source Link

Document

Returns the name of this header.

Usage

From source file:com.cubusmail.gwtui.server.services.ShowMessageSourceServlet.java

/**
 * @param msg//from   w  w w  .j a  v a 2s .  c o m
 * @return
 */
@SuppressWarnings("unchecked")
private String generateHeader(Message msg) {

    StringBuffer headerString = new StringBuffer();

    try {
        Enumeration<Header> e = msg.getAllHeaders();
        if (e != null) {
            for (; e.hasMoreElements();) {
                Header header = e.nextElement();
                headerString.append(header.getName());
                headerString.append(": ");
                headerString.append(header.getValue());
                headerString.append('\n');
            }
        }
    } catch (MessagingException e) {
        logger.error(e.getMessage(), e);
    }

    return headerString.toString();
}

From source file:com.cubusmail.server.services.ShowMessageSourceServlet.java

/**
 * @param msg//from w ww  .  j a va2  s.  co m
 * @return
 */
@SuppressWarnings("unchecked")
private String generateHeader(Message msg) {

    StringBuffer headerString = new StringBuffer();

    try {
        Enumeration<Header> e = msg.getAllHeaders();
        if (e != null) {
            for (; e.hasMoreElements();) {
                Header header = e.nextElement();
                headerString.append(header.getName());
                headerString.append(": ");
                headerString.append(header.getValue());
                headerString.append('\n');
            }
        }
    } catch (MessagingException e) {
        log.error(e.getMessage(), e);
    }

    return headerString.toString();
}

From source file:me.normanmaurer.camel.smtp.SMTPTest.java

@SuppressWarnings("unchecked")
@Test//from   w ww  .j a  v a2s . co m
public void testSendMatchingMessage() throws Exception {
    String sender = "sender@localhost";
    String rcpt = "rcpt@localhost";
    String body = "Subject: test\r\n\r\nTestmail";
    SMTPClient client = new SMTPClient();
    client.connect("localhost", 2525);
    client.helo("localhost");
    client.setSender(sender);
    client.addRecipient(rcpt);

    client.sendShortMessageData(body);
    client.quit();
    client.disconnect();
    resultEndpoint.expectedMessageCount(1);
    resultEndpoint.expectedBodyReceived().body(InputStream.class);
    Exchange ex = resultEndpoint.getReceivedExchanges().get(0);
    Map<String, Object> headers = ex.getIn().getHeaders();
    assertEquals(sender, headers.get(MailEnvelopeMessage.SMTP_SENDER_ADRRESS));
    assertEquals(rcpt, headers.get(MailEnvelopeMessage.SMTP_RCPT_ADRRESS_LIST));

    // check type converter
    MimeMessage message = ex.getIn().getBody(MimeMessage.class);
    Enumeration<Header> mHeaders = message.getAllHeaders();
    Header header = null;
    while (mHeaders.hasMoreElements()) {
        header = mHeaders.nextElement();
        if (header.getName().equals("Subject")) {
            break;
        }
    }
    assertNotNull(header);
    assertEquals("Subject", header.getName());
    assertEquals(header.getValue(), "test");

    resultEndpoint.assertIsSatisfied();
}

From source file:com.adaptris.core.services.splitter.MimePartSplitter.java

private void copyHeaders(MimeBodyPart src, AdaptrisMessage dest) throws MessagingException {
    if (preserveHeaders()) {
        Enumeration e = src.getAllHeaders();
        while (e.hasMoreElements()) {
            Header h = (Header) e.nextElement();
            dest.addMetadata(defaultIfEmpty(getHeaderPrefix(), "") + h.getName(), h.getValue());
        }//from  w w w .ja  va 2s. co  m
    }
}

From source file:com.adaptris.http.HttpHeaders.java

/** Add all the header elements to this set of headers.
 *  <p>Any existing headers will be replaced.
 * //from   w w w .  j a v  a2 s. c o m
 * @param other the HttpHeaders object containing the headers to be added.
 */
public void putAll(HttpHeaders other) {
    Enumeration e = other.getAllHeaders();
    while (e.hasMoreElements()) {
        Header h = (Header) e.nextElement();
        this.put(h.getName(), h.getValue());
    }
}

From source file:com.adaptris.core.services.mime.FlattenMimeParts.java

private void addHeaders(InternetHeaders hdrs, MultiPartOutput out) {
    Enumeration e = hdrs.getAllHeaders();
    while (e.hasMoreElements()) {
        Header h = (Header) e.nextElement();
        if (!DISCARD.contains(h.getName().toLowerCase())) {
            out.setHeader(h.getName(), h.getValue());
        }//w  ww  .j  av a  2s  .  c  om
    }
}

From source file:com.canoo.webtest.plugins.emailtest.EmailMessageStructureFilter.java

private boolean headerIsRequired(final Header header) {
    for (int i = 0; i < fTokenizedHeaders.length; i++) {
        if (fTokenizedHeaders[i].equalsIgnoreCase(header.getName())) {
            return true;
        }/*from   w ww  .  ja v  a  2 s  .  c  o m*/
    }
    return false;
}

From source file:com.garethahealy.elasticpostman.scraper.entities.EmailContent.java

public void parse() throws Exception {
    Session session = Session.getDefaultInstance(new Properties());
    MimeMessage message = MimeMessageUtils.createMimeMessage(session, raw);
    MimeMessageParser mimeMessageParser = new MimeMessageParser(message);
    MimeMessageParser parsed = mimeMessageParser.parse();

    this.from = parsed.getFrom();
    this.subject = parsed.getSubject();
    this.content = parsed.getPlainContent();
    this.contentIds = parsed.getContentIds();
    this.sentDate = new DateTime(parsed.getMimeMessage().getSentDate());
    this.headers = new HashMap<String, String>();

    @SuppressWarnings("unchecked")
    EnumerationIterator it = new EnumerationIterator(parsed.getMimeMessage().getAllHeaders());
    while (it.hasNext()) {
        Object current = it.next();
        if (current instanceof Header) {
            Header header = (Header) current;
            if (includeHeader(header.getName())) {
                headers.put(header.getName(), sanatizeValue(header.getName(), header.getValue()));
            }/*from w w  w . j  a  v a 2 s  .  com*/
        }
    }

}

From source file:mitm.common.mail.matcher.HeaderNameMatcher.java

@Override
public boolean isMatch(Header header) {
    boolean match = false;

    for (String headerName : headerNames) {
        headerName = StringUtils.trimToNull(headerName);

        if (headerName != null) {
            if (headerName.equalsIgnoreCase(header.getName())) {
                match = true;/*www.j ava2s.c  o m*/
                break;
            }
        }
    }

    return match;
}

From source file:net.orpiske.dcd.collector.dataset.impl.MBoxDataSet.java

@Override
public Data next() {
    MBoxData mBoxData = null;//  www.  j a va  2s.  c  o m
    Message message;

    try {
        message = inbox.getMessage(currentMessage);

        if (logger.isDebugEnabled()) {
            logger.debug("Processing message " + currentMessage + " of " + messageCount + "");

            if (logger.isTraceEnabled()) {
                logger.trace("------- MESSAGE START -------");
                logger.trace(message.getContent().toString());
                logger.trace("-------  MESSAGE END  -------");
            }
        }

        mBoxData = new MBoxData(message.getContent().toString());
        mBoxData.setBody(message.getContent().toString());

        StringBuilder stringBuilder = new StringBuilder();
        Enumeration<Header> enumeration = message.getAllHeaders();
        while (enumeration.hasMoreElements()) {
            Header header = enumeration.nextElement();

            if (header.getName().equalsIgnoreCase("from")) {
                mBoxData.setOriginator(header.getValue());
            } else {
                stringBuilder.append(header.getValue());
            }

            if (header.getName().equalsIgnoreCase("date")) {
                String strDate = header.getValue();
                Date date = getDate(strDate);

                mBoxData.setDate(date);
            }

            stringBuilder.append('\n');
        }

        mBoxData.setHeader(stringBuilder.toString());
    } catch (MessagingException e) {
        logger.error("Unable to process message " + currentMessage + ": " + e.getMessage(), e);
    } catch (IOException e) {
        logger.error("I/O error while processing the message " + currentMessage + ": " + e.getMessage(), e);
    }

    currentMessage++;
    return mBoxData;
}