本文整理汇总了Java中javax.mail.Part.isMimeType方法的典型用法代码示例。如果您正苦于以下问题:Java Part.isMimeType方法的具体用法?Java Part.isMimeType怎么用?Java Part.isMimeType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.mail.Part
的用法示例。
在下文中一共展示了Part.isMimeType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getMessageContent
import javax.mail.Part; //导入方法依赖的package包/类
/**
* Get the content of a mail message.
*
* @param message
* the mail message
* @return the content of the mail message
*/
private String getMessageContent(Message message) throws MessagingException {
try {
Object content = message.getContent();
if (content instanceof Multipart) {
StringBuffer messageContent = new StringBuffer();
Multipart multipart = (Multipart) content;
for (int i = 0; i < multipart.getCount(); i++) {
Part part = multipart.getBodyPart(i);
if (part.isMimeType("text/plain")) {
messageContent.append(part.getContent().toString());
}
}
return messageContent.toString();
}
return content.toString();
} catch (IOException e) {
e.printStackTrace();
}
return "";
}
示例2: 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());
}
}
示例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: 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);
}
}
示例9: 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);
}
}
}
示例10: 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);
}
}
示例11: 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());
}
}
示例12: 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;
}
示例13: 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 "";
}
示例14: getMainTextPart
import javax.mail.Part; //导入方法依赖的package包/类
/**
* Returns the <code>Part</code> whose <code>content</code>
* should be displayed inline.
* @throws MessagingException
* @throws IOException
*/
private Part getMainTextPart() throws MessagingException, IOException {
List<Part> parts = getParts();
Part mostPreferable = this;
for (Part part: parts) {
String disposition = part.getDisposition();
if (!Part.ATTACHMENT.equalsIgnoreCase(disposition)) {
// prefer plain text
if (part.isMimeType("text/plain"))
return part;
else if (part.isMimeType("text/html"))
mostPreferable = part;
}
}
return mostPreferable;
}
示例15: getPlainTextMessage
import javax.mail.Part; //导入方法依赖的package包/类
private String getPlainTextMessage(Part part) throws MessagingException, IOException
{
if (part.isMimeType("text/plain"))
{
return (String) part.getContent();
}
else if (part.isMimeType("multipart/*"))
{
Multipart multi = (Multipart) part;
for (int i = 0 ; i < multi.getCount(); i++)
{
Part subPart = multi.getBodyPart(i);
String text = getPlainTextMessage(subPart);
if (text != null) return text;
}
}
return null;
}