title: How to get the Message Id from POP3 using java Mail
body: <p>From the url </p>
  
  <blockquote>
    <p><a href="https://javamail.java.net/nonav/docs/api/com/sun/mail/pop3/package-summary.html" rel="nofollow noreferrer">https://javamail.java.net/nonav/docs/api/com/sun/mail/pop3/package-summary.html</a>,</p>
  </blockquote>
  
  <p>You can also pre-fetch all the UIDs for all messages like this:</p>
  
  <pre><code>FetchProfile fp = new FetchProfile();
  fp.add(UIDFolder.FetchProfileItem.UID);
  folder.fetch(folder.getMessages(), fp);
  </code></pre>
  
  <p>Then use the technique above to get the UID for each message. This is similar to the technique used with the UIDFolder interface supported by IMAP, but note that POP3 UIDs are strings, not integers like IMAP UIDs. See the POP3 spec for details.</p>
  
  <p>From this, <code>https://www.ietf.org/rfc/rfc1939.txt,</code></p>
  
  <p>In number 7, there's an example of what I need.</p>
  
  <p>Examples:</p>
  
  <pre><code>         S: +OK POP3 server ready &lt;1896.697170952@dbc.mtview.ca.us&gt;
           C: APOP mrose c4c9334bac560ecc979e58001b3e22fb
           S: +OK maildrop has 1 message (369 octets)
  
           In this example, the shared  secret  is  the  string  `tan-
           staaf'.  Hence, the MD5 algorithm is applied to the string
  
              &lt;1896.697170952@dbc.mtview.ca.us&gt;tanstaaf
  
           which produces a digest value of
  
              c4c9334bac560ecc979e58001b3e22fb //this is what we need in Java
  </code></pre>
  
  <p>After this, how do we get the MessageID / UID of each message?</p>
  
  <p>Sample Message ID that I need. A fuego.mail Library that was deprecated was providing us this before:</p>
  
  <pre><code>&lt;F855F5879C6E754E9DE37F2E7D0762327C942B43@GADC-EMB099.ap.abc‌​.com&gt; 
  </code></pre>
  
  <p><strong>UPDATE</strong>
  I got a 3 digit integer i.e. 561 when using this</p>
  
  <pre><code>Store store = emailSession.getStore(MAILSTORETYPE);
  
              store.connect(HOST, USERNAME, PASSWORD);
  
              Folder emailFolder = store.getFolder("INBOX");
              emailFolder.open(Folder.READ_ONLY);
  
              FetchProfile fp = new FetchProfile();
              fp.add(UIDFolder.FetchProfileItem.UID);
              emailFolder.fetch(emailFolder.getMessages(), fp);
  
              POP3Folder pf =(POP3Folder)emailFolder;         
  
              Message[] messages = emailFolder.getMessages();
  
              for (int i = 0, n = messages.length; i &lt; n; i++) {
                  Message message = messages[i];
  
                      String uid = pf.getUID(message);
                      System.out.println(uid);
  </code></pre>