當前位置: 首頁>>代碼示例>>Java>>正文


Java Header類代碼示例

本文整理匯總了Java中javax.mail.Header的典型用法代碼示例。如果您正苦於以下問題:Java Header類的具體用法?Java Header怎麽用?Java Header使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Header類屬於javax.mail包,在下文中一共展示了Header類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: parseDescriptionFile

import javax.mail.Header; //導入依賴的package包/類
/**
 * Parses metadata stored in a Debian Control File-like format.
 *
 * @see <a href="https://cran.r-project.org/doc/manuals/r-release/R-exts.html#The-DESCRIPTION-file">Description File</a>
 */
public static Map<String, String> parseDescriptionFile(final InputStream in) {
  checkNotNull(in);
  try {
    LinkedHashMap<String, String> results = new LinkedHashMap<>();
    InternetHeaders headers = new InternetHeaders(in);
    Enumeration headerEnumeration = headers.getAllHeaders();
    while (headerEnumeration.hasMoreElements()) {
      Header header = (Header) headerEnumeration.nextElement();
      String name = header.getName();
      String value = header.getValue()
          .replace("\r\n", "\n")
          .replace("\r", "\n"); // TODO: "should" be ASCII only, otherwise need to know encoding?
      results.put(name, value); // TODO: Supposedly no duplicates, is this true?
    }
    return results;
  } catch (MessagingException e) {
    throw new RException(null, e);
  }
}
 
開發者ID:sonatype-nexus-community,項目名稱:nexus-repository-r,代碼行數:25,代碼來源:RMetadataUtils.java

示例2: getHeaders

import javax.mail.Header; //導入依賴的package包/類
protected MessageHeaders getHeaders(MimeMessage message) throws MessagingException {

        Map<String, String> headerMap = new HashMap<>();

        // oh wow 2015 and it's untyped and uses Enumeration
        Enumeration allHeaders = message.getAllHeaders();
        while (allHeaders.hasMoreElements()) {
            Header header = (Header) allHeaders.nextElement();
            String headerName = header.getName();
            String headerVal = header.getValue();

            headerMap.put(headerName, headerVal);

        }

        return new MessageHeaders(headerMap);
    }
 
開發者ID:SpartaSystems,項目名稱:holdmail,代碼行數:18,代碼來源:SMTPHandler.java

示例3: createLog

import javax.mail.Header; //導入依賴的package包/類
@SuppressWarnings("unchecked")
private static String createLog(final Message msg) {
    StringBuilder bldr = new StringBuilder();
    Enumeration<Header> allHeaders;
    try {
        allHeaders = msg.getAllHeaders();
    } catch (MessagingException e) {
        return null;
    }
    while (allHeaders.hasMoreElements()) {
        Header header = allHeaders.nextElement();
        String name = header.getName();
        String value = header.getValue();
        bldr.append(name);
        bldr.append(":");
        bldr.append(value);
        bldr.append("\n");
    }
    return StringUtils.truncate(bldr.toString(), LOG_FIELD_WIDTH);
}
 
開發者ID:qoswork,項目名稱:opennmszh,代碼行數:21,代碼來源:MailAckProcessor.java

示例4: getHeaders

import javax.mail.Header; //導入依賴的package包/類
String getHeaders(final Part part) throws MessagingException {
    StringBuilder builder = new StringBuilder();
    @SuppressWarnings("unchecked")
    final Enumeration<Header> headers = part.getAllHeaders();
    while (headers.hasMoreElements()) {
        Header next = headers.nextElement();
        builder.append(next.getName());
        builder.append(": ");
        builder.append(next.getValue());
        builder.append('\n');
        if (!headers.hasMoreElements()) {
            builder.append('\n');
        }
    }
    return builder.toString();
}
 
開發者ID:RIPE-NCC,項目名稱:whois,代碼行數:17,代碼來源:MessageParser.java

示例5: getAllHeaders

import javax.mail.Header; //導入依賴的package包/類
@SuppressWarnings( "unchecked")
@PublicAtsApi
public List<PackageHeader> getAllHeaders() throws PackageException {

    try {
        List<PackageHeader> headers = new ArrayList<PackageHeader>();

        Enumeration<Header> messageHeaders = message.getAllHeaders();
        while (messageHeaders.hasMoreElements()) {
            Header messageHeader = messageHeaders.nextElement();
            headers.add(new PackageHeader(messageHeader.getName(), messageHeader.getValue()));
        }

        return headers;

    } catch (MessagingException me) {
        throw new PackageException(me);
    }
}
 
開發者ID:Axway,項目名稱:ats-framework,代碼行數:20,代碼來源:MimePackage.java

示例6: addHeadersTrace

import javax.mail.Header; //導入依賴的package包/類
private String addHeadersTrace(
                                Enumeration<?> headers,
                                String level ) {

    final String level1 = level;
    final String level2 = "\t" + level1;
    final String prefix = getPrefixTrace(level1, "HEADERS START: ");

    StringBuilder headersString = new StringBuilder();

    boolean hasHeaders = headers.hasMoreElements();
    if (hasHeaders) {
        headersString.append(level1 + "HEADERS START:\n");
        while (headers.hasMoreElements()) {
            Header header = (Header) headers.nextElement();
            headersString.append(level2 + header.getName() + ": "
                                 + normalizeNewLinesTrace(prefix, header.getValue()) + "\n");
        }
        headersString.append(level1 + "HEADERS END:\n");
    }

    return headersString.toString();
}
 
開發者ID:Axway,項目名稱:ats-framework,代碼行數:24,代碼來源:MimePackage.java

示例7: moveMIMEHeadersToHTTPHeader

import javax.mail.Header; //導入依賴的package包/類
public static void moveMIMEHeadersToHTTPHeader (@Nonnull final MimeMessage aMimeMsg,
                                                @Nonnull final HttpMessage aHttpMsg) throws MessagingException
{
  ValueEnforcer.notNull (aMimeMsg, "MimeMsg");
  ValueEnforcer.notNull (aHttpMsg, "HttpMsg");

  // Move all mime headers to the HTTP request
  final Enumeration <Header> aEnum = aMimeMsg.getAllHeaders ();
  while (aEnum.hasMoreElements ())
  {
    final Header h = aEnum.nextElement ();
    // Make a single-line HTTP header value!
    aHttpMsg.addHeader (h.getName (), HttpHeaderMap.getUnifiedValue (h.getValue ()));

    // Remove from MIME message!
    aMimeMsg.removeHeader (h.getName ());
  }
}
 
開發者ID:phax,項目名稱:ph-as4,代碼行數:19,代碼來源:MessageHelperMethods.java

示例8: generateMessageHash

import javax.mail.Header; //導入依賴的package包/類
public String generateMessageHash(Message message) {
    LOG.trace("generateMessageHash for msg: {}", message);

    String uid = null;

    // create an UID based on message headers on the message, that ought to be unique
    StringBuilder buffer = new StringBuilder();
    try {
        Enumeration<?> it = message.getAllHeaders();
        while (it.hasMoreElements()) {
            Header header = (Header) it.nextElement();
            buffer.append(header.getName()).append("=").append(header.getValue()).append("\n");
        }
        if (buffer.length() > 0) {
            LOG.trace("Generating UID from the following:\n {}", buffer);
            uid = UUID.nameUUIDFromBytes(buffer.toString().getBytes()).toString();
        }
    } catch (MessagingException e) {
        LOG.warn("Cannot read headers from mail message. This exception will be ignored.", e);
    }

    return uid;
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:24,代碼來源:DefaultMailUidGenerator.java

示例9: extractHeadersFromMail

import javax.mail.Header; //導入依賴的package包/類
protected Map<String, Object> extractHeadersFromMail(Message mailMessage, Exchange exchange) throws MessagingException {
    Map<String, Object> answer = new HashMap<String, Object>();
    Enumeration<?> names = mailMessage.getAllHeaders();

    while (names.hasMoreElements()) {
        Header header = (Header) names.nextElement();
        String value = header.getValue();
        if (headerFilterStrategy != null && !headerFilterStrategy.applyFilterToExternalHeaders(header.getName(), value, exchange)) {
            CollectionHelper.appendValue(answer, header.getName(), value);
        }
    }

    return answer;
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:15,代碼來源:MailBinding.java

示例10: onSend

import javax.mail.Header; //導入依賴的package包/類
@Override
@SuppressWarnings("unchecked")
public void onSend(SubEthaMessage msg, SendFilterContext ctx) throws MessagingException
{
	try
	{
		boolean didSomething = false;
		
		for (Part part: msg.getParts())
		{
			if (part.getContentType().startsWith(SubEthaMessage.DETACHMENT_MIME_TYPE))
			{
				Long id = (Long)part.getContent();
				String contentType = part.getHeader(SubEthaMessage.HDR_ORIGINAL_CONTENT_TYPE)[0];
				
				// remove all headers
				for (Enumeration<Header> e = part.getAllHeaders(); e.hasMoreElements();)
				{
					Header header = e.nextElement();
					part.removeHeader(header.getName());
				}
				
				String name = MailUtils.getNameFromContentType(contentType);
				String attachmentUrl = ctx.getList().getUrlBase() + "attachment/" + id + "/" + name ;
				
				part.setText("This attachment was left behind at the server:\n     " + attachmentUrl + "\n");
				part.setDisposition(Part.INLINE);
				didSomething = true;
			}
		}
		
		if (didSomething) msg.save();
	}
	catch (IOException ioex)
	{
	    log.log(Level.FINE,"Error getting message parts", ioex);
	}
}
 
開發者ID:voodoodyne,項目名稱:subetha,代碼行數:39,代碼來源:LeaveAttachmentsOnServerFilter.java

示例11: createAddress

import javax.mail.Header; //導入依賴的package包/類
@Nonnull
private static InternetAddress createAddress(final Header header, final String typeOfAddress) {
	try {
		return new InternetAddress(header.getValue());
	} catch (final AddressException e) {
		throw new MimeMessageParseException(format(MimeMessageParseException.ERROR_PARSING_ADDRESS, typeOfAddress), e);
	}
}
 
開發者ID:bbottema,項目名稱:simple-java-mail,代碼行數:9,代碼來源:MimeMessageParser.java

示例12: validateCustomHeaders

import javax.mail.Header; //導入依賴的package包/類
public void validateCustomHeaders(final Email email, final MimeMessage sentMessage)
        throws MessagingException, IOException {
    Map<String, String> customHeaders = email.getCustomHeaders();
    List<Header> internetHeaders = (List<Header>) Collections.list(sentMessage.getAllHeaders());
    List<String> headerKeys = internetHeaders.stream().map(Header::getName).collect(toList());

    assertions.assertThat(headerKeys)
            .as("Should contains all the headers keys provided at construction time")
            .containsAll(customHeaders.keySet());

    customHeaders.entrySet().stream()
            .forEach(entry -> {
                try {
                    assertions.assertThat(sentMessage.getHeader(entry.getKey())).isNotNull().containsExactly(entry.getValue());
                } catch (MessagingException e) {
                }
            });
}
 
開發者ID:ozimov,項目名稱:spring-boot-email-tools,代碼行數:19,代碼來源:EmailToMimeMessageValidators.java

示例13: headers

import javax.mail.Header; //導入依賴的package包/類
@SuppressWarnings("unchecked")
public PartAssert<P> headers(Matcher<Iterable<? extends Header>> matcher) {
	try {
		String message = "headers of ${partName} of message ${messageIndex}";
		for (PartWithContext partWithContext : actual) {
			Part part = partWithContext.getPart();
			assertThat(part == null ? null : (Iterable<? extends Header>) list(part.getAllHeaders()), usingContext(message, partWithContext, matcher));
		}
		return this;
	} catch (MessagingException e) {
		throw new AssertionError("Failed to get filename of part", e);
	}
}
 
開發者ID:groupe-sii,項目名稱:ogham,代碼行數:14,代碼來源:PartAssert.java

示例14: setUp

import javax.mail.Header; //導入依賴的package包/類
@Before
public void setUp() throws Exception {
    javaMailJMSStatistics = new JavaMailJMSStatistics();
    javaMailJMSStatistics.registerInJMX();
    mimeMessage = Mockito.mock(MimeMessage.class);
    when(mimeMessage.getAllHeaders()).thenReturn(Collections.enumeration(Arrays.asList(new Header("h1", "v1"), new Header("h2", "v2"))));
    when(mimeMessage.getMessageID()).thenReturn("MessageId");
    when(mimeMessage.getSubject()).thenReturn("MessageSubject");
}
 
開發者ID:m-szalik,項目名稱:javamail,代碼行數:10,代碼來源:JavaMailJMSStatisticsTest.java

示例15: main

import javax.mail.Header; //導入依賴的package包/類
public static void main(String[] args) throws SUTimeParsingError, MessagingException {
HashMap<String,String>  hm=new HashMap<String,String>();
hm.put("kk","ghhj");
for(java.util.Map.Entry<String, String> e: hm.entrySet()){
	//System.out.println("Key " + e.getKey());
	//System.out.println("Value " + e.getValue());

}

   String s="NextPart_000_005D_01CC73D5.3BA43FB0\nContent-Type: text/plain;\n\tcharset=\"iso-8859-1\"\nContent-Transfer-Encoding: quoted-printable\n\nStuff:\n\n            Please read this stuff at the beginning of each week.  =\nFeel free to discuss it throughout the week.\n\n\n--=20\n\nMrs. Suzy M. Smith\n555-555-5555\[email protected]\n------=_NextPart_000_005D_01CC73D5.3BA43FB0\nContent-Type: text/html;\n\tcharset=\"iso-8859-1\"\nContent-Transfer-Encoding: quoted-printable\n\n<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n<HTML><HEAD>\n<META content=3D\"text/html; charset=3Diso-8859-1\" =\nhttp-equiv=3DContent-Type>\n<META name=3DGENERATOR content=3D\"MSHTML 9.00.8112.16434\">\n<STYLE></STYLE>\n</HEAD>\n<BODY bgColor=3D#ffffff>\n<DIV>\n<P style=3D\"MARGIN: 0in 0in 0pt\" class=3DMsoNormal><SPAN=20\nstyle=3D\"mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 'Times New =\nRoman'; mso-bidi-font-family: 'Times New =\nRoman'\">Stuff:<?xml:namespace=20\nprefix =3D o ns =3D \"urn:schemas-microsoft-com:office:office\"=20\n/><o:p></o:p></SPAN></P>\n<P style=3D\"MARGIN: 0in 0in 0pt\" class=3DMsoNormal><SPAN=20\nstyle=3D\"mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 'Times New =\nRoman'; mso-bidi-font-family: 'Times New Roman'\"><SPAN=20\nstyle=3D\"mso-tab-count: =\n1\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20\n</SPAN></SPAN>Please read this stuff at the beginning of each =\nweek.&nbsp; Feel=20\nfree to discuss it throughout the week.<SPAN=20\nstyle=3D\"mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 'Times New =\nRoman'; mso-bidi-font-family: 'Times New =\nRoman'\"><o:p></o:p></SPAN></P></DIV>\n<DIV><BR>-- <BR><BR>Mrs. Suzy M. Smith<BR>555-555-5555<BR><A=20\nhref=3D\"mailto:[email protected]\">[email protected]</A></DIV></BODY=\n></HTML>\n\n------=_NextPart_000_005D_01CC73D5.3BA43FB0--\n\n";
   InputStream stream = new ByteArrayInputStream(s.getBytes(StandardCharsets.UTF_8));
   Session ss = Session.getDefaultInstance(new Properties());
   MimeMessage mi=new MimeMessage(ss,stream);
   mi.getAllHeaderLines();
   for (Enumeration<Header> e = mi.getAllHeaders(); e.hasMoreElements();) {
       Header h = e.nextElement();
       String name=h.getName();
       String value=h.getValue();
       System.out.println(value);
       h.getValue();
   }
   //System.out.println("String: " + s);
     //parse(s);
     System.out.println();

 }
 
開發者ID:vibhor1319,項目名稱:activent,代碼行數:27,代碼來源:SUTimeSimpleParser.java


注:本文中的javax.mail.Header類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。