當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。