本文整理汇总了Java中javax.mail.internet.MimeUtility.encodeText方法的典型用法代码示例。如果您正苦于以下问题:Java MimeUtility.encodeText方法的具体用法?Java MimeUtility.encodeText怎么用?Java MimeUtility.encodeText使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.mail.internet.MimeUtility
的用法示例。
在下文中一共展示了MimeUtility.encodeText方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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());
}
示例2: 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;
}
}
示例3: 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);
}
}
示例4: 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;
}
示例5: getAddressList
import javax.mail.internet.MimeUtility; //导入方法依赖的package包/类
private static String getAddressList(Set<? extends MessageRecipient> to) {
StringBuilder sb = new StringBuilder();
for (MessageRecipient p : to) {
EmailMessageRecipient er = (EmailMessageRecipient)p;
if (er.getEmail().length() > 0) {
if (sb.toString().length() > 0) {
sb.append(", ");
}
if (er.getName() != null && er.getName().length() > 0) {
String name = er.getName();
try {
name = MimeUtility.encodeText(name);
} catch (UnsupportedEncodingException e) {
Log.d("yako", "", e);
}
sb.append(name);
}
sb.append("<").append(er.getEmail()).append(">");
}
}
return sb.toString();
}
示例6: setAddressHeader
import javax.mail.internet.MimeUtility; //导入方法依赖的package包/类
private void setAddressHeader(String name, InternetAddress[] addresses)
throws MessagingException {
try {
// Encoding the email addresses so they are correctly sent to the mail server.
for (int i = 0; i < addresses.length; i++) {
String addStr = MimeUtility.encodeText(addresses[i].getAddress());
InternetAddress ia = new InternetAddress();
ia.setAddress(addStr);
addresses[i] = ia;
}
String s = InternetAddress.toString(addresses, name.length() + 2);
setHeader(name, s);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}
示例7: setFrom
import javax.mail.internet.MimeUtility; //导入方法依赖的package包/类
/**
* 设置发信人
*
* @param from
* @return
*/
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;
}
}
示例8: encodeFilenameForDownload
import javax.mail.internet.MimeUtility; //导入方法依赖的package包/类
/**
* Encode a filename in such a way that the UTF-8 characters won't be munged during the download by a browser. Need
* the request to work out the user's browser type
*
* @return encoded filename
* @throws UnsupportedEncodingException
*/
public static String encodeFilenameForDownload(HttpServletRequest request, String unEncodedFilename)
throws UnsupportedEncodingException {
// Different browsers handle stream downloads differently LDEV-1243
String agent = request.getHeader("USER-AGENT");
String filename = null;
if ((null != agent) && (-1 != agent.indexOf("MSIE"))) {
// if MSIE then urlencode it
filename = URLEncoder.encode(unEncodedFilename, FileUtil.ENCODING_UTF_8);
} else if ((null != agent) && (-1 != agent.indexOf("Mozilla"))) {
// if Mozilla then base64 url_safe encoding
filename = MimeUtility.encodeText(unEncodedFilename, FileUtil.ENCODING_UTF_8, "B");
} else {
// any others use same filename.
filename = unEncodedFilename;
}
// wrap filename in quotes as if it contains comma character Chrome can throw a multiple headers error
filename = "\"" + filename + "\"";
return filename;
}
示例9: encode
import javax.mail.internet.MimeUtility; //导入方法依赖的package包/类
public static String encode(String value, String charset) {
try {
return MimeUtility.encodeText(value, charset, null);
}
catch (UnsupportedEncodingException ex) {
throw new IllegalStateException(ex);
}
}
示例10: setText
import javax.mail.internet.MimeUtility; //导入方法依赖的package包/类
public void setText(String text) throws AS2MessageException {
try {
String encodeText = MimeUtility.encodeText(text + "\r\n", "us-ascii",
"7bit");
textPart.setContent(encodeText, "text/plain");
textPart.setHeader("Content-Type", "text/plain; charset=us-ascii");
textPart.setHeader("Content-Transfer-Encoding", "7bit");
}
catch (Exception e) {
throw new AS2MessageException("Unable to set text to MDN", e);
}
}
示例11: encode
import javax.mail.internet.MimeUtility; //导入方法依赖的package包/类
/**
* Encode specified value as RFC 2047
* @param name
* @return
* @throws Exception
*/
public static String encode(String name) {
try {
return MimeUtility.encodeText(name, "UTF-8", null);
} catch (UnsupportedEncodingException e) {
throw Throwables.asRuntime(e);
}
}
示例12: encodeText
import javax.mail.internet.MimeUtility; //导入方法依赖的package包/类
/**
* To make sure email clients can interpret text properly, we need to encode some values according to RFC-2047.
*/
public static String encodeText(@Nullable final String name) {
if (name == null) {
return null;
}
try {
return MimeUtility.encodeText(name);
} catch (final UnsupportedEncodingException e) {
throw new IllegalArgumentException(e.getMessage(), e);
}
}
示例13: getSubject
import javax.mail.internet.MimeUtility; //导入方法依赖的package包/类
public String getSubject() {
try {
subject = MimeUtility.encodeText(subject, "UTF-8", "B");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return subject;
}
示例14: transferChinese
import javax.mail.internet.MimeUtility; //导入方法依赖的package包/类
/**
* <br>
* 方法说明:把主题转换为中文 <br>
* 输入参数:String strText <br>
* 返回类型:
*/
@SuppressWarnings("unused")
private String transferChinese(String strText) {
try {
strText = MimeUtility.encodeText(new String(strText.getBytes(),
"GB2312"), "GB2312", "B");
} catch (Exception e) {
e.printStackTrace();
}
return strText;
}
示例15: encodeFilename
import javax.mail.internet.MimeUtility; //导入方法依赖的package包/类
/**
* 设置下载文件中文件的名称
*
* @param filename 文件名
* @param request HttpServletRequest
* @return 结果
*/
public static String encodeFilename(String filename, HttpServletRequest request) {
// 获取客户端浏览器和操作系统信息
// 在IE浏览器中得到的是:User-Agent=Mozilla/4.0
// (compatible; MSIE 6.0; Windows NT 5.1; SV1; Maxthon; Alexa Toolbar)
// 在Firefox中得到的是:User-Agent=Mozilla/5.0
// (Windows; U; Windows NT 5.1; zh-CN; rv:1.7.10) Gecko/20050717 Firefox/1.0.6
String agent = request.getHeader("USER-AGENT");
try {
if ((agent != null) && (agent.contains("MSIE"))) {
String newFileName = URLEncoder.encode(filename, "UTF-8");
newFileName = FileNameEncodeHelper.replace(newFileName, "+", "%20");
if (newFileName.length() > 150) {
newFileName = new String(filename.getBytes("GB2312"), "ISO8859-1");
newFileName = FileNameEncodeHelper.replace(newFileName, " ", "%20");
}
return newFileName;
}
if ((agent != null) && (agent.contains("Mozilla"))) {
MimeUtility.encodeText(filename, "UTF-8", "B");
}
return filename;
} catch (Exception ex) {
return filename;
}
}