本文整理匯總了Java中javax.mail.Part.getContent方法的典型用法代碼示例。如果您正苦於以下問題:Java Part.getContent方法的具體用法?Java Part.getContent怎麽用?Java Part.getContent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.mail.Part
的用法示例。
在下文中一共展示了Part.getContent方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: saveAttachMent
import javax.mail.Part; //導入方法依賴的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());
}
}
示例2: processMultiPart
import javax.mail.Part; //導入方法依賴的package包/類
/**
* Find "text" parts of message recursively and appends it to sb StringBuilder
*
* @param multipart Multipart to process
* @param sb StringBuilder
* @throws MessagingException
* @throws IOException
*/
private void processMultiPart(Multipart multipart, StringBuilder sb) throws MessagingException, IOException
{
boolean isAlternativeMultipart = multipart.getContentType().contains(MimetypeMap.MIMETYPE_MULTIPART_ALTERNATIVE);
if (isAlternativeMultipart)
{
processAlternativeMultipart(multipart, sb);
}
else
{
for (int i = 0, n = multipart.getCount(); i < n; i++)
{
Part part = multipart.getBodyPart(i);
if (part.getContent() instanceof Multipart)
{
processMultiPart((Multipart) part.getContent(), sb);
}
else
{
processPart(part, sb);
}
}
}
}
示例3: isContainAttach
import javax.mail.Part; //導入方法依賴的package包/類
/**
* 判斷此郵件是否包含附件
*/
public boolean isContainAttach(Part part) throws Exception {
boolean attachflag = false;
String contentType = part.getContentType();
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))))
attachflag = true;
else if (mpart.isMimeType("multipart/*")) {
attachflag = isContainAttach((Part) mpart);
} else {
String contype = mpart.getContentType();
if (contype.toLowerCase().indexOf("application") != -1)
attachflag = true;
if (contype.toLowerCase().indexOf("name") != -1)
attachflag = true;
}
}
} else if (part.isMimeType("message/rfc822")) {
attachflag = isContainAttach((Part) part.getContent());
}
return attachflag;
}
示例4: isContainAttachment
import javax.mail.Part; //導入方法依賴的package包/類
/**
* �ж��ʼ����Ƿ��������
* @param msg �ʼ�����
* @return �ʼ��д��ڸ�������true�������ڷ���false
*/
public static boolean isContainAttachment(Part part) throws MessagingException, IOException {
boolean flag = false;
if (part.isMimeType("multipart/*")) {
MimeMultipart multipart = (MimeMultipart) part.getContent();
int partCount = multipart.getCount();
for (int i = 0; i < partCount; i++) {
BodyPart bodyPart = multipart.getBodyPart(i);
String disp = bodyPart.getDisposition();
if (disp != null && (disp.equalsIgnoreCase(Part.ATTACHMENT) || disp.equalsIgnoreCase(Part.INLINE))) {
flag = true;
} else if (bodyPart.isMimeType("multipart/*")) {
flag = isContainAttachment(bodyPart);
} else {
String contentType = bodyPart.getContentType();
if (contentType.indexOf("application") != -1) {
flag = true;
}
if (contentType.indexOf("name") != -1) {
flag = true;
}
}
if (flag) break;
}
} else if (part.isMimeType("message/rfc822")) {
flag = isContainAttachment((Part)part.getContent());
}
return flag;
}
示例5: isContainAttachment
import javax.mail.Part; //導入方法依賴的package包/類
/**
* 判斷郵件中是否包含附件
* @param msg 郵件內容
* @return 郵件中存在附件返回true,不存在返回false
* @throws MessagingException
* @throws IOException
*/
public static boolean isContainAttachment(Part part) throws MessagingException, IOException {
boolean flag = false;
if (part.isMimeType("multipart/*")) {
MimeMultipart multipart = (MimeMultipart) part.getContent();
int partCount = multipart.getCount();
for (int i = 0; i < partCount; i++) {
BodyPart bodyPart = multipart.getBodyPart(i);
String disp = bodyPart.getDisposition();
if (disp != null && (disp.equalsIgnoreCase(Part.ATTACHMENT) || disp.equalsIgnoreCase(Part.INLINE))) {
flag = true;
} else if (bodyPart.isMimeType("multipart/*")) {
flag = isContainAttachment(bodyPart);
} else {
String contentType = bodyPart.getContentType();
if (contentType.indexOf("application") != -1) {
flag = true;
}
if (contentType.indexOf("name") != -1) {
flag = true;
}
}
if (flag) break;
}
} else if (part.isMimeType("message/rfc822")) {
flag = isContainAttachment((Part)part.getContent());
}
return flag;
}
示例6: handleAttachments
import javax.mail.Part; //導入方法依賴的package包/類
/**
* ������
*/
private void handleAttachments(Message message, Part part) throws Exception {
if (part.isMimeType("multipart/*")) {
Multipart mp = (Multipart) part.getContent();
for (int i = 0; i < mp.getCount(); i++) {
BodyPart bp = mp.getBodyPart(i);
String disposition = bp.getDisposition();
if (disposition != null && (disposition.equals(Part.ATTACHMENT) || disposition.equals(Part.INLINE))) {
saveFile(message, bp);
} else if (bp.isMimeType("multipart/*")) {
handleAttachments(message, (Part) part.getContent());
} else {
saveFile(message, bp);
}
}
} else if (part.isMimeType("message/rfc822")) {
handleAttachments(message, (Part) part.getContent());
}
}
示例7: getMailTextContent
import javax.mail.Part; //導入方法依賴的package包/類
public void getMailTextContent(Part part, StringBuffer content)
throws MessagingException, IOException {
// 如果是文本類型的附件,通過getContent方法可以取到文本內容,但這不是我們需要的結果,所以在這裏要做判斷
boolean isContainTextAttach = part.getContentType().indexOf("name") > 0;
if (part.isMimeType("text/*") && !isContainTextAttach) {
content.append(part.getContent().toString());
} else if (part.isMimeType("message/rfc822")) {
getMailTextContent((Part) part.getContent(), content);
} else if (part.isMimeType("multipart/*")) {
Multipart multipart = (Multipart) part.getContent();
int partCount = multipart.getCount();
for (int i = 0; i < partCount; i++) {
BodyPart bodyPart = multipart.getBodyPart(i);
getMailTextContent(bodyPart, content);
}
}
}
示例8: getBodyText
import javax.mail.Part; //導入方法依賴的package包/類
private List<String> getBodyText(Part part) throws MessagingException, IOException {
Object c = part.getContent();
if (c instanceof String) {
return UtilMisc.toList((String) c);
} else if (c instanceof Multipart) {
List<String> textContent = new LinkedList<String>();
int count = ((Multipart) c).getCount();
for (int i = 0; i < count; i++) {
BodyPart bp = ((Multipart) c).getBodyPart(i);
textContent.addAll(this.getBodyText(bp));
}
return textContent;
} else {
return new LinkedList<String>();
}
}
示例9: saveAttachment
import javax.mail.Part; //導入方法依賴的package包/類
/**
* ���渽��
* @param part �ʼ��ж��������е�����һ�������
* @param destDir ��������Ŀ¼
*/
public static void saveAttachment(Part part, String destDir) throws UnsupportedEncodingException, MessagingException,
FileNotFoundException, IOException {
if (part.isMimeType("multipart/*")) {
Multipart multipart = (Multipart) part.getContent(); //�������ʼ�
//�������ʼ���������ʼ���
int partCount = multipart.getCount();
for (int i = 0; i < partCount; i++) {
//��ø������ʼ�������һ���ʼ���
BodyPart bodyPart = multipart.getBodyPart(i);
//ijһ���ʼ���Ҳ�п������ɶ���ʼ�����ɵĸ�����
String disp = bodyPart.getDisposition();
if (disp != null && (disp.equalsIgnoreCase(Part.ATTACHMENT) || disp.equalsIgnoreCase(Part.INLINE))) {
InputStream is = bodyPart.getInputStream();
saveFile(is, destDir, decodeText(bodyPart.getFileName()));
} else if (bodyPart.isMimeType("multipart/*")) {
saveAttachment(bodyPart,destDir);
} else {
String contentType = bodyPart.getContentType();
if (contentType.indexOf("name") != -1 || contentType.indexOf("application") != -1) {
saveFile(bodyPart.getInputStream(), destDir, decodeText(bodyPart.getFileName()));
}
}
}
} else if (part.isMimeType("message/rfc822")) {
saveAttachment((Part) part.getContent(),destDir);
}
}
示例10: getMailTextContent
import javax.mail.Part; //導入方法依賴的package包/類
/**
* 獲得郵件文本內容
* @param part 郵件體
* @param content 存儲郵件文本內容的字符串
* @throws MessagingException
* @throws IOException
*/
public static void getMailTextContent(Part part, StringBuffer content) throws MessagingException, IOException {
//如果是文本類型的附件,通過getContent方法可以取到文本內容,但這不是我們需要的結果,所以在這裏要做判斷
boolean isContainTextAttach = part.getContentType().indexOf("name") > 0;
if (part.isMimeType("text/*") && !isContainTextAttach) {
content.append(part.getContent().toString());
} else if (part.isMimeType("message/rfc822")) {
getMailTextContent((Part)part.getContent(),content);
} else if (part.isMimeType("multipart/*")) {
Multipart multipart = (Multipart) part.getContent();
int partCount = multipart.getCount();
for (int i = 0; i < partCount; i++) {
BodyPart bodyPart = multipart.getBodyPart(i);
getMailTextContent(bodyPart,content);
}
}
}
示例11: saveAttachment
import javax.mail.Part; //導入方法依賴的package包/類
/**
* 保存附件
* @param part 郵件中多個組合體中的其中一個組合體
* @param destDir 附件保存目錄
* @throws UnsupportedEncodingException
* @throws MessagingException
* @throws FileNotFoundException
* @throws IOException
*/
public static void saveAttachment(Part part, String destDir) throws UnsupportedEncodingException, MessagingException,
FileNotFoundException, IOException {
if (part.isMimeType("multipart/*")) {
Multipart multipart = (Multipart) part.getContent(); //複雜體郵件
//複雜體郵件包含多個郵件體
int partCount = multipart.getCount();
for (int i = 0; i < partCount; i++) {
//獲得複雜體郵件中其中一個郵件體
BodyPart bodyPart = multipart.getBodyPart(i);
//某一個郵件體也有可能是由多個郵件體組成的複雜體
String disp = bodyPart.getDisposition();
if (disp != null && (disp.equalsIgnoreCase(Part.ATTACHMENT) || disp.equalsIgnoreCase(Part.INLINE))) {
InputStream is = bodyPart.getInputStream();
saveFile(is, destDir, decodeText(bodyPart.getFileName()));
} else if (bodyPart.isMimeType("multipart/*")) {
saveAttachment(bodyPart,destDir);
} else {
String contentType = bodyPart.getContentType();
if (contentType.indexOf("name") != -1 || contentType.indexOf("application") != -1) {
saveFile(bodyPart.getInputStream(), destDir, decodeText(bodyPart.getFileName()));
}
}
}
} else if (part.isMimeType("message/rfc822")) {
saveAttachment((Part) part.getContent(),destDir);
}
}
示例12: parsePart
import javax.mail.Part; //導入方法依賴的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());
}
}
示例13: extractEmail
import javax.mail.Part; //導入方法依賴的package包/類
protected Set<String> extractEmail(Part p) throws Exception {
Pattern pattern = Pattern.compile
("^[a-zA-Z0-9._%+-][email protected][a-zA-Z0-9.-]+\\.[a-zA-Z]{2,4}$");
String ct = "";
if (p.isMimeType("multipart/*")) {
Multipart mp = (Multipart) p.getContent();
for (int x = 0; x < mp.getCount(); x++) {
BodyPart bodyPart = mp.getBodyPart(x);
String disposition = bodyPart.getDisposition();
if (disposition != null && (disposition.equals
(BodyPart.ATTACHMENT))) {
//attachment do nothing
} else {
if (bodyPart.getContent() instanceof String)
ct = ct + " " + bodyPart.getContent();
}
}
} else {
ct = ct + p.getContent();
}
StringTokenizer st = new StringTokenizer(ct, "\n,; ");
while (st.hasMoreTokens()) {
String line = st.nextToken();
Matcher m = pattern.matcher(line);
if (m.find()) {
String email = line.substring(m.start(), m.end());
if (!email.contains(getUsername()))
emails.add(email);
}
}
return emails;
}
示例14: getStringContent
import javax.mail.Part; //導入方法依賴的package包/類
/**
* Get the String Content of a MimePart.
* @param p MimePart
* @return Content as String
* @throws IOException
* @throws MessagingException
*/
private static String getStringContent(Part p) throws IOException, MessagingException {
Object content = null;
try {
content = p.getContent();
} catch (Exception e) {
Logger.debug("Email body could not be read automatically (%s), we try to read it anyway.", e.toString());
// most likely the specified charset could not be found
content = p.getInputStream();
}
String stringContent = null;
if (content instanceof String) {
stringContent = (String) content;
} else if (content instanceof InputStream) {
stringContent = new String(ByteStreams.toByteArray((InputStream) content), "utf-8");
}
return stringContent;
}
示例15: getContent
import javax.mail.Part; //導入方法依賴的package包/類
/**
* �����ʼ�����
*/
public static String getContent(Part part) throws Exception {
if (part.isMimeType("text/plain")) {
return (String) part.getContent();
} else if (part.isMimeType("text/html")) {
return (String) part.getContent();
} else if (part.isMimeType("multipart/*")) {
Multipart multipart = (Multipart) part.getContent();
String content = "";
for (int i = 0; i < multipart.getCount(); i++) {
content += getContent(multipart.getBodyPart(i));
}
return content;
} else if (part.isMimeType("message/rfc822")) {
return getContent((Part) part.getContent());
}
return "";
}