本文整理汇总了Java中javax.mail.BodyPart.isMimeType方法的典型用法代码示例。如果您正苦于以下问题:Java BodyPart.isMimeType方法的具体用法?Java BodyPart.isMimeType怎么用?Java BodyPart.isMimeType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.mail.BodyPart
的用法示例。
在下文中一共展示了BodyPart.isMimeType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTextFromMimeMultipart
import javax.mail.BodyPart; //导入方法依赖的package包/类
/**
* Extracts the text content of a multipart email message
*/
private String getTextFromMimeMultipart(MimeMultipart mimeMultipart) throws Exception {
String result = "";
int partCount = mimeMultipart.getCount();
for (int i = 0; i < partCount; i++) {
BodyPart bodyPart = mimeMultipart.getBodyPart(i);
if (bodyPart.isMimeType("text/plain")) {
result = result + "\n" + bodyPart.getContent();
break; // without break same text appears twice in my tests
} else if (bodyPart.isMimeType("text/html")) {
String html = (String) bodyPart.getContent();
// result = result + "\n" + org.jsoup.Jsoup.parse(html).text();
result = html;
} else if (bodyPart.getContent() instanceof MimeMultipart) {
result = result + getTextFromMimeMultipart((MimeMultipart) bodyPart.getContent());
}
}
return result;
}
示例2: saveAttachMent
import javax.mail.BodyPart; //导入方法依赖的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.BodyPart; //导入方法依赖的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.BodyPart; //导入方法依赖的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.BodyPart; //导入方法依赖的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.BodyPart; //导入方法依赖的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: saveAttachment
import javax.mail.BodyPart; //导入方法依赖的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);
}
}
示例8: saveAttachment
import javax.mail.BodyPart; //导入方法依赖的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);
}
}
示例9: getTextFromMimeMultipart
import javax.mail.BodyPart; //导入方法依赖的package包/类
private String getTextFromMimeMultipart(MimeMultipart mimeMultipart)
throws MessagingException, IOException {
StringBuilder result = new StringBuilder();
int count = mimeMultipart.getCount();
for (int i = 0; i < count; i++) {
BodyPart bodyPart = mimeMultipart.getBodyPart(i);
if (bodyPart.isMimeType("text/plain")) {
result.append("\n").append(bodyPart.getContent());
} else if (bodyPart.isMimeType("text/html")) {
result.append("\n").append((String) bodyPart.getContent());
} else if (bodyPart.getContent() instanceof MimeMultipart) {
result.append(getTextFromMimeMultipart((MimeMultipart) bodyPart.getContent()));
}
}
return result.toString();
}
示例10: getTextFromMultiPartAlternative
import javax.mail.BodyPart; //导入方法依赖的package包/类
/**
* Returns the text from multipart/alternative, the type of text returned follows the preference of the sending agent.
*/
private static String getTextFromMultiPartAlternative(Multipart multipart) throws IOException, MessagingException {
// search in reverse order as a multipart/alternative should have their most preferred format last
for (int i = multipart.getCount() - 1; i >= 0; i--) {
BodyPart bodyPart = multipart.getBodyPart(i);
if (bodyPart.isMimeType("text/html")) {
return (String) bodyPart.getContent();
} else if (bodyPart.isMimeType("text/plain")) {
// Since we are looking in reverse order, if we did not encounter a text/html first we can return the plain
// text because that is the best preferred format that we understand. If a text/html comes along later it
// means the agent sending the email did not set the html text as preferable or did not set their preferred
// order correctly, and in that case we do not handle that.
return (String) bodyPart.getContent();
} else if (bodyPart.isMimeType("multipart/*") || bodyPart.isMimeType("message/rfc822")) {
String text = getTextFromPart(bodyPart);
if (text != null) {
return text;
}
}
}
// we do not know how to handle the text in the multipart or there is no text
return null;
}
示例11: isMultipartValid
import javax.mail.BodyPart; //导入方法依赖的package包/类
private boolean isMultipartValid(Message message) throws MessagingException, IOException {
boolean retvalue = false;
Multipart multipart = (Multipart)message.getContent();
int count = multipart.getCount();
for(int i = 0; i < count; i++) {
BodyPart part = multipart.getBodyPart(i);
if(part.isMimeType("text/plain")) {
retvalue = true;
}
}
return retvalue;
}
示例12: getContent
import javax.mail.BodyPart; //导入方法依赖的package包/类
private String getContent(Message message) throws IOException, MessagingException {
String retvalue = "";
Object msgContent = message.getContent();
if(msgContent instanceof Multipart) {
Multipart multipart = (Multipart)message.getContent();
int count = multipart.getCount();
for(int i = 0; i < count; i++) {
BodyPart part = multipart.getBodyPart(i);
if(part.isMimeType("text/plain")) {
retvalue += "Part" + i + ": " + part.getContent().toString();
}
}
} else {
retvalue = msgContent.toString();
}
return retvalue;
}
示例13: extractAttachmentFromOriginalMime
import javax.mail.BodyPart; //导入方法依赖的package包/类
private List<BodyPart> extractAttachmentFromOriginalMime(MimeMessage mimeMessage, int inviteId) throws MessagingException, IOException
{
MimeMultipart mimeMultipart = (MimeMultipart)mimeMessage.getContent();
MimeMessage subMimeMessage = (MimeMessage)mimeMultipart.getBodyPart(0).getContent();
for (int n = 0; n < mimeMultipart.getCount(); ++n)
{
BodyPart part = mimeMultipart.getBodyPart(n);
String[] headerInvId = part.getHeader("invId");
if (headerInvId != null && headerInvId.length > 0 && headerInvId[0].equals(String.valueOf(inviteId)))
{
subMimeMessage = (MimeMessage) part.getContent();
}
}
MimeMultipart subMultipart = (MimeMultipart)subMimeMessage.getContent();
List<BodyPart> bodyPartList = new LinkedList<BodyPart>();
for( int n=0; n < subMultipart.getCount(); ++n )
{
BodyPart bodyPart = subMultipart.getBodyPart(n);
boolean isAttachment = false;
String contentDispositions = bodyPart.getDisposition();
if( contentDispositions != null && contentDispositions.equals(Part.ATTACHMENT) )
{
isAttachment = true;
}
if( bodyPart.isMimeType("application/*") || bodyPart.isMimeType("image/*") )
{
isAttachment = true;
}
if( isAttachment )
{
bodyPartList.add(bodyPart);
}
}
return bodyPartList;
}
示例14: save
import javax.mail.BodyPart; //导入方法依赖的package包/类
private void save(Store store, String wheretobackup, String f) throws MessagingException, IOException {
System.out.println("opening folder " + f);
Folder folder = store.getFolder(f);
folder.open(Folder.READ_ONLY);
FileUtils.forceMkdir(new File(wheretobackup));
// Get directory
Message message[] = folder.getMessages();
for (int i = 0, n = message.length; i < n; i++) {
// String from = (message[i].getFrom()[0]).toString();
String subj = (message[i].getSubject()).toString();
String nota = (message[i].getContent()).toString();
if (message[i].getContent() instanceof MimeMultipart) {
MimeMultipart multipart = (MimeMultipart) message[i].getContent();
for (int j = 0; j < multipart.getCount(); j++) {
BodyPart bodyPart = multipart.getBodyPart(j);
if (bodyPart.isMimeType("text/html")) {
nota = bodyPart.getContent().toString();
generals.writeFile(wheretobackup + "/" + generals.makeFilename(subj).trim() + ".html", nota, message[i].getSentDate());
} else if (bodyPart.isMimeType("IMAGE/PNG")) {
String imagecid = ((MimePart) bodyPart).getContentID();
InputStream is = bodyPart.getInputStream();
FileUtils.forceMkdir(new File(wheretobackup + "/images/"));
File fimg = new File(wheretobackup + "/images/" + bodyPart.getFileName());
System.out.println("saving " + wheretobackup + "/images/" + bodyPart.getFileName());
FileOutputStream fos = new FileOutputStream(fimg);
byte[] buf = new byte[4096];
int bytesRead;
while((bytesRead = is.read(buf))!=-1) {
fos.write(buf, 0, bytesRead);
}
fos.close();
// devi fare il replace 0DA094B7-933A-4B19-947F-2FC42FA9DABD
System.out.println("html replace file name : " + imagecid);
System.out.println("into file name : " + bodyPart .getFileName());
}
}
} else {
generals.writeFile(wheretobackup + "/" + generals.makeFilename(subj).trim() + ".html", nota, message[i].getSentDate());
}
}
folder.close(false);
}
示例15: getText
import javax.mail.BodyPart; //导入方法依赖的package包/类
/**
* Attempts to reteive the string portion of a message... tries to handle
* multipart messages as well. This seems to be working so far with my tests
* but could use some tweaking later as more types of mail servers are used
* with this feature.
*
* @param msg a {@link javax.mail.Message} object.
* @return The text portion of an email with each line being an element of the list.
* @throws javax.mail.MessagingException if any.
* @throws java.io.IOException if any.
*/
public static List<String> getText(Message msg) throws MessagingException, IOException {
Object content = null;
String text = null;
log().debug("getText: getting text of message from MimeType: text/*");
try {
text = (String)msg.getContent();
} catch (ClassCastException cce) {
content = msg.getContent();
if (content instanceof MimeMultipart) {
log().debug("getText: content is MimeMultipart, checking for text from each part...");
for (int cnt = 0; cnt < ((MimeMultipart)content).getCount(); cnt++) {
BodyPart bp = ((MimeMultipart)content).getBodyPart(cnt);
if (bp.isMimeType("text/*")) {
text = (String)bp.getContent();
log().debug("getText: found text MIME type: "+text);
break;
}
}
log().debug("getText: did not find text within MimeMultipart message.");
}
}
return string2Lines(text);
}