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


Java BodyPart.getContentType方法代码示例

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


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

示例1: isContainAttach

import javax.mail.BodyPart; //导入方法依赖的package包/类
/**  
 * 判断此邮件是否包含附件  
 */  
public boolean isContainAttach(Part part) throws Exception {   
    boolean attachflag = false;   
    String contentType = part.getContentType();   
    if (part.isMimeType("multipart/*")) {   
        Multipart mp = (Multipart) part.getContent();   
        for (int i = 0; i < mp.getCount(); i++) {   
            BodyPart mpart = mp.getBodyPart(i);   
            String disposition = mpart.getDisposition();   
            if ((disposition != null)   
                    && ((disposition.equals(Part.ATTACHMENT)) || (disposition   
                            .equals(Part.INLINE))))   
                attachflag = true;   
            else if (mpart.isMimeType("multipart/*")) {   
                attachflag = isContainAttach((Part) mpart);   
            } else {   
                String contype = mpart.getContentType();   
                if (contype.toLowerCase().indexOf("application") != -1)   
                    attachflag = true;   
                if (contype.toLowerCase().indexOf("name") != -1)   
                    attachflag = true;   
            }   
        }   
    } else if (part.isMimeType("message/rfc822")) {   
        attachflag = isContainAttach((Part) part.getContent());   
    }   
    return attachflag;   
}
 
开发者ID:tiglabs,项目名称:jsf-core,代码行数:31,代码来源:ReciveMail.java

示例2: isContainAttachment

import javax.mail.BodyPart; //导入方法依赖的package包/类
/**
 * �ж��ʼ����Ƿ��������
 * @param msg �ʼ�����
 * @return �ʼ��д��ڸ�������true�������ڷ���false
 */ 
public static boolean isContainAttachment(Part part) throws MessagingException, IOException { 
    boolean flag = false; 
    if (part.isMimeType("multipart/*")) { 
        MimeMultipart multipart = (MimeMultipart) part.getContent(); 
        int partCount = multipart.getCount(); 
        for (int i = 0; i < partCount; i++) { 
            BodyPart bodyPart = multipart.getBodyPart(i); 
            String disp = bodyPart.getDisposition(); 
            if (disp != null && (disp.equalsIgnoreCase(Part.ATTACHMENT) || disp.equalsIgnoreCase(Part.INLINE))) { 
                flag = true; 
            } else if (bodyPart.isMimeType("multipart/*")) { 
                flag = isContainAttachment(bodyPart); 
            } else { 
                String contentType = bodyPart.getContentType(); 
                if (contentType.indexOf("application") != -1) { 
                    flag = true; 
                }   
                 
                if (contentType.indexOf("name") != -1) { 
                    flag = true; 
                }  
            } 
             
            if (flag) break; 
        } 
    } else if (part.isMimeType("message/rfc822")) { 
        flag = isContainAttachment((Part)part.getContent()); 
    } 
    return flag; 
}
 
开发者ID:bjut-2014,项目名称:scada,代码行数:36,代码来源:MailUtils.java

示例3: isContainAttachment

import javax.mail.BodyPart; //导入方法依赖的package包/类
/**
 * 判断邮件中是否包含附件
 * @param msg 邮件内容
 * @return 邮件中存在附件返回true,不存在返回false
 * @throws MessagingException
 * @throws IOException
 */
public static boolean isContainAttachment(Part part) throws MessagingException, IOException {
	boolean flag = false;
	if (part.isMimeType("multipart/*")) {
		MimeMultipart multipart = (MimeMultipart) part.getContent();
		int partCount = multipart.getCount();
		for (int i = 0; i < partCount; i++) {
			BodyPart bodyPart = multipart.getBodyPart(i);
			String disp = bodyPart.getDisposition();
			if (disp != null && (disp.equalsIgnoreCase(Part.ATTACHMENT) || disp.equalsIgnoreCase(Part.INLINE))) {
				flag = true;
			} else if (bodyPart.isMimeType("multipart/*")) {
				flag = isContainAttachment(bodyPart);
			} else {
				String contentType = bodyPart.getContentType();
				if (contentType.indexOf("application") != -1) {
					flag = true;
				}  
				
				if (contentType.indexOf("name") != -1) {
					flag = true;
				} 
			}
			
			if (flag) break;
		}
	} else if (part.isMimeType("message/rfc822")) {
		flag = isContainAttachment((Part)part.getContent());
	}
	return flag;
}
 
开发者ID:xiaomin0322,项目名称:alimama,代码行数:38,代码来源:POP3ReceiveMailTest.java

示例4: saveAttachment

import javax.mail.BodyPart; //导入方法依赖的package包/类
/** 
 * ���渽�� 
 * @param part �ʼ��ж��������е�����һ������� 
 * @param destDir  ��������Ŀ¼ 
 */ 
public static void saveAttachment(Part part, String destDir) throws UnsupportedEncodingException, MessagingException, 
        FileNotFoundException, IOException { 
    if (part.isMimeType("multipart/*")) { 
        Multipart multipart = (Multipart) part.getContent();    //�������ʼ� 
        //�������ʼ���������ʼ��� 
        int partCount = multipart.getCount(); 
        for (int i = 0; i < partCount; i++) { 
            //��ø������ʼ�������һ���ʼ��� 
            BodyPart bodyPart = multipart.getBodyPart(i); 
            //ijһ���ʼ���Ҳ�п������ɶ���ʼ�����ɵĸ����� 
            String disp = bodyPart.getDisposition(); 
            if (disp != null && (disp.equalsIgnoreCase(Part.ATTACHMENT) || disp.equalsIgnoreCase(Part.INLINE))) { 
                InputStream is = bodyPart.getInputStream(); 
                saveFile(is, destDir, decodeText(bodyPart.getFileName())); 
            } else if (bodyPart.isMimeType("multipart/*")) { 
                saveAttachment(bodyPart,destDir); 
            } else { 
                String contentType = bodyPart.getContentType(); 
                if (contentType.indexOf("name") != -1 || contentType.indexOf("application") != -1) { 
                    saveFile(bodyPart.getInputStream(), destDir, decodeText(bodyPart.getFileName())); 
                } 
            } 
        } 
    } else if (part.isMimeType("message/rfc822")) { 
        saveAttachment((Part) part.getContent(),destDir); 
    } 
}
 
开发者ID:bjut-2014,项目名称:scada,代码行数:33,代码来源:MailUtils.java

示例5: saveAttachment

import javax.mail.BodyPart; //导入方法依赖的package包/类
/**
 * 保存附件
 * @param part 邮件中多个组合体中的其中一个组合体
 * @param destDir  附件保存目录
 * @throws UnsupportedEncodingException
 * @throws MessagingException
 * @throws FileNotFoundException
 * @throws IOException
 */
public static void saveAttachment(Part part, String destDir) throws UnsupportedEncodingException, MessagingException,
		FileNotFoundException, IOException {
	if (part.isMimeType("multipart/*")) {
		Multipart multipart = (Multipart) part.getContent();	//复杂体邮件
		//复杂体邮件包含多个邮件体
		int partCount = multipart.getCount();
		for (int i = 0; i < partCount; i++) {
			//获得复杂体邮件中其中一个邮件体
			BodyPart bodyPart = multipart.getBodyPart(i);
			//某一个邮件体也有可能是由多个邮件体组成的复杂体
			String disp = bodyPart.getDisposition();
			if (disp != null && (disp.equalsIgnoreCase(Part.ATTACHMENT) || disp.equalsIgnoreCase(Part.INLINE))) {
				InputStream is = bodyPart.getInputStream();
				saveFile(is, destDir, decodeText(bodyPart.getFileName()));
			} else if (bodyPart.isMimeType("multipart/*")) {
				saveAttachment(bodyPart,destDir);
			} else {
				String contentType = bodyPart.getContentType();
				if (contentType.indexOf("name") != -1 || contentType.indexOf("application") != -1) {
					saveFile(bodyPart.getInputStream(), destDir, decodeText(bodyPart.getFileName()));
				}
			}
		}
	} else if (part.isMimeType("message/rfc822")) {
		saveAttachment((Part) part.getContent(),destDir);
	}
}
 
开发者ID:xiaomin0322,项目名称:alimama,代码行数:37,代码来源:POP3ReceiveMailTest.java

示例6: appendMultiPart

import javax.mail.BodyPart; //导入方法依赖的package包/类
private void appendMultiPart(SampleResult child, StringBuilder cdata,
        MimeMultipart mmp) throws MessagingException, IOException {
    String preamble = mmp.getPreamble();
    if (preamble != null ){
        cdata.append(preamble);
    }
    child.setResponseData(cdata.toString(),child.getDataEncodingNoDefault());
    int count = mmp.getCount();
    for (int j=0; j<count;j++){
        BodyPart bodyPart = mmp.getBodyPart(j);
        final Object bodyPartContent = bodyPart.getContent();
        final String contentType = bodyPart.getContentType();
        SampleResult sr = new SampleResult();
        sr.setSampleLabel("Part: "+j);
        sr.setContentType(contentType);
        sr.setDataEncoding(RFC_822_DEFAULT_ENCODING);
        sr.setEncodingAndType(contentType);
        sr.sampleStart();
        if (bodyPartContent instanceof InputStream){
            sr.setResponseData(IOUtils.toByteArray((InputStream) bodyPartContent));
        } else if (bodyPartContent instanceof MimeMultipart){
            appendMultiPart(sr, cdata, (MimeMultipart) bodyPartContent);
        } else {
            sr.setResponseData(bodyPartContent.toString(),sr.getDataEncodingNoDefault());
        }
        sr.setResponseOK();
        if (sr.getEndTime()==0){// not been set by any child samples
            sr.sampleEnd();
        }
        child.addSubResult(sr);
    }
}
 
开发者ID:johrstrom,项目名称:cloud-meter,代码行数:33,代码来源:MailReaderSampler.java

示例7: getTextContent

import javax.mail.BodyPart; //导入方法依赖的package包/类
/**
 * Extract the text content for a {@link BodyPart}, assuming the default
 * encoding.
 */
public static String getTextContent(BodyPart part) throws MessagingException, IOException {
  ContentType contentType = new ContentType(part.getContentType());
  String charset = contentType.getParameter("charset");
  if (charset == null) {
    // N.B.(schwardo): The MIME spec doesn't seem to provide a
    // default charset, but the default charset for HTTP is
    // ISO-8859-1.  That seems like a reasonable default.
    charset = "ISO-8859-1";
  }

  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  ByteStreams.copy(part.getInputStream(), baos);
  try {
    return new String(baos.toByteArray(), charset);
  } catch (UnsupportedEncodingException ex) {
    return new String(baos.toByteArray());
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-java-vm-runtime,代码行数:23,代码来源:MultipartMimeUtils.java

示例8: getPartContentType

import javax.mail.BodyPart; //导入方法依赖的package包/类
public String getPartContentType(String index) {
    BodyPart part = getPart(index);
    if (part != null) {
        try {
            return part.getContentType();
        } catch (MessagingException e) {
            Debug.logError(e, module);
            return null;
        }
    } else {
        return null;
    }
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:14,代码来源:MimeMessageWrapper.java

示例9: parse2Html

import javax.mail.BodyPart; //导入方法依赖的package包/类
protected Document parse2Html(File file) throws Exception {
  InputStream in = new FileInputStream(file);

  Session mailSession = Session.getDefaultInstance(System.getProperties(), null);

  MimeMessage msg = new MimeMessage(mailSession, in);

  Multipart part = (Multipart) msg.getContent();
  String html = "";
  for(int i = 0; i < part.getCount(); i++) {
    BodyPart body = part.getBodyPart(i);
    String type = body.getContentType();
    if(type.startsWith("text/html")) {
      html = body.getContent().toString();
      break;
    }
  }
  in.close();
  
  if(html == null || html.length() == 0) {
    String content = FileUtils.readFileToString(file);
    final String endFlag = "</html>";
    int start = content.indexOf("<html");
    int end = content.indexOf(endFlag);
    content = content.substring(start, end + endFlag.length());
    html = QuotedPrintableUtils.decode(content.getBytes(), "gb2312");
    System.err.println(html);
  }
  return Jsoup.parse(html);
}
 
开发者ID:xsocket,项目名称:job,代码行数:31,代码来源:ZhilianEmailResumeParser.java

示例10: extractIndex

import javax.mail.BodyPart; //导入方法依赖的package包/类
static DisambiguatedDocument extractIndex(MimeMultipart mmp, int index) throws MessagingException, IOException {
  // Retrieve the body part. If encoded with "gzip", decode it.
  // We want to copy into into the byte buffer stored in the response
  BodyPart doc = mmp.getBodyPart(index);     
  String encoding = null;
  String[] encodings = doc.getHeader("Content-Encoding");
  if (encodings != null && encodings.length == 1 && encodings[0].contentEquals("gzip"))
    encoding = encodings[0];
  return new DisambiguatedDocument(doc.getContentType(), encoding, doc.getInputStream());
}
 
开发者ID:Idilia,项目名称:idilia-java-sdk,代码行数:11,代码来源:DisambiguateCodec.java

示例11: getFileContentType

import javax.mail.BodyPart; //导入方法依赖的package包/类
/**
 * Get the content type of a file parameter from the request.
 * @param name the name of the input field
 * @return the content type
 */
public String getFileContentType(String name) {
  BodyPart part = getBodyPart(name);
  if (part != null) {
    try {
      return part.getContentType();
    } catch (MessagingException e) {
      // ignore and simply return null
    }
  }
  return null;
}
 
开发者ID:thinkberg,项目名称:snipsnap,代码行数:17,代码来源:MultipartWrapper.java

示例12: createMessage

import javax.mail.BodyPart; //导入方法依赖的package包/类
/**
 * Creates a MIME message from a SOAP message.
 * 
 * @param from the 'from' mail address.
 * @param to the 'to' mail address(es).
 * @param cc the 'cc' mail address(es).
 * @param subject the mail subject.
 * @param soapMessage the SOAP message.
 * @param session the mail session.
 * @return a new MIME message.
 * @throws ConnectionException if error occurred in constructing the mail
 *             message.
 * @see hk.hku.cecid.piazza.commons.net.MailSender#createMessage(java.lang.String, java.lang.String, java.lang.String, java.lang.String, javax.mail.Session)
 */
public MimeMessage createMessage(String from, String to, String cc,
        String subject, SOAPMessage soapMessage, Session session) throws ConnectionException {
    try {
        MimeMessage message = super.createMessage(from, to, cc, subject, session);
        
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        soapMessage.writeTo(bos);
        String contentType = getContentType(soapMessage);
        
        ByteArrayDataSource content = new ByteArrayDataSource(bos.toByteArray(), contentType);
        soapMessage.getAttachments();
        boolean hasAttachments = soapMessage.countAttachments() > 0;
        if (hasAttachments) {
            putHeaders(soapMessage.getMimeHeaders(), message);
            MimeMultipart mmp = new MimeMultipart(content);
            for (int i=0; i<mmp.getCount(); i++) {
                BodyPart bp = mmp.getBodyPart(i);

                // encoding all parts in base64 to overcome length of character line limitation in SMTP
                InputStreamDataSource isds = new InputStreamDataSource(
                	bp.getInputStream(), bp.getContentType(), bp.getFileName());
                bp.setDataHandler(new DataHandler(isds));
                bp.setHeader("Content-Transfer-Encoding", "base64");              
            }
            message.setContent(mmp);
        }
        else {
            DataHandler dh = new DataHandler(content);
            message.setDataHandler(dh);
            message.setHeader("Content-Transfer-Encoding", "base64");
        }

        message.saveChanges();
        return message;
    }
    catch (Exception e) {
        throw new ConnectionException("Unable to construct mail message from SOAP message", e);
    }
}
 
开发者ID:cecid,项目名称:hermes,代码行数:54,代码来源:SOAPMailSender.java

示例13: doFilter

import javax.mail.BodyPart; //导入方法依赖的package包/类
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
    throws IOException, ServletException {
  HttpServletRequest req = (HttpServletRequest) request;
  if (req.getHeader(UPLOAD_HEADER) != null) {
    Map<String, List<String>> blobKeys = new HashMap<String, List<String>>();
    Map<String, List<Map<String, String>>> blobInfos =
        new HashMap<String, List<Map<String, String>>>();
    Map<String, List<String>> otherParams = new HashMap<String, List<String>>();

    try {
      MimeMultipart multipart = MultipartMimeUtils.parseMultipartRequest(req);

      int parts = multipart.getCount();
      for (int i = 0; i < parts; i++) {
        BodyPart part = multipart.getBodyPart(i);
        String fieldName = MultipartMimeUtils.getFieldName(part);
        if (part.getFileName() != null) {
          ContentType contentType = new ContentType(part.getContentType());
          if ("message/external-body".equals(contentType.getBaseType())) {
            String blobKeyString = contentType.getParameter("blob-key");
            List<String> keys = blobKeys.get(fieldName);
            if (keys == null) {
              keys = new ArrayList<String>();
              blobKeys.put(fieldName, keys);
            }
            keys.add(blobKeyString);
            List<Map<String, String>> infos = blobInfos.get(fieldName);
            if (infos == null) {
              infos = new ArrayList<Map<String, String>>();
              blobInfos.put(fieldName, infos);
            }
            infos.add(getInfoFromBody(MultipartMimeUtils.getTextContent(part), blobKeyString));
          }
        } else {
          List<String> values = otherParams.get(fieldName);
          if (values == null) {
            values = new ArrayList<String>();
            otherParams.put(fieldName, values);
          }
          values.add(MultipartMimeUtils.getTextContent(part));
        }
      }
      req.setAttribute(UPLOADED_BLOBKEY_ATTR, blobKeys);
      req.setAttribute(UPLOADED_BLOBINFO_ATTR, blobInfos);
    } catch (MessagingException ex) {
      logger.log(Level.WARNING, "Could not parse multipart message:", ex);
    }

    chain.doFilter(new ParameterServletWrapper(request, otherParams), response);
  } else {
    chain.doFilter(request, response);
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-java-vm-runtime,代码行数:54,代码来源:ParseBlobUploadFilter.java


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