Note that there are some explanatory texts on larger screens.

plurals
  1. PODifferences between Folder.fetch and getmessages
    primarykey
    data
    text
    <p>I'm trying to write an app that get emails from a POP3 server. The "Strategy" I used eventually is:</p> <ol> <li>Get single message</li> <li>check if the message is already present in my database</li> <li>if not, insert it, goto 1</li> </ol> <p>I know that this is not perfect, but ok...let's just face a problem at once :)</p> <p>apologizing for the ugly style, I'm well trained as Assembly and pure C programmer, just started with Java, my code to get the single message is (I have cut the try/catch statements to make it more readable)</p> <pre class="lang-java prettyprint-override"><code>Properties props = new Properties(); Session session = Session.getDefaultInstance(props, null); Store store = null; POP3Folder folder = null; openStaffLabel: { store = session.getStore(exXContainer.accounts[selectedAccount].accountType.toLowerCase()); store.connect(host, username, password); folder =(POP3Folder) store.getFolder("INBOX"); folder.open(Folder.READ_WRITE); int countMsg = 0; countMsg = folder.getMessageCount(); if (countMsg == 0) break openStaffLabel; message = folder.getMessages(countMsg - first + 1); for(int i = 0;i &lt; messages.length;i++) { // do some stuffs with messages } } // openStaffLabel: folder.close(false); store.close(); </code></pre> <p>That seems to work fine. Then I found over internet this code (<a href="http://www.developer.com/java/other/article.php/3092171/JavaMail-More-Efficiently.htm" rel="nofollow">here</a>), claimed by the poster to be much more efficient:</p> <pre class="lang-java prettyprint-override"><code>URLName url = new URLName("pop3", host, 110, "", user, password); Session session = Session.getDefaultInstance(System.getProperties(),null); Store store = session.getStore(url); store.connect(); POP3Folder inbox = (POP3Folder)store.getFolder("INBOX"); inbox.open(Folder.READ_WRITE); FetchProfile profile = new FetchProfile(); profile.add(UIDFolder.FetchProfileItem.UID); Message[] messages = inbox.getMessages(); inbox.fetch(messages,profile); for(int i = 0;i &lt; messages.length;i++) { // do some stuffs with messages } </code></pre> <p>The author claims: "The major difference with the previous scenario is that the client downloads new emails only"</p> <p>but in his code there is a inbox.getMessages() that, if I understood well, actually download all messages. So the point is...what is the real advantage of using fetch(messages,profile) if with getMessages I have already fetched all the headers? if I only want to download UIDs, how can I do? </p> <p>and, furthermore, if I only want to download the UIDs of the first N mails...is it possible?</p> <p>thank you very much to anyone who will help, I'm stuck on this problem since one week. Cristiano</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload