Example usage for javax.mail Header Header

List of usage examples for javax.mail Header Header

Introduction

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

Prototype

public Header(String name, String value) 

Source Link

Document

Construct a Header object.

Usage

From source file:ReadHeaders.java

public Header next() {
    int pos = inputLine.indexOf(":");
    if (pos < 0)
        return new Header("??", inputLine);
    return new Header(inputLine.substring(0, pos), inputLine.substring(pos + 1));
}

From source file:org.apache.axiom.attachments.impl.AbstractPart.java

public void addHeader(String name, String value) {
    if (log.isDebugEnabled()) {
        log.debug("addHeader: (" + name + ") value=(" + value + ")");
    }/*  ww  w.j av  a2s .c  o  m*/
    Header headerObj = new Header(name, value);

    // Use the lower case name as the key
    String key = name.toLowerCase();
    headers.put(key, headerObj);
}

From source file:org.apache.axiom.attachments.impl.PartFactory.java

/**
 * Parse the header into a name and value pair.
 * Add the name value pair to the map./* ww w.j ava  2  s.  c om*/
 * @param header StringBuffer
 * @param headers Map
 */
private static void readHeader(StringBuffer header, Map headers) {
    int delimiter = header.indexOf(":");
    String name = header.substring(0, delimiter).trim();
    String value = header.substring(delimiter + 1, header.length()).trim();

    if (log.isDebugEnabled()) {
        log.debug("addHeader: (" + name + ") value=(" + value + ")");
    }
    Header headerObj = new Header(name, value);

    // Use the lower case name as the key
    String key = name.toLowerCase();
    headers.put(key, headerObj);
}

From source file:org.pentaho.di.trans.steps.mailinput.ParseMailInputTest.java

@Before
public void beforeTest() throws MessagingException, IOException, KettleException {
    message = Mockito.mock(Message.class);

    MailConnection conn = mock(MailConnection.class);
    when(conn.getMessageBody(any(Message.class))).thenReturn(MSG_BODY);
    when(conn.getFolderName()).thenReturn(FLD_NAME);
    when(conn.getAttachedFilesCount(any(Message.class), any(Pattern.class))).thenReturn(ATTCH_COUNT);
    when(conn.getMessageBodyContentType(any(Message.class))).thenReturn(CNTNT_TYPE);
    data = mock(MailInputData.class);
    data.mailConn = conn;/*  www.  j  a  v a2s  .  c  o m*/

    mailInput = new MailInput(stepMockHelper.stepMeta, data, 0, stepMockHelper.transMeta, stepMockHelper.trans);

    Address addrFrom1 = mock(Address.class);
    when(addrFrom1.toString()).thenReturn(FROM1);
    Address addrFrom2 = mock(Address.class);
    when(addrFrom2.toString()).thenReturn(FROM2);
    Address addrRep1 = mock(Address.class);
    when(addrRep1.toString()).thenReturn(REP1);
    Address addrRep2 = mock(Address.class);
    when(addrRep2.toString()).thenReturn(REP2);
    Address allRec1 = mock(Address.class);
    when(allRec1.toString()).thenReturn(REC1);
    Address allRec2 = mock(Address.class);
    when(allRec2.toString()).thenReturn(REC2);

    Address[] adrFr = { addrFrom1, addrFrom2 };
    Address[] adrRep = { addrRep1, addrRep2 };
    Address[] adrRecip = { allRec1, allRec2 };

    message = Mockito.mock(Message.class);
    when(message.getMessageNumber()).thenReturn(MSG_NUMB);
    when(message.getSubject()).thenReturn(SUBJ);

    when(message.getFrom()).thenReturn(adrFr);
    when(message.getReplyTo()).thenReturn(adrRep);
    when(message.getAllRecipients()).thenReturn(adrRecip);
    when(message.getDescription()).thenReturn(DESC);
    when(message.getReceivedDate()).thenReturn(DATE1);
    when(message.getSentDate()).thenReturn(DATE2);
    when(message.getContentType()).thenReturn(CNTNT_TYPE_EMAIL);
    when(message.getSize()).thenReturn(CNTNT_SIZE);

    Header ex1 = new Header(HDR_EX1, HDR_EX1V);
    Header ex2 = new Header(HDR_EX2, HDR_EX2V);

    // for fixed [PDI-6532]
    when(message.getMatchingHeaders(aryEq(new String[] { HDR_EX1 }))).thenReturn(getEnum(new Header[] { ex1 }));
    when(message.getMatchingHeaders(aryEq(new String[] { HDR_EX2 }))).thenReturn(getEnum(new Header[] { ex2 }));
    when(message.getMatchingHeaders(aryEq(new String[] { HDR_EX1, HDR_EX2 })))
            .thenReturn(getEnum(new Header[] { ex1, ex2 }));

    // for previous implementation
    when(message.getHeader(eq(HDR_EX1))).thenReturn(new String[] { ex1.getValue() });
    when(message.getHeader(eq(HDR_EX2))).thenReturn(new String[] { ex2.getValue() });
}