Je suis en train de créer un récepteur de courriers Imapmail de base en utilisant Spring Integration et je suis tombé sur une exception sticky folder closed. Je reçois constamment une exception de dossier fermé lors de la lecture du contenu de l'e-mail, mais je suis capable d'obtenir correctement le sujet.
Toute aide est grandement appréciée.
1. Mon contexte d'application est le suivant
javax.net.ssl.SSLSocketFactory
false
imaps
false
2. L'application principale est la suivante
ApplicationContext ac = new ClassPathXmlApplicationContext("/META-INF/spring/integration/gmail.xml");
ImapIdleChannelAdapter ic=(ImapIdleChannelAdapter)ac
.getBean("mailAdapter");
ic.start();
3. L'activatrice de service est la suivante
public class MessageReceiver {
public void handle(javax.mail.Message message){
MailToStringTransformer m2s = new MailToStringTransformer();
m2s.setCharset("utf-8");
//payload instanceof MimeMultipart
if (message instanceof MimeMessage) {
try {
System.out.println("inside mimemessagehandler");
// javax.mail.Message mailMessage = (javax.mail.Message) payload;
System.out.println(message.getSubject());
System.out.println(getTextFromMessage(message));
Address[] receipts = message.getAllRecipients();
System.out.println("RECEIPIENTS MAIL ID");
if (receipts != null && receipts.length > 0) {
for (int i = 0; i < receipts.length; i++) {
System.out.println(((InternetAddress) receipts[i]).getAddress());
}
}
System.out.println("FROM MAIL ID");
Address[] froms = message.getFrom();
String email = froms == null ? null
: ((InternetAddress) froms[0]).getAddress();
System.out.println(email);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
private static String getTextFromMessage(javax.mail.Message message) throws Exception {
String result = "";
if (message.isMimeType("text/plain")) {
result = message.getContent().toString();
} else if (message.isMimeType("multipart/*")) {
MimeMultipart mimeMultipart = (MimeMultipart) message.getContent();
result = getTextFromMimeMultipart(mimeMultipart);
}
return result;
}
private static String getTextFromMimeMultipart(MimeMultipart mimeMultipart) throws Exception {
String result = "";
int count = mimeMultipart.getCount();
System.out.println("CCC "+count);
for (int i = 0; i < count; i++) {
// mimeMultipart.toString()
BodyPart bodyPart = mimeMultipart.getBodyPart(i);
if (bodyPart.isMimeType("text/plain")) {
result = mimeMultipart.toString();//(String) bodyPart.getContent();
} else if (bodyPart.isMimeType("text/html")) {
String html = (String) bodyPart.getContent();
// result = result + "\n" + org.jsoup.Jsoup.parse(html).text();
} else if (bodyPart.getContent() instanceof MimeMultipart) {
result = result + getTextFromMimeMultipart((MimeMultipart) bodyPart.getContent());
}
}
return result;
}
}
--- EXCEPTION
javax.mail.FolderClosedException
at javax.mail.internet.MimeBodyPart.getContent(MimeBodyPart.java:659)
at org.springframework.integration.mail.imapidle.MessageReceiver.getTextFromMimeMultipart(MessageReceiver.java:101)
at org.springframework.integration.mail.imapidle.MessageReceiver.getTextFromMessage(MessageReceiver.java:83)
at org.springframework.integration.mail.imapidle.MessageReceiver.handle(MessageReceiver.java:41)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at