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


Java MimeUtility.decodeText方法代码示例

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


在下文中一共展示了MimeUtility.decodeText方法的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: 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

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

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

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

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

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

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

示例10: getAttachmentKey

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

示例11: getFromAddress

import javax.mail.internet.MimeUtility; //导入方法依赖的package包/类
/**
 * Access the from: address of the message.
 * 
 * @return The from: address of the message.
 */
public String getFromAddress()
{
	String fromAddress = ((m_fromAddress == null) ? "" : m_fromAddress);
	
	try
	{
		fromAddress = MimeUtility.decodeText(fromAddress);
	}
	catch (UnsupportedEncodingException e)
	{
		// if unable to decode RFC address, just return address as is
		log.debug(this+".getFromAddress "+e.toString());
	}
	
	return fromAddress;

}
 
开发者ID:sakaiproject,项目名称:sakai,代码行数:23,代码来源:BaseMailArchiveService.java

示例12: handleAttachment

import javax.mail.internet.MimeUtility; //导入方法依赖的package包/类
private static void handleAttachment(Part part, List<EmailAttachment> attachments) throws MessagingException {
	String fileName = part.getFileName();
	try {
		if (fileName != null) {
			fileName = MimeUtility.decodeText(fileName);
		} else {
			fileName = "binaryPart.dat";
		}
		attachments.add(createEmailAttachment(part, fileName));
	} catch (Exception e) {
		// just ignore
	}
}
 
开发者ID:trackplus,项目名称:Genji,代码行数:14,代码来源:MailReader.java

示例13: getFiles

import javax.mail.internet.MimeUtility; //导入方法依赖的package包/类
/**
 * 获取消息附件中的文件.
 * @return List&lt;ResourceFileBean&gt;
 * 				文件的集合(每个 ResourceFileBean 对象中存放文件名和 InputStream 对象)
 * @throws MessagingException
 *             the messaging exception
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 */
public List<ResourceFileBean> getFiles() throws MessagingException, IOException {
	List<ResourceFileBean> resourceList = new ArrayList<ResourceFileBean>();
	Object content = message.getContent();
	Multipart mp = null;
	if (content instanceof Multipart) {
		mp = (Multipart) content;
	} else {
		return resourceList;
	}
	for (int i = 0, n = mp.getCount(); i < n; i++) {
		Part part = mp.getBodyPart(i);
		//此方法返回 Part 对象的部署类型。
		String disposition = part.getDisposition();
		//Part.ATTACHMENT 指示 Part 对象表示附件。
		//Part.INLINE 指示 Part 对象以内联方式显示。
		if ((disposition != null) && ((disposition.equals(Part.ATTACHMENT) || (disposition.equals(Part.INLINE))))) {
			//part.getFileName():返回 Part 对象的文件名。
			String fileName = MimeUtility.decodeText(part.getFileName());
			//此方法为 Part 对象返回一个 InputStream 对象
			InputStream is = part.getInputStream();
			resourceList.add(new ResourceFileBean(fileName, is));
		} else if (disposition == null) {
			//附件也可以没有部署类型的方式存在
			getRelatedPart(part, resourceList);
		}
	}
	return resourceList;
}
 
开发者ID:heartsome,项目名称:translationstudio8,代码行数:38,代码来源:MessageParser.java

示例14: testSend

import javax.mail.internet.MimeUtility; //导入方法依赖的package包/类
@Test
public void testSend() throws MessagingException, UnsupportedEncodingException {

    Session session = GreenMailUtil.getSession(ServerSetupTest.SMTP, properties);
    MimeMessage mimeMessage = new MockInternationalizedMimeMessage(session);
    mimeMessage.setSubject("subject");
    mimeMessage.setSentDate(new Date());
    mimeMessage.setFrom("múchätįldé@tìldę.oœ");
    mimeMessage.setRecipients(Message.RecipientType.TO, "用户@例子.广告");
    mimeMessage.setRecipients(Message.RecipientType.CC, "θσερεχα@μπλε.ψομ");
    mimeMessage.setRecipients(Message.RecipientType.BCC, "राममो@हन.ईन्फो");

    // The body text needs to be encoded if it contains non us-ascii characters
    mimeMessage.setText(MimeUtility.encodeText("用户@例子"));

    GreenMailUtil.sendMimeMessage(mimeMessage);

    // Decoding the body text to verify equality
    String decodedText = MimeUtility.decodeText(GreenMailUtil.getBody(greenMail.getReceivedMessages()[0]));
    assertEquals("用户@例子", decodedText);
}
 
开发者ID:greenmail-mail-test,项目名称:greenmail,代码行数:22,代码来源:SendReceiveWithInternationalAddressTest.java

示例15: mimeDecodeString

import javax.mail.internet.MimeUtility; //导入方法依赖的package包/类
/**
 * For receiving an email, the sender, receiver, reply-to and subject may 
 * be messy code. The default encoding of HTTP is ISO8859-1, In this situation, 
 * use MimeUtility.decodeTex() to convert these information to GBK encoding.
 * @param res The String to be decoded.
 * @return A decoded String.
 */
private static String mimeDecodeString(String res) {
    if(res != null) {
        String from = res.trim();
        try {
            if (from.startsWith("=?GB") || from.startsWith("=?gb")
                    || from.startsWith("=?UTF") || from.startsWith("=?utf")) {
                from = MimeUtility.decodeText(from);
            }
        } catch (Exception e) {
            LOGGER.error("Decode string error. Origin string is: " + res, e);
        }
        return from;
    }
    return null;
}
 
开发者ID:yifzhang,项目名称:storm-miclog,代码行数:23,代码来源:MailUtils.java


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