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


Java BodyPart.getFileName方法代码示例

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


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

示例1: saveAttachMent

import javax.mail.BodyPart; //导入方法依赖的package包/类
/**   
 * 【保存附件】   
 */   
public void saveAttachMent(Part part) throws Exception {   
    String fileName = "";   
    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)))) {   
                fileName = mpart.getFileName();   
                if (fileName.toLowerCase().indexOf("gb2312") != -1) {   
                    fileName = MimeUtility.decodeText(fileName);   
                }   
                saveFile(fileName, mpart.getInputStream());   
            } else if (mpart.isMimeType("multipart/*")) {   
                saveAttachMent(mpart);   
            } else {   
                fileName = mpart.getFileName();   
                if ((fileName != null)   
                        && (fileName.toLowerCase().indexOf("GB2312") != -1)) {   
                    fileName = MimeUtility.decodeText(fileName);   
                    saveFile(fileName, mpart.getInputStream());   
                }   
            }   
        }   
    } else if (part.isMimeType("message/rfc822")) {   
        saveAttachMent((Part) part.getContent());   
    }   
}
 
开发者ID:tiglabs,项目名称:jsf-core,代码行数:34,代码来源:ReciveMail.java

示例2: saveFile

import javax.mail.BodyPart; //导入方法依赖的package包/类
/**
 * �����Ĵ������ϴ�
 */
private void saveFile(Message message, BodyPart bp) throws Exception {
	String fileName = bp.getFileName();
	if ((fileName != null)) {
		new File(dir).mkdirs(); // �½�Ŀ¼
		fileName = MimeUtility.decodeText(fileName);
		String suffix = fileName.substring(fileName.lastIndexOf("."));
		String filePath = dir + "/" + UUID.randomUUID() + suffix;
		message.attachMap.put(fileName, filePath);

		File file = new File(filePath);
		BufferedInputStream bis = new BufferedInputStream(bp.getInputStream());
		BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file));
		int i;
		while ((i = bis.read()) != -1) {
			bos.write(i);
		}
		bos.close();
		bis.close();
	}
}
 
开发者ID:toulezu,项目名称:play,代码行数:24,代码来源:MailHelper.java

示例3: getContent

import javax.mail.BodyPart; //导入方法依赖的package包/类
public static String getContent(Part message) throws MessagingException,
        IOException {

    if (message.getContent() instanceof String) {
        return message.getContentType() + ": " + message.getContent() + " \n\t";
    } else if (message.getContent() != null && message.getContent() instanceof Multipart) {
        Multipart part = (Multipart) message.getContent();
        String text = "";
        for (int i = 0; i < part.getCount(); i++) {
            BodyPart bodyPart = part.getBodyPart(i);
            if (!Message.ATTACHMENT.equals(bodyPart.getDisposition())) {
                text += getContent(bodyPart);
            } else {
                text += "attachment: \n" +
                        "\t\t name: " + (StringUtils.isEmpty(bodyPart.getFileName()) ? "none"
                        : bodyPart.getFileName()) + "\n" +
                        "\t\t disposition: " + bodyPart.getDisposition() + "\n" +
                        "\t\t description: " + (StringUtils.isEmpty(bodyPart.getDescription()) ? "none"
                        : bodyPart.getDescription()) + "\n\t";
            }
        }
        return text;
    }
    if (message.getContent() != null && message.getContent() instanceof Part) {
        if (!Message.ATTACHMENT.equals(message.getDisposition())) {
            return getContent((Part) message.getContent());
        } else {
            return "attachment: \n" +
                    "\t\t name: " + (StringUtils.isEmpty(message.getFileName()) ? "none"
                    : message.getFileName()) + "\n" +
                    "\t\t disposition: " + message.getDisposition() + "\n" +
                    "\t\t description: " + (StringUtils.isEmpty(message.getDescription()) ? "none"
                    : message.getDescription()) + "\n\t";
        }
    }

    return "";
}
 
开发者ID:GojaFramework,项目名称:goja,代码行数:39,代码来源:EMail.java

示例4: getAttachmentKey

import javax.mail.BodyPart; //导入方法依赖的package包/类
private String getAttachmentKey(BodyPart bp) throws MessagingException, UnsupportedEncodingException {
    // use the filename as key for the map
    String key = bp.getFileName();
    // if there is no file name we use the Content-ID header
    if (key == null && bp instanceof MimeBodyPart) {
        key = ((MimeBodyPart)bp).getContentID();
        if (key != null && key.startsWith("<") && key.length() > 2) {
            // strip <>
            key = key.substring(1, key.length() - 1);
        }
    }
    // or a generated content id
    if (key == null) {
        key = UUID.randomUUID().toString() + "@camel.apache.org";
    }
    return MimeUtility.decodeText(key);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:MimeMultipartDataFormat.java

示例5: getMainPart

import javax.mail.BodyPart; //导入方法依赖的package包/类
private MimeBodyPart getMainPart() throws MessagingException {
	MimeMultipart mimeMultipart = getMimeMultipart();
	MimeBodyPart bodyPart = null;
	for (int i = 0; i < mimeMultipart.getCount(); i++) {
		BodyPart bp = mimeMultipart.getBodyPart(i);
		if (bp.getFileName() == null) {
			bodyPart = (MimeBodyPart) bp;
		}
	}
	if (bodyPart == null) {
		MimeBodyPart mimeBodyPart = new MimeBodyPart();
		mimeMultipart.addBodyPart(mimeBodyPart);
		bodyPart = mimeBodyPart;
	}
	return bodyPart;
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:17,代码来源:MimeMessageHelper.java

示例6: save

import javax.mail.BodyPart; //导入方法依赖的package包/类
private void save(Store store, String wheretobackup, String f) throws MessagingException, IOException {

	    System.out.println("opening folder " + f);
	    Folder folder = store.getFolder(f);
	    folder.open(Folder.READ_ONLY);

	    FileUtils.forceMkdir(new File(wheretobackup));

		// Get directory
		Message message[] = folder.getMessages();
		for (int i = 0, n = message.length; i < n; i++) {
			// String from = (message[i].getFrom()[0]).toString();
			String subj = (message[i].getSubject()).toString();
			String nota = (message[i].getContent()).toString();

			if (message[i].getContent() instanceof MimeMultipart) {

				MimeMultipart multipart = (MimeMultipart) message[i].getContent();

				for (int j = 0; j < multipart.getCount(); j++) {

					BodyPart bodyPart = multipart.getBodyPart(j);
						
						if (bodyPart.isMimeType("text/html")) {
							nota = bodyPart.getContent().toString();
							generals.writeFile(wheretobackup + "/" + generals.makeFilename(subj).trim() + ".html", nota, message[i].getSentDate());
							
						} else if (bodyPart.isMimeType("IMAGE/PNG")) {
							String imagecid = ((MimePart) bodyPart).getContentID();
							
							InputStream is = bodyPart.getInputStream();
						    FileUtils.forceMkdir(new File(wheretobackup + "/images/"));
							File fimg = new File(wheretobackup + "/images/" + bodyPart.getFileName());
							System.out.println("saving " + wheretobackup + "/images/" + bodyPart.getFileName());
					        FileOutputStream fos = new FileOutputStream(fimg);
					        byte[] buf = new byte[4096];
					        int bytesRead;
					        while((bytesRead = is.read(buf))!=-1) {
					            fos.write(buf, 0, bytesRead);
					        }
					        fos.close();
					        
					        
					        // devi fare il replace 0DA094B7-933A-4B19-947F-2FC42FA9DABD
							System.out.println("html replace file name : " + imagecid);							
							System.out.println("into file name : " + bodyPart .getFileName());							

						}
				}
			} else {
				generals.writeFile(wheretobackup + "/" + generals.makeFilename(subj).trim() + ".html", nota, message[i].getSentDate());
			}
		}
		folder.close(false);
	}
 
开发者ID:edoardoc,项目名称:iCloudNotes,代码行数:56,代码来源:NotesSaver.java

示例7: getPartFilename

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

示例8: 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

示例9: 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

示例10: processRequest

import javax.mail.BodyPart; //导入方法依赖的package包/类
/**
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        System.out.println("Uploader request: path=" + request.getPathInfo() + " querystring=" + request.getQueryString() + " sess=" + request.getSession(false));

        int t = 0;
        String ct = request.getContentType();
        if (ct == null) {
            return;
        }

        if (ct.startsWith("multipart/form-data;")) {
            MultipartDataSource src = new MultipartDataSource(request);
            MimeMultipart mp;

            try {
                mp = new MimeMultipart(src);
                System.out.println("Got body count " + mp.getCount());

                BodyPart bp = mp.getBodyPart(0);
                FileOutputStream fout = new FileOutputStream("c:\\temp\\" + bp.getFileName());
                bp.getDataHandler().writeTo(fout);
                fout.close();
                System.out.println("Upload data read complete.");

                System.out.println("FileName = " + bp.getFileName());
                System.out.println("Disposition = " + bp.getDisposition());
                System.out.println("Description = " + bp.getDescription());
                System.out.println("Size = " + bp.getSize());
            } catch (MessagingException ex) {
                ex.printStackTrace();
            }
        } else {
            System.out.println("Uknown content type: " + ct);
            /*
            ServletInputStream in = request.getInputStream();
            int                c;
            byte[]             b = new byte[10240];
            
            while ((c = in.read(b)) != -1) {
            
            // System.out.println ("Read "+c+" bytes");
            t += c;
            }
            System.out.println("UploadServlet data read complete " + t + " bytes");
             */
        }


//      response.setStatus(response.SC_NO_CONTENT);
    }
 
开发者ID:ethanpeng,项目名称:openacs,代码行数:56,代码来源:UploadServlet.java


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