ImapMailReceiver在只读文件夹上没有存储尝试(失败)[已限制]; [英] ImapMailReceiver NO STORE attempt on READ-ONLY folder (Failure) [THROTTLED];

查看:112
本文介绍了ImapMailReceiver在只读文件夹上没有存储尝试(失败)[已限制];的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我花了一天的时间来寻找这种例外的一些解释.我尝试以编程方式配置ImapMailReceiver和ImapIdleChannelAdapter.

I spend day trying to find some explanation this exception. I try to configure ImapMailReceiver and ImapIdleChannelAdapter programmatic.

Pro Spring Integration 书中,我仅找到少量有关该问题的教程.

I didn't find any tutorials about this question just small info in Pro Spring Integration book.

public void loadMessages() {
        ImapIdleChannelAdapter imapIdleChannelAdapter = null;
        ImapMailReceiver imapMailReceiver = null;
        try {
            imapMailReceiver = new ImapMailReceiver("imaps://" + URLEncoder.encode(USERNAME, "UTF-8") + ":" + PASSWORD + "@imap.gmail.com:993/INBOX");
            imapMailReceiver.setShouldMarkMessagesAsRead(true);
            imapMailReceiver.setShouldDeleteMessages(false);

            Properties javaMailProperties = new Properties();
            javaMailProperties.put(MAIL_IMAP_SOCKET_FACTORY_CLASS, environment.getProperty(MAIL_IMAP_SOCKET_FACTORY_CLASS, SOCKET_FACTORY_CLASS));
            javaMailProperties.put(MAIL_IMAP_SOCKET_FACTORY_FALLBACK, environment.getProperty(MAIL_IMAP_SOCKET_FACTORY_FALLBACK, Boolean.class, SOCKET_FACTORY_FALLBACK));
            javaMailProperties.put(MAIL_STORE_PROTOCOL, environment.getProperty(MAIL_STORE_PROTOCOL, INBOX_MAIL_PROTOCOL));
            javaMailProperties.put(MAIL_DEBUG, environment.getProperty(MAIL_DEBUG, Boolean.class, MAIL_DEBUG_VAL));
            imapMailReceiver.setJavaMailProperties(javaMailProperties);

            imapMailReceiver.setJavaMailAuthenticator(new Authenticator() {
                @Override
                protected PasswordAuthentication getPasswordAuthentication() {
                    return new PasswordAuthentication(USERNAME, PASSWORD);
                }
            });


            ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler();
            threadPoolTaskScheduler.setPoolSize(environment.getProperty(RECEIVE_MESSAGE_POOL_SIZE, Integer.class, DEFAULT_RECEIVE_MESSAGE_POOL_SIZE));
            threadPoolTaskScheduler.afterPropertiesSet();

            DirectChannel directChannel = new DirectChannel();
            directChannel.subscribe(new MessageHandler() {
                @Override
                public void handleMessage(Message<?> message) throws org.springframework.messaging.MessagingException {
                    LOGGER.info("Message: " + message);

                }
            });


            imapIdleChannelAdapter = new ImapIdleChannelAdapter(imapMailReceiver);
            imapIdleChannelAdapter.setAutoStartup(true);
            imapIdleChannelAdapter.setShouldReconnectAutomatically(true);
            imapIdleChannelAdapter.setTaskScheduler(threadPoolTaskScheduler);
            imapIdleChannelAdapter.setOutputChannel(directChannel);
            imapIdleChannelAdapter.start();
        } catch (IllegalStateException iex){
            LOGGER.debug("Receiving messages failed", iex);
            iex.printStackTrace();
            imapIdleChannelAdapter.stop();
            try{
                imapMailReceiver.destroy();
            } catch (Exception ex){
                LOGGER.debug("Impossible destroy imapMailReceiver", ex);
                ex.printStackTrace();
            }
        } catch (UnsupportedEncodingException uex) {
            LOGGER.debug("UnsupportedEncoding Exception", uex);
            uex.printStackTrace();
        }
    }

我的堆栈跟踪

09:13:27,429  INFO ImapMailReceiver:251 - attempting to receive mail from folder [INBOX]
09:13:34,840  WARN ImapIdleChannelAdapter:230 - error occurred in idle task
javax.mail.MessagingException: A13 NO STORE attempt on READ-ONLY folder (Failure) [THROTTLED];
  nested exception is:
    com.sun.mail.iap.CommandFailedException: A13 NO STORE attempt on READ-ONLY folder (Failure) [THROTTLED]
    at com.sun.mail.imap.IMAPMessage.setFlags(IMAPMessage.java:858)
    at javax.mail.Message.setFlag(Message.java:574)
    at org.springframework.integration.mail.AbstractMailReceiver.setMessageFlags(AbstractMailReceiver.java:317)
    at org.springframework.integration.mail.AbstractMailReceiver.postProcessFilteredMessages(AbstractMailReceiver.java:283)
    at org.springframework.integration.mail.AbstractMailReceiver.receive(AbstractMailReceiver.java:272)
    at org.springframework.integration.mail.ImapIdleChannelAdapter$IdleTask.run(ImapIdleChannelAdapter.java:216)
    at org.springframework.integration.mail.ImapIdleChannelAdapter$ReceivingTask.run(ImapIdleChannelAdapter.java:184)
    at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
    at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:81)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:178)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:292)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:722)

我也找到了这样的决定

http://harikrishnan83.wordpress.com/2009/01/24/access-gmail-with-imap-using-java-mail-api/ http://metoojava.wordpress. com/2010/03/21/java-code-to-receive-mail-using-javamailapi/

但是我不明白为什么人们使用这种方式来获取消息(该决定的主要来源,因为我什至无法在Spring Pro Integration和

But I can't understand why people use this way for getting messages (where the main source this decision because I can't even find this type of solution in Spring Pro Integration and Spring documentation )

请,任何人都可以向我解释 1)在这种情况下,我应该使用ImapIdleChannelAdapter,而当使用Session进行存储并连接到邮箱时. 2)为什么现在出现异常仅对只读文件夹不进行存储尝试"

Please, can anyone explain me 1)in which case I should use ImapIdleChannelAdapter and when just Session for getting store and connecting to mailbox. 2)Why do I get the exception 'NO STORE attempt on READ-ONLY folder' now

推荐答案

您应该调用imapMailReceiver.afterPropertiesSet(),这会切换this.folderOpenMode = Folder.READ_WRITE;.就您而言,它看起来就在这里:

You should call imapMailReceiver.afterPropertiesSet(), which switches this.folderOpenMode = Folder.READ_WRITE;. In your case it looks lie here:

imapMailReceiver.setJavaMailAuthenticator(new Authenticator() {
...
});

imapMailReceiver.afterPropertiesSet();

实际上,几乎所有的Spring Integration组件都应配置为Spring Bean,并且Container会注意它们的初始化.新的4.0版本为JavaConfig提供了足够的选项: https://spring.io/blog/2014/04/30/spring-integration-4-0-released .

Actually almost all Spring Integration components should be configured as Spring beans and Container will take care about their initialization. The new 4.0 version provides enough options for JavaConfig: https://spring.io/blog/2014/04/30/spring-integration-4-0-released .

我不清楚为什么默认情况下它是Folder.READ_ONLY,并且对此没有任何影响.

It's not clear to me why by default it is Folder.READ_ONLY and there is no setter on the matter.

随时提出JIRA问题: https://jira.spring.io/browse/INT

Feel free to raise a JIRA issue: https://jira.spring.io/browse/INT

在这种情况下,我应该使用ImapIdleChannelAdapter,而当使用Session进行存储并连接到邮箱时.

In which case I should use ImapIdleChannelAdapter and when just Session for getting store and connecting to mailbox.

实际上,这取决于您的邮件提供商. Spring Integration提供了两个组件:Pop3MailReceiverImapMailReceiver.当然,Imap更好,因为它不将消息提取到本地目录并支持Listener. Pop3,您应该定期ping通.

Actually it depends on your Mail provider. Spring Integration provides two components: Pop3MailReceiver and ImapMailReceiver. Of course Imap is better, because it doesn't fetch messages to the local directory and supports Listener. Pop3 you should ping periodically.

这篇关于ImapMailReceiver在只读文件夹上没有存储尝试(失败)[已限制];的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆