本文整理汇总了Java中javax.mail.internet.MimeUtility.encodeWord方法的典型用法代码示例。如果您正苦于以下问题:Java MimeUtility.encodeWord方法的具体用法?Java MimeUtility.encodeWord怎么用?Java MimeUtility.encodeWord使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.mail.internet.MimeUtility
的用法示例。
在下文中一共展示了MimeUtility.encodeWord方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setHeaderFileName
import javax.mail.internet.MimeUtility; //导入方法依赖的package包/类
/**
* ダウンロード対象ファイル名を、User-Agentに応じたエンコードを行いレスポンスヘッダに設定する.
* <ul>
* <li>IEで正常にファイル名が表示・ダウンロードできることを第一とする</li>
* <li>User-Agentの偽装は考慮しない</li>
* <li>ファイル名の長さが256バイトを越える場合、ダウンロードしたファイルを開けない場合があるがここでは考慮しない</li>
* </ul>
* @param request リクエスト情報
* @param response レスポンス情報
* @param fileName ダウンロードするファイル名
*/
private void setHeaderFileName(HttpServletRequest request,
HttpServletResponse response,
String fileName,
boolean downloadByRealFileName) {
String headerFileName;
String userAgent = request.getHeader("User-Agent");
try {
if (userAgent.indexOf("MSIE") != -1) {
// IEで認識可能な文字エンコーディングに変換したファイル名を設定
String enc = SystemConfig.getValue(KEY_DOWNLOAD_HEADER_FILENAME_ENCODING);
headerFileName = new String(fileName.getBytes(enc), "iso-8859-1");
// 以下コードでも文字化けは起こらないが
// URLエンコードした名前 + 保存先パス名が256byteを越える可能性が大きいので
// 採用しない
// headerFileName = URLEncoder.encode(fileName, "UTF-8");
} else {
// その他のブラウザであればMIMEエンコードしたファイル名を設定
// see RFC2231
headerFileName = MimeUtility.encodeWord(fileName, "ISO-2022-JP", "B");
}
// SpreadsheetMLをExcel 2007で開くと拡張子偽装の警告が出るので
// *.xmlに変更
if (!downloadByRealFileName && headerFileName.endsWith(".xls")) {
headerFileName = headerFileName.replaceAll("\\.xls$", ".xml");
}
response.addHeader("Content-Disposition",
"attachment; filename=\"" + headerFileName + "\"");
} catch (UnsupportedEncodingException ignore) {
log.warn(
String.format("failed to set filename to response header. %s", fileName),
ignore);
}
}
示例2: setPersonal
import javax.mail.internet.MimeUtility; //导入方法依赖的package包/类
public void setPersonal(String name, String charset, String encoding) throws UnsupportedEncodingException {
this.personal = name;
if (name != null) {
this.encodedPersonal = MimeUtility.encodeWord(name, charset, encoding);
} else {
this.encodedPersonal = null;
}
}
示例3: createEncodeAction
import javax.mail.internet.MimeUtility; //导入方法依赖的package包/类
private ActionListener createEncodeAction() {
return new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
try {
String encodeText = MimeUtility.encodeWord(StringUtils.defaultIfEmpty(Rfc2074Dialog.this.decodeTextArea.getText(), ""), StringUtils.defaultIfBlank(Rfc2074Dialog.this.charsetField.getText(), "UTF-8"), (String) Rfc2074Dialog.this.encodingOptionBox.getSelectedItem());
Rfc2074Dialog.this.encodeTextArea.setText(encodeText);
} catch (Throwable e) {
JOptionPane.showMessageDialog(Rfc2074Dialog.this, e.getClass().getSimpleName() + " - " + e.getMessage(), "Encoding fail !", JOptionPane.ERROR_MESSAGE);
}
}
};
}
示例4: buildContentPart
import javax.mail.internet.MimeUtility; //导入方法依赖的package包/类
@Override
public Object buildContentPart() throws Throwable {
MimeBodyPart part = new MimeBodyPart();
File file = new File(this.pathField.getText());
part.attachFile(file);
String typeAppendText = "";
EncodingTextData typeNameData = dispositionFilenamePanel.getEncodingTextData();
if (typeNameData.isUse()) {
String encodedTypeName = MimeUtility.encodeWord(StringUtils.defaultString(typeNameData.getText(), file.getName()), StringUtils.defaultString(typeNameData.getCharset(), "UTF-8"), typeNameData.getEncoding());
typeAppendText += "; name=\"" + encodedTypeName + "\"";
}
String dispositionAppendText = "";
EncodingTextData dispositionFilenameData = dispositionFilenamePanel.getEncodingTextData();
if (dispositionFilenameData.isUse()) {
String encodedDispositionFilename = MimeUtility.encodeWord(StringUtils.defaultString(dispositionFilenameData.getText(), file.getName()), StringUtils.defaultString(dispositionFilenameData.getCharset(), "UTF-8"), dispositionFilenameData.getEncoding());
dispositionAppendText += "; filename=\"" + encodedDispositionFilename + "\"";
}
part.setHeader("Content-Type", this.typeField.getText() + typeAppendText);
part.setHeader("Content-Disposition", this.dispositionOptionBox.getSelectedItem() + dispositionAppendText);
part.setHeader("Content-Transfer-Encoding", (String) this.transferOptionBox.getSelectedItem());
if (this.contentIdUseCheckBox.isSelected()) {
String contentId = this.contentIdField.getText();
if (StringUtils.isNotBlank(contentId)) {
part.setContentID("<" + contentId + ">");
}
}
return part;
}
示例5: testSetPersonal_case2
import javax.mail.internet.MimeUtility; //导入方法依赖的package包/类
@Test
public void testSetPersonal_case2() throws Exception {
String addr = "[email protected]";
String personal = "가나다";
AdvancedInternetAddress address = new AdvancedInternetAddress(addr, personal, "UTF-8", "B");
String result = address.toString();
log.info(result);
String encodedPersonal = MimeUtility.encodeWord(personal, "UTF-8", "B");
String expectedAddressStr = encodedPersonal + " <" + addr + ">";
Assert.assertEquals(expectedAddressStr, result);
}
示例6: encodeText
import javax.mail.internet.MimeUtility; //导入方法依赖的package包/类
/**
* Encode text into MIME with encoding.
* @param text Text
* @param charset Text charset
* @return Encoded text
* @throws UnsupportedEncodingException if fail
*/
private static String encodeText(
final String text,
final String charset
) throws UnsupportedEncodingException {
final String encoded = MimeUtility.encodeWord(text, charset, null);
final int last = encoded.lastIndexOf('?');
final int prev = encoded.lastIndexOf('?', last - 1);
return encoded.substring(prev + 1, last);
}
示例7: IhaveReplayTest
import javax.mail.internet.MimeUtility; //导入方法依赖的package包/类
@Test
public void IhaveReplayTest() throws StorageBackendException, IOException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, ParseException{
Config.inst().set(Config.HOSTNAME, "not-in-path.com"); //added to path
ArticleOutput art0 = Mockito.mock(ArticleOutput.class);//empty
when(storage.getArticle("<[email protected]>", null, 1)).thenReturn(art0);
when(art0.getId()).thenReturn( 105 );
when(art0.getThread_id()).thenReturn( 105 );
Set<String> host = new HashSet<String>(Arrays.asList("hschan.ano","host.com"));
//name id flags hosts
when(StorageManager.groups.get("local.test")).thenReturn(
(Group) groupC.newInstance("local.test",23,0,host));
String send1 = "ihave <[email protected]>";
String[] send2 = {
"Mime-Version: 1.0",
"From: "+MimeUtility.encodeWord("петрик <[email protected]>"),
"Date: Thu, 02 May 2013 12:16:44 +0000",
"Message-ID: <[email protected]>",
"Newsgroups: local.test",
"Subject: "+MimeUtility.encodeWord("ыффывфыв фыв фыв фыв фыв фыв фыв фыв фыв фыв фыв фы"),
"references: <[email protected]>",
"Path: hschan.ano!dontcare", //circle check
"Content-type: text/plain; charset=utf-8",
"X-Sage: optional",
"",//empty line separator
"message"
};
//String send3 = "bWVzc2FnZQ==";
IhaveCommand c = new IhaveCommand();
c.processLine(conn, send1, send1.getBytes("UTF-8")); //send ihave
verify(this.storage).getArticle("<[email protected]>", null, 1); //ReceivingService there is no such article yet
verify(conn, atLeastOnce()).println(startsWith("335")); //Send article
for(int i = 0; i < send2.length; i++)
c.processLine(conn, send2[i], send2[i].getBytes("UTF-8")); //headers
c.processLine(conn, ".", ".".getBytes("UTF-8")); //the end
//Article art = new Article(thread_id, mId[0], mId[1], from, subjectT, message,
//date[0], path[0], groupHeader[0], group.getInternalID());
ArticleInput art = ArticleFactory.crAInput(105, "<[email protected]>", "host.com", "петрик <[email protected]>", "ыффывфыв фыв фыв фыв фыв фыв фыв фыв фыв фыв фыв фы", "message",
Headers.ParseRawDate("Thu, 02 May 2013 12:16:44 +0000"), "hschan.ano!dontcare", "local.test", 23, 0, null, null);
verify(this.storage, atLeastOnce()).createReplay(art, null); //ReceivingService here
verify(conn, atLeastOnce()).println(startsWith("235")); //article is accepted
}
示例8: TakeThisReplayTest
import javax.mail.internet.MimeUtility; //导入方法依赖的package包/类
@Test
public void TakeThisReplayTest() throws StorageBackendException, IOException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, ParseException{
File t = File.createTempFile("test", null);
t.deleteOnExit();
when(cache.createTMPfile(Mockito.anyString())).thenReturn(t);
Config.inst().set(Config.HOSTNAME, "not-in-path.com"); //added to path
ArticleOutput art0 = Mockito.mock(ArticleOutput.class);//empty
//when(storage.getArticle("<[email protected]>", null)).thenReturn(art0);//ref
when(storage.getArticle("<[email protected]>", null, 1)).thenReturn(art0);//ref
when(art0.getId()).thenReturn( 105 );
when(art0.getThread_id()).thenReturn( 105 );
Set<String> host = new HashSet<String>(Arrays.asList("hschan.ano","host.com"));
//name id flags hosts
when(StorageManager.groups.get("local.test")).thenReturn(
(Group) groupC.newInstance("local.test",23,0,host));
String send1 = "takethis <[email protected]>";
String[] send2 = {
"Mime-Version: 1.0",
"From: "+MimeUtility.encodeWord("петрик <[email protected]>"),
"Date: Thu, 02 May 2013 12:16:44 +0000",
"Message-ID: <[email protected]>",
"Newsgroups: local.test",
"Subject: "+MimeUtility.encodeWord("ыффывфыв фыв фыв фыв фыв фыв фыв фыв фыв фыв фыв фы ыффывфыв фыв фыв фыв фыв фыв фыв фыв фыв фыв фыв фы"),
"references: <[email protected]>",
"Path: hschan.ano!dontcare",
"Content-type: text/plain; charset=utf-8",
"X-Sage: optional",
"",//empty line separator
"message"
};
TakeThisCommand c = new TakeThisCommand();
c.processLine(conn, send1, send1.getBytes("UTF-8")); //send ihave
verify(this.storage).getArticle("<[email protected]>", null, 1); //ReceivingService there is no such article yet
for(int i = 0; i < send2.length; i++)
c.processLine(conn, send2[i], send2[i].getBytes("UTF-8")); //headers
c.processLine(conn, ".", ".".getBytes("UTF-8")); //the end
//Article art = new Article(thread_id, mId[0], mId[1], from, subjectT, message,
//date[0], path[0], groupHeader[0], group.getInternalID());
ArticleInput art = ArticleFactory.crAInput(105, "<[email protected]>", "host.com", "петрик <[email protected]>", "ыффывфыв фыв фыв фыв фыв фыв фыв фыв фыв фыв фыв фы ыффывфыв фыв фыв фыв фыв фыв фыв фыв фыв фыв фыв фы", "message",
Headers.ParseRawDate("Thu, 02 May 2013 12:16:44 +0000"), "hschan.ano!dontcare", "local.test", 23, 0, null, null);
verify(this.storage, atLeastOnce()).createReplay(art, null); //ReceivingService here
verify(conn, atLeastOnce()).println(startsWith("239")); //article is accepted
}
示例9: encodeSubject
import javax.mail.internet.MimeUtility; //导入方法依赖的package包/类
public String encodeSubject() throws UnsupportedEncodingException {
return MimeUtility.encodeWord(StringUtils.defaultString(this.text, ""), StringUtils.defaultString(this.charset, "UTF-8"), StringUtils.defaultString(this.encoding, "B"));
}