本文整理汇总了Java中javax.mail.BodyPart.getDisposition方法的典型用法代码示例。如果您正苦于以下问题:Java BodyPart.getDisposition方法的具体用法?Java BodyPart.getDisposition怎么用?Java BodyPart.getDisposition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.mail.BodyPart
的用法示例。
在下文中一共展示了BodyPart.getDisposition方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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());
}
}
示例2: 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;
}
示例3: 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;
}
示例4: 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;
}
示例5: 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());
}
}
示例6: getBodyIfNotAttachment
import javax.mail.BodyPart; //导入方法依赖的package包/类
/**
* Check if the body is from the content type and returns it if not attachment
*
* @param mimePart
* @param contentType
* @return null if not with specific content type or part is attachment
*/
private String getBodyIfNotAttachment(
BodyPart mimePart,
String contentType ) throws MessagingException, IOException {
String mimePartContentType = mimePart.getContentType().toLowerCase();
if (mimePartContentType.startsWith(contentType)) { // found a part with given mime type
String contentDisposition = mimePart.getDisposition();
if (!Part.ATTACHMENT.equalsIgnoreCase(contentDisposition)) {
Object partContent = mimePart.getContent();
if (partContent instanceof InputStream) {
return IoUtils.streamToString((InputStream) partContent);
} else {
return partContent.toString();
}
}
}
return null;
}
示例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: extractEmail
import javax.mail.BodyPart; //导入方法依赖的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;
}
示例10: getContent
import javax.mail.BodyPart; //导入方法依赖的package包/类
public static String getContent(Part message) throws MessagingException,
IOException {
if (message.getContent() instanceof String) {
return message.getContentType() + ": " + message.getContent() + " \n\t";
} else if (message.getContent() != null && message.getContent() instanceof Multipart) {
Multipart part = (Multipart) message.getContent();
String text = "";
for (int i = 0; i < part.getCount(); i++) {
BodyPart bodyPart = part.getBodyPart(i);
if (!Message.ATTACHMENT.equals(bodyPart.getDisposition())) {
text += getContent(bodyPart);
} else {
text += "attachment: \n" +
"\t\t name: " + (StringUtils.isEmpty(bodyPart.getFileName()) ? "none"
: bodyPart.getFileName()) + "\n" +
"\t\t disposition: " + bodyPart.getDisposition() + "\n" +
"\t\t description: " + (StringUtils.isEmpty(bodyPart.getDescription()) ? "none"
: bodyPart.getDescription()) + "\n\t";
}
}
return text;
}
if (message.getContent() != null && message.getContent() instanceof Part) {
if (!Message.ATTACHMENT.equals(message.getDisposition())) {
return getContent((Part) message.getContent());
} else {
return "attachment: \n" +
"\t\t name: " + (StringUtils.isEmpty(message.getFileName()) ? "none"
: message.getFileName()) + "\n" +
"\t\t disposition: " + message.getDisposition() + "\n" +
"\t\t description: " + (StringUtils.isEmpty(message.getDescription()) ? "none"
: message.getDescription()) + "\n\t";
}
}
return "";
}
示例11: getBodyText
import javax.mail.BodyPart; //导入方法依赖的package包/类
private String getBodyText(BodyPart bodyPart) {
Object content;
String disposition;
String bodyText = null;
try {
content = bodyPart.getContent();
disposition = bodyPart.getDisposition();
if (content instanceof String
&& disposition.toLowerCase().contains(
CONTENT_DISPOSITION_INLINE)) {
return (String) bodyText;
}
} catch (Exception e) {
logger.error(e);
return "";
}
return bodyText;
}
示例12: receiveEmailPOPAndroid
import javax.mail.BodyPart; //导入方法依赖的package包/类
public static void receiveEmailPOPAndroid(MailProfile mailprofile, String folder, int offset, int limit) throws Exception{
Properties props = new Properties();
props.setProperty("mail.store.protocol", "pop3");
props.put("mail.pop3.port", mailprofile.getPop3Port());
props.setProperty("mail.pop3.socketFactory.class",
"javax.net.ssl.SSLSocketFactory");
props.setProperty("mail.pop3.socketFactory.fallback",
"false");
props.setProperty("mail.pop3.port", "" + mailprofile.getPop3Port());
props.setProperty("mail.pop3.socketFactory.port", ""
+ mailprofile.getPop3Port());
Session session = Session.getInstance(props, null);
Store store = session.getStore();
store.connect(mailprofile.getPop3Host(), mailprofile.getEmail(), mailprofile.getPassword());
Folder inbox = store.getFolder(folder);
inbox.open(Folder.READ_ONLY);
if(limit > inbox.getMessageCount()) limit = inbox.getMessageCount()-1;
javax.mail.Message[] msg = inbox.getMessages(inbox.getMessageCount()-offset-limit, inbox.getMessageCount()-offset);
String content = null;
javax.mail.Message m;
try{
for(int i=msg.length-1; i >= 0; i--){
m = msg[i];
Object msgContent = m.getContent();
if (msgContent instanceof Multipart) {
Multipart multipart = (Multipart) msgContent;
for (int j = 0; j < multipart.getCount(); j++) {
BodyPart bodyPart = multipart.getBodyPart(j);
String disposition = bodyPart.getDisposition();
if (disposition != null && (disposition.equalsIgnoreCase("ATTACHMENT"))) {
DataHandler handler = bodyPart.getDataHandler();
}
else {
if(bodyPart instanceof IMAPBodyPart){
content = ((IMAPBodyPart)bodyPart).getContent().toString(); // the changed code
if(((IMAPBodyPart)bodyPart).getContent() instanceof MimeMultipart){
Multipart multi2 = (Multipart) ((IMAPBodyPart)bodyPart).getContent();
for (int k = 0; k < multi2.getCount(); k++)
content =multi2.getBodyPart(k).getContent().toString();
}
}
}
}
}
else
content= m.getContent().toString();
if(m.getContentType().startsWith("com.sun.mail.util.BASE64DecoderStream"))
content = ((BASE64DecoderStream) m.getContent()).toString();
mailprofile.addReceivedMessage(
new Email(
MimeUtility.decodeText(m.getFrom()[0].toString()),
MimeUtility.decodeText(m.getAllRecipients()[0].toString()),
MimeUtility.decodeText(m.getSubject()), m.getReceivedDate(),
content,
new ArrayList<File>()
)
);
}
} catch(Exception e){}
finally{
if(inbox != null)
inbox.close(true);
if(store != null)
store.close();
}
}
示例13: receiveEmailIMAPAndroid
import javax.mail.BodyPart; //导入方法依赖的package包/类
public static void receiveEmailIMAPAndroid(MailProfile mailprofile, String folder, int offset, int limit) throws Exception{
Properties props = new Properties();
props.setProperty("mail.store.protocol", "imaps");
props.put("mail.imap.port", mailprofile.getImapPort());
props.setProperty("mail.imap.socketFactory.class",
"javax.net.ssl.SSLSocketFactory");
props.setProperty("mail.imap.socketFactory.fallback",
"false");
props.setProperty("mail.imap.port", "" + mailprofile.getImapPort());
props.setProperty("mail.imap.socketFactory.port", ""
+ mailprofile.getImapPort());
Session session = Session.getInstance(props, null);
Store store = session.getStore();
store.connect(mailprofile.getImapHost(), mailprofile.getEmail(), mailprofile.getPassword());
Folder inbox = store.getFolder(folder);
inbox.open(Folder.READ_ONLY);
if(limit > inbox.getMessageCount()) limit = inbox.getMessageCount()-1;
javax.mail.Message[] msg = inbox.getMessages(inbox.getMessageCount()-offset-limit, inbox.getMessageCount()-offset);
String content;
javax.mail.Message m;
try{
for(int i=msg.length-1; i >= 0; i--){
m = msg[i];
content = m.getContent().toString();
Object msgContent = m.getContent();
if (msgContent instanceof Multipart) {
Multipart multipart = (Multipart) msgContent;
for (int j = 0; j < multipart.getCount(); j++) {
BodyPart bodyPart = multipart.getBodyPart(j);
String disposition = bodyPart.getDisposition();
if (disposition != null && (disposition.equalsIgnoreCase("ATTACHMENT"))) {
DataHandler handler = bodyPart.getDataHandler();
}
else {
if(bodyPart instanceof IMAPBodyPart){
content = ((IMAPBodyPart)bodyPart).getContent().toString(); // the changed code
if(((IMAPBodyPart)bodyPart).getContent() instanceof MimeMultipart){
Multipart multi2 = (Multipart) ((IMAPBodyPart)bodyPart).getContent();
for (int k = 0; k < multi2.getCount(); k++)
content =multi2.getBodyPart(k).getContent().toString();
}
}
}
}
}
else
content= m.getContent().toString();
if(content.startsWith("com.sun.mail.util.BASE64DecoderStream")){
}
mailprofile.addReceivedMessage(
new Email(
MimeUtility.decodeText(m.getFrom()[0].toString()),
MimeUtility.decodeText(m.getAllRecipients()[0].toString()),
MimeUtility.decodeText(m.getSubject()), m.getReceivedDate(),
content,
new ArrayList<File>()
)
);
}
} catch(Exception e){e.printStackTrace();}
finally{
if(inbox != null)
inbox.close(true);
if(store != null)
store.close();
}
}
示例14: bodyFromMimeType
import javax.mail.BodyPart; //导入方法依赖的package包/类
/**
* This function returns string of the body from Mime Type
* @param message -Pass your message
* @return -Get string of the body.
* @throws MessagingException - This is thrown when there is any exception in Messaging
* @throws IOException - This mostly occurs during connection error
*/
public static String bodyFromMimeType(Object message)
throws MessagingException, IOException {
String body = message.toString();
if (message instanceof Multipart) {
Multipart multipart = (Multipart) message;
for (int x = 0; x < multipart.getCount(); x++) {
BodyPart bodyPart = multipart.getBodyPart(x);
String disposition = bodyPart.getDisposition();
if (disposition != null
&& disposition.equals(BodyPart.ATTACHMENT))
continue;
else {
return bodyPart.getContent().toString();
}
}
}
return body;
}
开发者ID:selenium-webdriver-software-testing,项目名称:kspl-selenium-helper,代码行数:27,代码来源:MiscellaneousFunctions.java
示例15: setBodyPart
import javax.mail.BodyPart; //导入方法依赖的package包/类
public static void setBodyPart(Multipart multipart, byte[] content, String contentType) throws MessagingException {
String disposition = null;
for (int i = 0; i < multipart.getCount(); i++) {
BodyPart bp = multipart.getBodyPart(i);
if (contentType.equalsIgnoreCase(bp.getContentType())) {
disposition = bp.getDisposition();
multipart.removeBodyPart(i);
break;
}
}
InternetHeaders ih1 = new InternetHeaders();
ih1.setHeader("Content-Type", contentType);
BodyPart bodyPart = new MimeBodyPart(ih1, content);
if (disposition != null) {
bodyPart.setDisposition(disposition);
}
multipart.addBodyPart(bodyPart);
}