Home > Mobile >  Help: android studio. Write a imap receiving application error.
Help: android studio. Write a imap receiving application error.

Time:10-17

Reference:

The import javax.mail. Mail. Address;
The import javax.mail. Mail. BodyPart;
The import javax.mail. Mail. Flags;
The import javax.mail. Mail. Folder;
The import javax.mail. Mail. The Message;
The import javax.mail. Mail. MessagingException;
The import javax.mail. Mail. Multipart;
The import javax.mail. Mail. Part;
The import javax.mail. Mail. Session;
The import javax.mail. Mail. Store;
The import javax.mail. Mail. Internet. InternetAddress;
The import javax.mail. Mail. Internet. MimeMessage;
The import javax.mail. Mail. Internet. MimeMultipart;
The import javax.mail. Mail. Internet. MimeUtility;
////////////////////////////////////////////////////////////////////////
The main function
Public static void parseMessage (Message... Messages) throws MessagingException, IOException {
If (messages==null | | messages. The length & lt; 1)
Throw new MessagingException (" was not found to parse the mail!" );

//parse all email
For (int I=0, count=messages. The length; I & lt; The count. I++) {
The MimeMessage MSG=(MimeMessage) messages [I];
MSG. SetFlag (Flags. The Flag. SEEN, true);
System. The out. Println (" -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- parse the first "+ MSG. GetMessageNumber () +" email -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ");
System. The out. Println (" subject: "+ getSubject (MSG));
System. The out. Println (" the sender: "+ getFrom (MSG));
System. The out. Println (" the recipient: "+ getReceiveAddress (MSG, null));
System. The out. Println (" send time: "+ getSentDate (MSG, null));
System. The out. Println (" have read: "+ isSeen (MSG));
System. The out. Println (" priority mail: "+ getPriority (MSG));
System. The out. Println (" do you need receipt: "+ isReplySign (MSG));
System. The out. Println (" mail size: "+ MSG. GetSize () * 1024 +" KB ");
/* to perform to this step wrong, */
Boolean isContainerAttachment=isContainAttachment (MSG);
System. The out. Println (" contains attachments: "+ isContainerAttachment);

If (isContainerAttachment) {
D09 saveAttachment (MSG, "/storage/0-0 b07/Download/" + MSG. The getSubject () +" _ ");//save attachment
}


////////////////////////////////////////////////////////////////////////
The called function isContainAttachment contains a parameter part






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 & lt; PartCount; I++) {
BodyPart BodyPart=multipart. GetBodyPart (I);
String disp=bodyPart. GetDisposition ();
If (disp!=null & amp; & (disp. EqualsIgnoreCase (Part. ATTACHMENT) | | disp. EqualsIgnoreCase (Part. The 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 (" the message/rfc822 ")) {
Flag=isContainAttachment ((Part) Part. GetContent ());
}
return flag;
}






/System. Out: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- analytical 1 email -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Printing information
I/System. Out: topic: this is an English mail for test
The sender: XXX & lt; 240 [email protected] & gt;
I/System. Out: the recipient: 240 xxx462 & lt; [email protected] & gt;
I/System. Out: send time: October 16, 2020 Fri 00:32
Have read: true
I/System. Out: priority mail: ordinary
I/System. Out: do you need receipt: false
Mail size: 2423808 KB


W/m.e xample. Emai: Rejecting the class com., sun. Mail. Handlers. Multipart_mixed that attempts to sub - type erroneous class com., sun. Mail. Handlers. Handler_base in/data/app/~ ~ 1 vevtezuofpweyzmewzg - g==/com. Example. Email - Pjja9LiRaQz5kqfN5tTA3w==/base. Apk
E/AndroidRuntime: FATAL EXCEPTION: Thread - 2
Process: com. Example. Email, PID: 21568
Java. Lang. VerifyError: Rejecting the class com., sun. Mail. Handlers. Multipart_mixed that attempts to sub - type erroneous class com., sun. Mail. Handlers. Handler_base (declaration of 'com. Sun. Mail. Handlers. Multipart_mixed' appears in/data/app/~ ~ 1 vevtezuofpweyzmewzg - g==/com. Example. Email - Pjja9LiRaQz5kqfN5tTA3w==/base. The apk)
The at Java. Lang. Class. NewInstance (Native Method)
The at javax.mail. Activation. MailcapCommandMap. GetDataContentHandler (MailcapCommandMap. Java: 631)
The at javax.mail. Activation. MailcapCommandMap. CreateDataContentHandler (MailcapCommandMap. Java: 603)
At javax.activation.Com mandMap. CreateDataContentHandler (CommandMap. Java: 235)
The at javax.mail. Activation. The DataHandler. GetDataContentHandler (DataHandler. Java: 624)
The at javax.mail. Activation. The DataHandler. GetContent (DataHandler. Java: 551)
The at javax.mail. Mail. Internet. MimeMessage. GetContent (MimeMessage. Java: 1502)
At com. Example. Email. Mail. IMAPReceiveMailTest. GetMailTextContent (IMAPReceiveMailTest. Java: 311)
At com. Example. Email. Mail. IMAPReceiveMailTest. ParseMessage (IMAPReceiveMailTest. Java: 123)
At com. Example. Email. Mail. IMAPReceiveMailTest. IMAP_recv (IMAPReceiveMailTest. Java: 79)
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related