Java
Chilkat2 Java
Open an IMAP Mailbox Read-Only
See more IMAP Examples
Demonstrates the Chilkat Imap.ExamineMailbox method, which opens a mailbox as read-only. Use it instead of SelectMailbox when the application must not change message state, such as the \Seen flag. This example examines the Inbox.
Background: Reading a message can have a side effect: fetching its body normally sets the
\Seen flag, marking it as read. ExamineMailbox corresponds to IMAP's EXAMINE command, which opens the mailbox in a read-only mode where no such changes are made — ideal for scanning, indexing, or backup tools that must leave the user's mailbox exactly as they left it.Chilkat Java Downloads
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Imap;
public class ChilkatExample {
public static void main(String[] args) {
// Demonstrates the Imap.ExamineMailbox method, which opens a mailbox as read-only. Use this
// instead of SelectMailbox when the application must not change message state (such as the
// \Seen flag).
Imap imap = new Imap();
imap.setSsl(true);
imap.setPort(993);
try {
imap.connect("imap.example.com");
imap.login("user@example.com", "myPassword");
// Open the Inbox as read-only.
imap.examineMailbox("Inbox");
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
System.out.println("Inbox opened read-only.");
try {
imap.disconnect();
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
}
}