Sample code for 30+ languages & platforms
Java

Compare Two Emails by UIDL

See more Email Object Examples

Demonstrates the Chilkat Email.UidlEquals method, which returns true if this email's UIDL equals the UIDL of the email passed as the argument. The comparison is meaningful for messages obtained through POP3. This example gives two emails the same UIDL and compares them.

Background: A POP3 UIDL is a stable, unique identifier a server assigns to each message in a mailbox. Comparing UIDLs is how a client decides whether two message references point to the same server message — the basis for "leave messages on server" logic, where an app downloads a message once and skips it on later checks by remembering its UIDL.

Chilkat Java Downloads

Java
import com.chilkatsoft.*;

public class ChilkatExample {

  static {
    try {
        System.loadLibrary("chilkat");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load.\n" + e);
      System.exit(1);
    }
  }

  public static void main(String argv[])
  {
    //  Demonstrates the UidlEquals method, which returns true if this email's UIDL equals the
    //  UIDL of the email passed as the argument.  UIDLs are POP3 message identifiers.

    CkEmail email1 = new CkEmail();
    email1.AddHeaderField("X-UIDL","0000000123abcdef");

    CkEmail email2 = new CkEmail();
    email2.AddHeaderField("X-UIDL","0000000123abcdef");

    //  Compare the two emails' UIDLs.
    boolean eq = email1.UidlEquals(email2);

    if (eq == true) {
        System.out.println("The two emails have the same UIDL.");
        }
    else {
        System.out.println("The two emails have different UIDLs.");
        }
  }
}