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


Java MimeBodyPart.getContentType方法代码示例

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


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

示例1: doTestTextAttachment

import javax.mail.internet.MimeBodyPart; //导入方法依赖的package包/类
private void doTestTextAttachment(boolean useFs) throws IOException, MessagingException {
    emailerConfig.setFileStorageUsed(useFs);
    testMailSender.clearBuffer();

    String attachmentText = "Test Attachment Text";
    EmailAttachment textAttach = EmailAttachment.createTextAttachment(attachmentText, "ISO-8859-1", "test.txt");

    EmailInfo myInfo = new EmailInfo("[email protected]", "Test", null, "Test", textAttach);
    emailer.sendEmailAsync(myInfo);

    emailer.processQueuedEmails();

    MimeMessage msg = testMailSender.fetchSentEmail();
    MimeBodyPart firstAttachment = getFirstAttachment(msg);

    // check content bytes
    Object content = firstAttachment.getContent();
    assertTrue(content instanceof InputStream);
    byte[] data = IOUtils.toByteArray((InputStream) content);
    assertEquals(attachmentText, new String(data, "ISO-8859-1"));

    // disposition
    assertEquals(Part.ATTACHMENT, firstAttachment.getDisposition());

    // charset header
    String contentType = firstAttachment.getContentType();
    assertTrue(contentType.toLowerCase().contains("charset=iso-8859-1"));
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:29,代码来源:EmailerTest.java

示例2: doTestInlineImage

import javax.mail.internet.MimeBodyPart; //导入方法依赖的package包/类
private void doTestInlineImage(boolean useFs) throws IOException, MessagingException {
    emailerConfig.setFileStorageUsed(useFs);
    testMailSender.clearBuffer();

    byte[] imageBytes = new byte[]{1, 2, 3, 4, 5};
    String fileName = "logo.png";
    EmailAttachment imageAttach = new EmailAttachment(imageBytes, fileName, "logo");

    EmailInfo myInfo = new EmailInfo("[email protected]", "Test", null, "Test", imageAttach);
    emailer.sendEmailAsync(myInfo);

    emailer.processQueuedEmails();

    MimeMessage msg = testMailSender.fetchSentEmail();
    MimeBodyPart attachment = getInlineAttachment(msg);

    // check content bytes
    InputStream content = (InputStream) attachment.getContent();
    byte[] data = IOUtils.toByteArray(content);
    assertByteArrayEquals(imageBytes, data);

    // disposition
    assertEquals(Part.INLINE, attachment.getDisposition());

    // mime type
    String contentType = attachment.getContentType();
    assertTrue(contentType.contains("image/png"));
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:29,代码来源:EmailerTest.java

示例3: doTestPdfAttachment

import javax.mail.internet.MimeBodyPart; //导入方法依赖的package包/类
private void doTestPdfAttachment(boolean useFs) throws IOException, MessagingException {
    emailerConfig.setFileStorageUsed(useFs);
    testMailSender.clearBuffer();

    byte[] pdfBytes = new byte[]{1, 2, 3, 4, 6};
    String fileName = "invoice.pdf";
    EmailAttachment pdfAttach = new EmailAttachment(pdfBytes, fileName);

    EmailInfo myInfo = new EmailInfo("[email protected]", "Test", null, "Test", pdfAttach);
    emailer.sendEmailAsync(myInfo);

    emailer.processQueuedEmails();

    MimeMessage msg = testMailSender.fetchSentEmail();
    MimeBodyPart attachment = getFirstAttachment(msg);

    // check content bytes
    InputStream content = (InputStream) attachment.getContent();
    byte[] data = IOUtils.toByteArray(content);
    assertByteArrayEquals(pdfBytes, data);

    // disposition
    assertEquals(Part.ATTACHMENT, attachment.getDisposition());

    // mime type
    String contentType = attachment.getContentType();
    assertTrue(contentType.contains("application/pdf"));
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:29,代码来源:EmailerTest.java

示例4: createIncomingFileAttachment

import javax.mail.internet.MimeBodyPart; //导入方法依赖的package包/类
@Nonnull
public static WSS4JAttachment createIncomingFileAttachment (@Nonnull final MimeBodyPart aBodyPart,
                                                            @Nonnull final AS4ResourceManager aResMgr) throws MessagingException,
                                                                                                       IOException
{
  ValueEnforcer.notNull (aBodyPart, "BodyPart");
  ValueEnforcer.notNull (aResMgr, "ResMgr");

  final WSS4JAttachment ret = new WSS4JAttachment (aResMgr, aBodyPart.getContentType ());

  {
    // Reference in header is: <ID>
    // See
    // http://docs.oasis-open.org/wss-m/wss/v1.1.1/os/wss-SwAProfile-v1.1.1-os.html
    // chapter 5.2
    final String sRealContentID = StringHelper.trimStartAndEnd (aBodyPart.getContentID (), '<', '>');
    ret.setId (sRealContentID);
  }

  if (canBeKeptInMemory (aBodyPart.getSize ()))
  {
    // keep some small parts in memory
    final DataHandler aDH = aBodyPart.getDataHandler ();
    ret.setSourceStreamProvider (HasInputStream.once ( () -> {
      try
      {
        return aDH.getInputStream ();
      }
      catch (final IOException ex)
      {
        throw new UncheckedIOException (ex);
      }
    }));
  }
  else
  {
    // Write to temp file
    final File aTempFile = aResMgr.createTempFile ();
    try (final OutputStream aOS = FileHelper.getBufferedOutputStream (aTempFile))
    {
      aBodyPart.getDataHandler ().writeTo (aOS);
    }
    ret.setSourceStreamProvider (HasInputStream.multiple ( () -> FileHelper.getBufferedInputStream (aTempFile)));
  }

  // Convert all headers to attributes
  final Enumeration <?> aEnum = aBodyPart.getAllHeaders ();
  while (aEnum.hasMoreElements ())
  {
    final Header aHeader = (Header) aEnum.nextElement ();
    ret.addHeader (aHeader.getName (), aHeader.getValue ());
  }

  // These headers are mandatory and overwrite headers from the MIME body part
  ret.addHeader (AttachmentUtils.MIME_HEADER_CONTENT_DESCRIPTION, "Attachment");
  ret.addHeader (AttachmentUtils.MIME_HEADER_CONTENT_ID, "<attachment=" + ret.getId () + ">");
  ret.addHeader (AttachmentUtils.MIME_HEADER_CONTENT_TYPE, ret.getMimeType ());

  return ret;
}
 
开发者ID:phax,项目名称:ph-as4,代码行数:61,代码来源:WSS4JAttachment.java

示例5: resendAsNew

import javax.mail.internet.MimeBodyPart; //导入方法依赖的package包/类
public AS2Message resendAsNew(String primalMessageId) throws Exception {		
	AS2DAOHandler daoHandler = new AS2DAOHandler(getDAOFactory());
	
	// Checking precondition
	if (primalMessageId == null || 0 == primalMessageId.length()) {
		throw new Exception("Null / Empty primal message ID");
	}		

	MessageDVO primalMsgDVO = daoHandler.findMessageDVO(primalMessageId, MessageDVO.MSGBOX_OUT);
	String primalStatus = primalMsgDVO.getStatus();
	if (MessageDVO.STATUS_PENDING.equals(primalStatus) || MessageDVO.STATUS_PROCESSING.equals(primalStatus)) {
		throw new Exception("Message can only be resent as new when its status is not Pending or Processing");
	}
	
	if (primalMsgDVO.isReceipt()) {
		throw new Exception("Receipt cannot be resent as new");
	}
	
	String partnershipId = primalMsgDVO.getPartnershipId();
	if (null == partnershipId) {
		throw new Exception("Null partnership ID");
	}
	
	PartnershipDVO partnershipDVO = daoHandler.findPartnership(primalMsgDVO.getPartnershipId());
	
	primalMsgDVO.setHasResendAsNew("true");
	
	// Reconstruct old as2 message
	RawRepositoryDVO primalRawRepoDVO = daoHandler.findRawRepositoryDVO(primalMessageId);
	ByteArrayInputStream messageContent = new ByteArrayInputStream(primalRawRepoDVO.getContent());
	AS2Message oldAs2Message = new AS2Message(messageContent);
	messageContent.close();
	
	// Construct new as2 message
	String[] values = oldAs2Message.getBodyPart().getHeader("Content-Disposition");
	String fileName = AS2Util.getFileNameFromMIMEHeader(values);
	
	MimeBodyPart bodyPart = oldAs2Message.getBodyPart();
	String contentType = bodyPart.getContentType();
	ByteArrayOutputStream baos = new ByteArrayOutputStream();
       IOHandler.pipe(bodyPart.getInputStream(), baos);
       DataSource dataSource = new ByteArrayDataSource(baos.toByteArray(), contentType);
       DataHandler dataHandler = new DataHandler(dataSource);
       
       String type = getType(contentType);
	
	InputStreamDataSource insDS = new InputStreamDataSource(dataHandler.getInputStream(), type, fileName);
	AS2Message newAs2Message = storeOutgoingMessage(AS2Message.generateID(), type, partnershipDVO, insDS, primalMsgDVO);

	return newAs2Message;
}
 
开发者ID:cecid,项目名称:hermes,代码行数:52,代码来源:OutgoingMessageProcessor.java

示例6: getBodyContentType

import javax.mail.internet.MimeBodyPart; //导入方法依赖的package包/类
private String getBodyContentType(MimeMessage msg) throws Exception {
    MimeBodyPart textPart = getTextPart(msg);
    return textPart.getContentType();
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:5,代码来源:EmailerTest.java


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