Search code examples
javaimap

Identifying the Inbox folder through IMAP


I have connected to an email Store via IMAP (outlook.office365.com). I can work out which folders to use for deleted, spam, outbox and so on, using the LIST command which passes back flags that I can use.

The question is, "how do I know what to use for the InBox". I could just hard-code the name, but that seems likely to fail rapidly. I am sure I am missing something, because if the other folders are tagged, then "inbox" would be a strange omission.

Looking forward to your help. Thanks.

PS - I am doing this with the Java Mail API if that makes a difference to the response.


Solution

  • By protocol specification, the main folder is a special folder always named INBOX.

    See IMAP RFC 3501 §5.1:

    The case-insensitive mailbox name INBOX is a special name reserved to mean "the primary mailbox for this user on this server". The interpretation of all other names is implementation-dependent.