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


Java MimeUtility类代码示例

本文整理汇总了Java中javax.mail.internet.MimeUtility的典型用法代码示例。如果您正苦于以下问题:Java MimeUtility类的具体用法?Java MimeUtility怎么用?Java MimeUtility使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: saveAttachMent

import javax.mail.internet.MimeUtility; //导入依赖的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: getFrom

import javax.mail.internet.MimeUtility; //导入依赖的package包/类
public static String getFrom(MimeMessage msg) throws MessagingException,
        UnsupportedEncodingException {
    String from = "";
    Address[] froms = msg.getFrom();

    if (froms.length < 1) {
        throw new MessagingException("没有发件人!");
    }

    InternetAddress address = (InternetAddress) froms[0];
    String person = address.getPersonal();

    if (person != null) {
        person = MimeUtility.decodeText(person) + " ";
    } else {
        person = "";
    }

    from = person + "<" + address.getAddress() + ">";

    return from;
}
 
开发者ID:zhaojunfei,项目名称:lemon,代码行数:23,代码来源:JavamailService.java

示例3: buildContentModelMessage

import javax.mail.internet.MimeUtility; //导入依赖的package包/类
/**
 * This method builds {@link MimeMessage} based on {@link ContentModel}
 * 
 * @throws MessagingException
 */
private void buildContentModelMessage() throws MessagingException
{
    Map<QName, Serializable> properties = messageFileInfo.getProperties();
    String prop = null;
    setSentDate(messageFileInfo.getModifiedDate());
    // Add FROM address
    Address[] addressList = buildSenderFromAddress();
    addFrom(addressList);
    // Add TO address
    addressList = buildRecipientToAddress();
    addRecipients(RecipientType.TO, addressList);
    prop = (String) properties.get(ContentModel.PROP_TITLE);
    try
    {
        prop = (prop == null || prop.equals("")) ? messageFileInfo.getName() : prop;
        prop = MimeUtility.encodeText(prop, AlfrescoImapConst.UTF_8, null);
    }
    catch (UnsupportedEncodingException e)
    {
        // ignore
    }
    setSubject(prop);
    setContent(buildContentModelMultipart());
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:30,代码来源:ContentModelMessage.java

示例4: downloadAttachment

import javax.mail.internet.MimeUtility; //导入依赖的package包/类
private void downloadAttachment(Part part, String folderPath) throws MessagingException, IOException {
	String disPosition = part.getDisposition();
	String fileName = part.getFileName();
	String decodedAttachmentName = null;

	if (fileName != null) {
		LOGGER.info("Attached File Name :: " + fileName);
		decodedAttachmentName = MimeUtility.decodeText(fileName);
		LOGGER.info("Decoded string :: " + decodedAttachmentName);
		decodedAttachmentName = Normalizer.normalize(decodedAttachmentName, Normalizer.Form.NFC);
		LOGGER.info("Normalized string :: " + decodedAttachmentName);
		int extensionIndex = decodedAttachmentName.indexOf(EXTENSION_VALUE_46);
		extensionIndex = extensionIndex == -1 ? decodedAttachmentName.length() : extensionIndex;
		File parentFile = new File(folderPath);
		LOGGER.info("Updating file name if any file with the same name exists. File : " + decodedAttachmentName);
		decodedAttachmentName = FileUtils.getUpdatedFileNameForDuplicateFile(decodedAttachmentName.substring(0, extensionIndex), parentFile, -1)
				+ decodedAttachmentName.substring(extensionIndex);

		LOGGER.info("Updated file name : " + decodedAttachmentName);
	}
	if (disPosition != null && disPosition.equalsIgnoreCase(Part.ATTACHMENT)) {
		File file = new File(folderPath + File.separator + decodedAttachmentName);
		file.getParentFile().mkdirs();
		saveEmailAttachment(file, part);
	}
}
 
开发者ID:kuzavas,项目名称:ephesoft,代码行数:27,代码来源:MailReceiverServiceImpl.java

示例5: parsePart

import javax.mail.internet.MimeUtility; //导入依赖的package包/类
private void parsePart(Part part) throws Exception {
    if (part.isMimeType("text/*")) {
        content.append((String) part.getContent());
    } else if (part.isMimeType("multipart/*")) {
        Part p = null;
        Multipart multipart = (Multipart) part.getContent();
        for (int i = 0; i < multipart.getCount(); i++) {
            p = multipart.getBodyPart(i);
            String disposition = p.getDisposition();
            if (disposition != null && (disposition.equals(Part.ATTACHMENT) || disposition.equals(Part.INLINE))) {
                attachments.add(MimeUtility.decodeText(p.getFileName()));
            }
            parsePart(p);
        }
    } else if (part.isMimeType("message/rfc822")) {
        parsePart((Part) part.getContent());
    }
}
 
开发者ID:txazo,项目名称:txazo,代码行数:19,代码来源:MimeEmail.java

示例6: saveFile

import javax.mail.internet.MimeUtility; //导入依赖的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

示例7: getFilename

import javax.mail.internet.MimeUtility; //导入依赖的package包/类
public static String getFilename( Part Mess ) throws MessagingException{
// Part.getFileName() doesn't take into account any encoding that may have been 
// applied to the filename so in order to obtain the correct filename we
// need to retrieve it from the Content-Disposition

String [] contentType = Mess.getHeader( "Content-Disposition" );
	if ( contentType != null && contentType.length > 0 ){
		int nameStartIndx = contentType[0].indexOf( "filename=\"" );
		if ( nameStartIndx != -1 ){
			String filename = contentType[0].substring( nameStartIndx+10, contentType[0].indexOf( '\"', nameStartIndx+10 ) );
			try {
			filename = MimeUtility.decodeText( filename );
			return filename;
		} catch (UnsupportedEncodingException e) {}
		}  		
	}

	// couldn't determine it using the above, so fall back to more reliable but 
// less correct option
	return Mess.getFileName();
}
 
开发者ID:OpenBD,项目名称:openbd-core,代码行数:22,代码来源:cfMailMessageData.java

示例8: digestString

import javax.mail.internet.MimeUtility; //导入依赖的package包/类
/**
 * Calculate digest of given String using given algorithm. Encode digest in
 * MIME-like base64.
 * 
 * @param pass
 *            the String to be hashed
 * @param algorithm
 *            the algorithm to be used
 * @return String Base-64 encoding of digest
 * 
 * @throws NoSuchAlgorithmException
 *             if the algorithm passed in cannot be found
 */
public static String digestString(String pass, String algorithm) throws NoSuchAlgorithmException {

    MessageDigest md;
    ByteArrayOutputStream bos;

    try {
        md = MessageDigest.getInstance(algorithm);
        byte[] digest = md.digest(pass.getBytes("iso-8859-1"));
        bos = new ByteArrayOutputStream();
        OutputStream encodedStream = MimeUtility.encode(bos, "base64");
        encodedStream.write(digest);
        return bos.toString("iso-8859-1");
    } catch (IOException ioe) {
        throw new RuntimeException("Fatal error: " + ioe);
    } catch (MessagingException me) {
        throw new RuntimeException("Fatal error: " + me);
    }
}
 
开发者ID:twachan,项目名称:James,代码行数:32,代码来源:DigestUtil.java

示例9: getPartFileName

import javax.mail.internet.MimeUtility; //导入依赖的package包/类
/**
 * Method extracts file name from a message part for saving its as aa attachment. If the file name can't be extracted, it will be generated based on defaultPrefix parameter.
 * 
 * @param defaultPrefix This prefix fill be used for generating file name.
 * @param messagePart A part of message
 * @return File name.
 * @throws MessagingException
 */
private String getPartFileName(String defaultPrefix, Part messagePart) throws MessagingException
{
    String fileName = messagePart.getFileName();
    if (fileName != null)
    {
        try
        {
            fileName = MimeUtility.decodeText(fileName);
        }
        catch (UnsupportedEncodingException ex)
        {
            // Nothing to do :)
        }
    }
    else
    {
        fileName = defaultPrefix;
        if (messagePart.isMimeType(MIME_PLAIN_TEXT))
            fileName += ".txt";
        else if (messagePart.isMimeType(MIME_HTML_TEXT))
            fileName += ".html";
        else if (messagePart.isMimeType(MIME_XML_TEXT))
            fileName += ".xml";
        else if (messagePart.isMimeType(MIME_IMAGE))
            fileName += ".gif";
    }
    return fileName;
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:37,代码来源:SubethaEmailMessage.java

示例10: setFrom

import javax.mail.internet.MimeUtility; //导入依赖的package包/类
/**
 * 设置发信人
 * 
 * @param name String
 * @param pass String
 */
public boolean setFrom(String from) {
	if (from == null || from.trim().equals("")) {
		from = PropertiesUtil.getString("email.send.from");
	}
	try {
		String[] f = from.split(",");
		if (f.length > 1) {
			from = MimeUtility.encodeText(f[0]) + "<" + f[1] + ">";
		}
		mimeMsg.setFrom(new InternetAddress(from)); // 设置发信人
		return true;
	} catch (Exception e) {
		logger.error(e.getLocalizedMessage());
		return false;
	}
}
 
开发者ID:guokezheng,项目名称:automat,代码行数:23,代码来源:EmailSender.java

示例11: saveReportValues

import javax.mail.internet.MimeUtility; //导入依赖的package包/类
private void saveReportValues() throws AS2MessageException {
    try {
        Enumeration reportEn = reportValues.getAllHeaderLines();
        StringBuffer reportData = new StringBuffer();

        while (reportEn.hasMoreElements()) {
            reportData.append((String) reportEn.nextElement()).append("\r\n");
        }

        reportData.append("\r\n");

        String reportText = MimeUtility.encodeText(reportData.toString(),
                "us-ascii", "7bit");
        reportPart.setContent(reportText,
                AS2Header.CONTENT_TYPE_MESSAGE_DISPOSITION_NOTIFICATION);
        reportPart.setHeader("Content-Type",
                AS2Header.CONTENT_TYPE_MESSAGE_DISPOSITION_NOTIFICATION);
        reportPart.setHeader("Content-Transfer-Encoding", "7bit");
    }
    catch (Exception e) {
        throw new AS2MessageException("Error in saving report values", e);
    }
}
 
开发者ID:cecid,项目名称:hermes,代码行数:24,代码来源:DispositionNotification.java

示例12: getFrom

import javax.mail.internet.MimeUtility; //导入依赖的package包/类
/**
 * ����ʼ�������
 * @param msg �ʼ�����
 * @return ���� <Email��ַ>
 */ 
public static String getFrom(MimeMessage msg) throws MessagingException, UnsupportedEncodingException { 
    String from = ""; 
    Address[] froms = msg.getFrom(); 
    if (froms.length < 1){
    	//return "ϵͳ�ָ�";
        throw new MessagingException("û�з�����!");
    }         
    InternetAddress address = (InternetAddress) froms[0]; 
    String person = address.getPersonal(); 
    if (person != null) { 
        person = MimeUtility.decodeText(person) + " "; 
    } else { 
        person = ""; 
    } 
    from = person + "<" + address.getAddress() + ">"; 
     
    return from; 
}
 
开发者ID:bjut-2014,项目名称:scada,代码行数:24,代码来源:MailUtils.java

示例13: addAttachFile

import javax.mail.internet.MimeUtility; //导入依赖的package包/类
/**
 * 
 * 发送邮件时添加附件列表
 * @param mp
 * @param attachFiles
 * @return
 * @throws MailException
 * @throws IOException
 * @throws MessagingException
 */
private Multipart  addAttachFile(Multipart mp, Set<String> attachFiles) throws MailException, IOException, MessagingException{
	
	if(mp == null){
		throw new MailException("bean Multipart is null .");
	}
	
	//没有附件时直接返回
	if(attachFiles == null || (attachFiles.size())== 0){
		return mp;
	}
	Iterator<String> iterator = attachFiles.iterator();
	while (iterator.hasNext()) {
		String fileName  = iterator.next();
		MimeBodyPart mbp_file = new MimeBodyPart();
		mbp_file.attachFile(fileName);
		mp.addBodyPart(mbp_file);
		//防止乱码
		String encode = MimeUtility.encodeText(mbp_file.getFileName());
           mbp_file.setFileName(encode); 
		
	}
	
	return mp;
}
 
开发者ID:thinking-github,项目名称:nbone,代码行数:35,代码来源:MailServiceImpl.java

示例14: getFrom

import javax.mail.internet.MimeUtility; //导入依赖的package包/类
/**
 * 获得邮件发件人
 * @param msg 邮件内容
 * @return 姓名 <Email地址>
 * @throws MessagingException
 * @throws UnsupportedEncodingException 
 */
public static String getFrom(MimeMessage msg) throws MessagingException, UnsupportedEncodingException {
	String from = "";
	Address[] froms = msg.getFrom();
	if (froms.length < 1)
		throw new MessagingException("没有发件人!");
	
	InternetAddress address = (InternetAddress) froms[0];
	String person = address.getPersonal();
	if (person != null) {
		person = MimeUtility.decodeText(person) + " ";
	} else {
		person = "";
	}
	from = person + "<" + address.getAddress() + ">";
	
	return from;
}
 
开发者ID:xiaomin0322,项目名称:alimama,代码行数:25,代码来源:POP3ReceiveMailTest.java

示例15: getAttachments

import javax.mail.internet.MimeUtility; //导入依赖的package包/类
/**
 * Extracts the attachments from the mail.
 *
 * @param message
 *            The message.
 * @return Collection of attachments as {@link AttachmentTO}.
 * @throws IOException
 *             Exception.
 * @throws MessagingException
 *             Exception.
 */
public static Collection<AttachmentTO> getAttachments(Message message)
        throws MessagingException, IOException {
    Collection<AttachmentTO> attachments = new ArrayList<AttachmentTO>();
    Collection<Part> parts = getAllParts(message);
    for (Part part : parts) {
        String disposition = part.getDisposition();
        String contentType = part.getContentType();
        if (StringUtils.containsIgnoreCase(disposition, "inline")
                || StringUtils.containsIgnoreCase(disposition, "attachment")
                || StringUtils.containsIgnoreCase(contentType, "name=")) {
            String fileName = part.getFileName();
            Matcher matcher = FILENAME_PATTERN.matcher(part.getContentType());
            if (matcher.matches()) {
                fileName = matcher.group(1);
                fileName = StringUtils.substringBeforeLast(fileName, ";");
            }
            if (StringUtils.isNotBlank(fileName)) {
                fileName = fileName.replace("\"", "").replace("\\\"", "");
                fileName = MimeUtility.decodeText(fileName);
                if (fileName.endsWith("?=")) {
                    fileName = fileName.substring(0, fileName.length() - 2);
                }
                fileName = fileName.replace("?", "_");
                AttachmentTO attachmentTO = new AttachmentStreamTO(part.getInputStream());
                attachmentTO.setContentLength(part.getSize());
                attachmentTO.setMetadata(new ContentMetadata());
                attachmentTO.getMetadata().setFilename(fileName);
                if (StringUtils.isNotBlank(contentType)) {
                    contentType = contentType.split(";")[0].toLowerCase();
                }
                attachmentTO.setStatus(AttachmentStatus.UPLOADED);
                attachments.add(attachmentTO);
            }
        }
    }
    return attachments;
}
 
开发者ID:Communote,项目名称:communote-server,代码行数:49,代码来源:MailMessageHelper.java


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