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


Java Part.getSize方法代碼示例

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


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

示例1: SubethaEmailMessagePart

import javax.mail.Part; //導入方法依賴的package包/類
/**
 * Object can be built on existing message part only.
 * 
 * @param messagePart Message part.
 */
public SubethaEmailMessagePart(Part messagePart)
{
    ParameterCheck.mandatory("messagePart", messagePart);

    try
    {
        fileSize = messagePart.getSize();
        fileName = messagePart.getFileName();
        contentType = messagePart.getContentType();

        Matcher matcher = encodingExtractor.matcher(contentType);
        if (matcher.find())
        {
            encoding = matcher.group(1);
            if (!Charset.isSupported(encoding))
            {
                throw new EmailMessageException(ERR_UNSUPPORTED_ENCODING, encoding);
            }
        }

        try
        {
            contentInputStream = messagePart.getInputStream(); 
        }
        catch (Exception ex)
        {
            throw new EmailMessageException(ERR_FAILED_TO_READ_CONTENT_STREAM, ex.getMessage());
        }
    }
    catch (MessagingException e)
    {
        throw new EmailMessageException(ERR_INCORRECT_MESSAGE_PART, e.getMessage());
    }
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:40,代碼來源:SubethaEmailMessagePart.java

示例2: getMessageAttachment

import javax.mail.Part; //導入方法依賴的package包/類
private byte[] getMessageAttachment(Message message, String attachmentId,
        AttachmentProgressUpdate onProgressUpdate) throws IOException, MessagingException {
  Object msg = message.getContent();
  ByteArrayOutputStream buffer = null;
  if (msg instanceof Multipart) {
    Multipart mp = (Multipart) msg;
    for (int j = 0; j < mp.getCount(); j++) {
      Part bp = mp.getBodyPart(j);
      if (!Part.ATTACHMENT.equalsIgnoreCase(bp.getDisposition())) {
        continue;
      }
      if (MimeUtility.decodeText(bp.getFileName()).equals(attachmentId)) {
        
        InputStream is = bp.getInputStream();
        buffer = new ByteArrayOutputStream();
        int nRead;
        byte[] data = new byte[65536];
        int fullSize = bp.getSize();
        while ((nRead = is.read(data, 0, data.length)) != -1) {
          buffer.write(data, 0, nRead);
          if (onProgressUpdate != null) {
            onProgressUpdate.onProgressUpdate(buffer.size() * 100 / fullSize);
          }
        }
        buffer.flush();
        is.close();
        return buffer.toByteArray();
      }
    }
  }
  return null;
  
}
 
開發者ID:k-kojak,項目名稱:yako,代碼行數:34,代碼來源:SimpleEmailMessageProvider.java

示例3: onInject

import javax.mail.Part; //導入方法依賴的package包/類
@Override
@SuppressWarnings("unchecked")
public void onInject(SubEthaMessage msg, FilterContext ctx)
	throws IgnoreException, HoldException, MessagingException
{
	int maxKB = Integer.parseInt(ctx.getArgument(ARG_MAXSIZEINKB).toString());

	String msgContent = (String) ctx.getArgument(ARG_MSG);
	String expandedMsg = ctx.expand(msgContent);

	boolean changed = false;
	try 
	{
		for (Part p: msg.getParts())
		{
			if (p.getContentType().startsWith("text/") && !Part.ATTACHMENT.equals(p.getDisposition()))
				continue;
			
			if (p.getContentType().startsWith("multipart/"))
				continue;
			
			// Hopefully this means it is some sort of binary time
			if (p.getSize() > (maxKB * 1024)) 
			{
			    if (log.isLoggable(Level.FINE))
			        log.log(Level.FINE,"Stripping attachement of type: {0}", p.getContentType());		

				//remove all headers
				for (Enumeration<Header> e = p.getAllHeaders(); e.hasMoreElements();)
				{
					Header header = e.nextElement();
					p.removeHeader(header.getName());
				}

				p.setText(expandedMsg);
				changed = true;
			}
		}
		
		if (changed)
			msg.save();
	}
	catch (IOException ioex)
	{
		throw new RuntimeException(ioex);
	}
}
 
開發者ID:voodoodyne,項目名稱:subetha,代碼行數:48,代碼來源:StripAttachmentsFilter.java

示例4: processContentPart

import javax.mail.Part; //導入方法依賴的package包/類
protected void processContentPart(int indent, Part part) throws Exception {
  if (part.getContent() instanceof MimeMultipart) {
    log(indent, "--- multipart "+getMimeType(part)+" ----------------------------------");
    MimeMultipart mimeMultipart = (MimeMultipart) part.getContent();
    for (int i=0; i<mimeMultipart.getCount(); i++) {
      BodyPart bodyPart = mimeMultipart.getBodyPart(i);
      processContentPart(indent+1, bodyPart);
    }
    
  } else {
    log(indent, "--- part "+getMimeType(part)+" ----------------------------------");
    if (part.isMimeType("text/plain")) {
      String contentText = (String) part.getContent();
      log(indent, "adding plain text: "+contentText);
      messageText.append(contentText);
      
    } else if (part.isMimeType("text/html")){
      String rawHtml = (String) part.getContent();
      log(indent, "raw html: "+rawHtml);
      String cleanedUpHtml = htmlExtractBodyContent(rawHtml);
      log(indent, "adding cleaned up html: "+cleanedUpHtml);
      containsHtml = true;
      messageHtml.append(cleanedUpHtml);

    } else {
      String fileName = part.getFileName();
      log(indent, "unknown content part | "+part.getContentType()+" | "+part.getDisposition()+" | "+Arrays.toString(part.getHeader("Content-ID"))+" | "+fileName+" | "+part.getContent().getClass().getName());
      
      if (part.getSize()!=-1 && part.getSize()<ATTACHMENT_SIZE_LIMIT && (part.getContent() instanceof InputStream)) {
        String attachmentName = null;
        String attachmentType = null;
        String[] contentIdArray = part.getHeader("Content-ID");
        if (contentIdArray!=null && contentIdArray.length>0) {
          attachmentName = contentIdArray[0].trim();
          if (attachmentName.startsWith("<") && attachmentName.endsWith(">")) {
            attachmentName = attachmentName.substring(1, attachmentName.length()-2).trim();
          }
          attachmentType = getImageMimeType(attachmentName);
        } else if (Part.INLINE.equalsIgnoreCase(part.getDisposition())) {
          attachmentName = fileName;
          attachmentType = getImageMimeType(attachmentName);
          messageText.append("<img id=\"cid:"+fileName+"\" src=\"cid:"+fileName+"\" />");
          messageHtml.append("<img id=\"cid:"+fileName+"\" src=\"cid:"+fileName+"\" />");
        }
        if (attachmentName==null) {
          attachmentName = fileName;
          attachmentType = "email-attachment";
        }

        AttachmentEntity attachment = new AttachmentEntity();
        attachment.setName(attachmentName);
        attachment.setType(attachmentType);
        attachments.add(attachment);
        
        byte[] bytes = IoUtil.readInputStream((InputStream)part.getContent(), "mail attachment "+attachmentName);
        attachment.setContent(new ByteArrayEntity(bytes));
      }
    }
  }
  
}
 
開發者ID:logicalhacking,項目名稱:SecureBPMN,代碼行數:62,代碼來源:MailTransformer.java


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