当前位置: 首页>>代码示例>>Java>>正文


Java InternetHeaders.setHeader方法代码示例

本文整理汇总了Java中javax.mail.internet.InternetHeaders.setHeader方法的典型用法代码示例。如果您正苦于以下问题:Java InternetHeaders.setHeader方法的具体用法?Java InternetHeaders.setHeader怎么用?Java InternetHeaders.setHeader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.mail.internet.InternetHeaders的用法示例。


在下文中一共展示了InternetHeaders.setHeader方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setBodyPart

import javax.mail.internet.InternetHeaders; //导入方法依赖的package包/类
public static void setBodyPart(Multipart multipart, byte[] content, String contentType) throws MessagingException {
	String disposition = null;

	for (int i = 0; i < multipart.getCount(); i++) {
		BodyPart bp = multipart.getBodyPart(i);
		if (contentType.equalsIgnoreCase(bp.getContentType())) {
			disposition = bp.getDisposition();
			multipart.removeBodyPart(i);

			break;
		}
	}

	InternetHeaders ih1 = new InternetHeaders();
	ih1.setHeader("Content-Type", contentType);
	BodyPart bodyPart = new MimeBodyPart(ih1, content);
	if (disposition != null) {
		bodyPart.setDisposition(disposition);
	}

	multipart.addBodyPart(bodyPart);

}
 
开发者ID:mcdjw,项目名称:sip-servlets,代码行数:24,代码来源:CallStateHandler.java

示例2: generateBinaryPart

import javax.mail.internet.InternetHeaders; //导入方法依赖的package包/类
private MimeBodyPart generateBinaryPart() throws MessagingException
{
    byte[] content = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 10, 10, 15, 16 };   
    InternetHeaders ih = new InternetHeaders();
    
    ih.setHeader("Content-Transfer-Encoding", "binary");
    return new MimeBodyPart(ih, content);
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:9,代码来源:NewSMIMESignedTest.java

示例3: createTemplate

import javax.mail.internet.InternetHeaders; //导入方法依赖的package包/类
private MimeBodyPart createTemplate(String contentType, String contentTransferEncoding)
    throws UnsupportedEncodingException, MessagingException
{
    byte[] content = "<?xml version=\"1.0\"?>\n<INVOICE_CENTER>\n  <CONTENT_FRAME>\n</CONTENT_FRAME>\n</INVOICE_CENTER>\n".getBytes("US-ASCII");

    InternetHeaders ih = new InternetHeaders();
    ih.setHeader("Content-Type", contentType);
    ih.setHeader("Content-Transfer-Encoding", contentTransferEncoding);

    return new MimeBodyPart(ih, content);
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:12,代码来源:NewSMIMESignedTest.java

示例4: signMessage

import javax.mail.internet.InternetHeaders; //导入方法依赖的package包/类
private MimeBodyPart signMessage(MimeBodyPart bodyPart) throws Exception{
	X509Certificate cert = partnershipDVO.getVerifyX509Certificate();
	
	/* Create the SMIMESignedGenerator */
       SMIMECapabilityVector capabilities = new SMIMECapabilityVector();
       capabilities.addCapability(SMIMECapability.dES_EDE3_CBC);
       capabilities.addCapability(SMIMECapability.rC2_CBC, 128);
       capabilities.addCapability(SMIMECapability.dES_CBC);

       ASN1EncodableVector attributes = new ASN1EncodableVector();
       attributes.add(new SMIMEEncryptionKeyPreferenceAttribute(
           new IssuerAndSerialNumber(new X509Name(cert.getIssuerDN().getName()), cert.getSerialNumber()))
       );
       attributes.add(new SMIMECapabilitiesAttribute(capabilities));

       SMIMESignedGenerator signer = new SMIMESignedGenerator();
       signer.setContentTransferEncoding("base64");
signer.addSignerInfoGenerator(new JcaSimpleSignerInfoGeneratorBuilder().setProvider(SECURITY_PROVIDER)
			      .setSignedAttributeGenerator(new AttributeTable(attributes))
			      .build("SHA1withRSA",
				     keyMan.getPrivateKey(),
				     partnershipDVO.getVerifyX509Certificate()));

       // Add the list of certs to the generator
       ArrayList certList = new ArrayList();
       certList.add(cert);
       CertStore certs = CertStore.getInstance("Collection",
               new CollectionCertStoreParameters(certList), "BC");
signer.addCertificates(new JcaCertStore(certList));

       // Sign body part
MimeMultipart mm = signer.generate(bodyPart);

       InternetHeaders headers = new InternetHeaders();
       boolean isContentTypeFolded = new Boolean(System.getProperty("mail.mime.foldtext","true")).booleanValue();
       headers.setHeader("Content-Type", isContentTypeFolded? mm.getContentType():mm.getContentType().replaceAll("\\s", " "));
       ByteArrayOutputStream baos = new ByteArrayOutputStream();
       mm.writeTo(baos);  
       MimeBodyPart signedPart = new MimeBodyPart(headers, baos.toByteArray());
       
       return signedPart;
}
 
开发者ID:cecid,项目名称:hermes,代码行数:43,代码来源:IncomingMessageProcessorTest.java

示例5: getHeaders

import javax.mail.internet.InternetHeaders; //导入方法依赖的package包/类
protected InternetHeaders getHeaders(final String contentType, final String encoding) {
    final InternetHeaders headers = new InternetHeaders();
    headers.setHeader("Content-Type", contentType + "; charset=UTF-8");
    headers.setHeader("Content-Transfer-Encoding", encoding);
    return headers;
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:7,代码来源:SMTPManager.java

示例6: sign

import javax.mail.internet.InternetHeaders; //导入方法依赖的package包/类
public void sign(X509Certificate cert, PrivateKey privateKey, String digestAlg) throws SFRMException {
      try {
      	
          /* Create the SMIMESignedGenerator */
          SMIMECapabilityVector capabilities = new SMIMECapabilityVector();
          capabilities.addCapability(SMIMECapability.dES_EDE3_CBC);
          capabilities.addCapability(SMIMECapability.rC2_CBC, 128);
          capabilities.addCapability(SMIMECapability.dES_CBC);
                      
          SMIMESignedGenerator signer = new SMIMESignedGenerator();
          
          signer.setContentTransferEncoding("binary");

   String signerDigestAlg = "";
   
   if (digestAlg.equalsIgnoreCase(ALG_SIGN_MD5))
signerDigestAlg = "MD5withRSA";
   else if (digestAlg.equalsIgnoreCase(ALG_SIGN_SHA1))
signerDigestAlg = "SHA1withRSA";
   else
throw new SFRMException("Encryption algorihtm error - " + digestAlg);

   signer.addSignerInfoGenerator(new JcaSimpleSignerInfoGeneratorBuilder()
    .setProvider(SECURITY_PROVIDER)
    .build(signerDigestAlg, privateKey, cert));

          /* Add the list of certs to the generator */
          ArrayList<X509Certificate> certList = new ArrayList<X509Certificate>();
          certList.add(cert);
          CertStore certs = CertStore.getInstance("Collection",
                  new CollectionCertStoreParameters(certList), "BC");
          // signer.addCertificatesAndCRLs(certs);
   signer.addCertificates(new JcaCertStore(certList));

          /* Sign the body part */
          MimeMultipart mm = signer.generate(bodyPart);

          InternetHeaders headers = new InternetHeaders();
          headers.setHeader("Content-Type", mm.getContentType());
          
          ByteArrayOutputStream baos = new ByteArrayOutputStream();
          mm.writeTo(baos);
         
          this.bodyPart = new MimeBodyPart(headers, baos.toByteArray());
          
          this.setIsSigned(true);
          
      } catch (org.bouncycastle.mail.smime.SMIMEException ex) {
          throw new SFRMException("Unable to sign body part", ex.getUnderlyingException());
      } catch (Exception e) {
          throw new SFRMException("Unable to sign body part", e);
      }
  }
 
开发者ID:cecid,项目名称:hermes,代码行数:54,代码来源:SFRMMessage.java


注:本文中的javax.mail.internet.InternetHeaders.setHeader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。