Sample code for 30+ languages & platforms
Android™

End a POP3 Session Without Committing Deletions

See more POP3 Examples

Demonstrates the Chilkat MailMan.Pop3EndSessionNoQuit method, which closes the POP3 connection without sending the QUIT command. Pending deletion marks are not committed — messages marked with DELE during the session remain in the mailbox. This example marks a message for deletion and then abandons the session so the deletion does not take effect.

Background: POP3's deferred-deletion model effectively gives you a transaction: marks made with DELE are only applied when the session ends with QUIT. Ending without QUIT is therefore a rollback — useful if an error occurs mid-processing and you'd rather leave the mailbox untouched than risk deleting messages you failed to handle. Use Pop3EndSession when you do want the deletions committed.

Chilkat Android™ Downloads

Android™
// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;

import android.app.Activity;
import com.chilkatsoft.*;

import android.widget.TextView;
import android.os.Bundle;

public class SimpleActivity extends Activity {

  private static final String TAG = "Chilkat";

  // Called when the activity is first created.
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    boolean success = false;

    //  Demonstrates the MailMan.Pop3EndSessionNoQuit method, which closes the POP3 connection
    //  WITHOUT sending the QUIT command.  Pending deletion marks are not committed -- messages
    //  marked with DELE during the session remain in the mailbox.

    CkMailMan mailman = new CkMailMan();

    //  Configure the POP3 server connection.
    mailman.put_MailHost("pop.example.com");
    mailman.put_MailPort(995);
    mailman.put_PopSsl(true);
    mailman.put_PopUsername("user@example.com");
    mailman.put_PopPassword("myPassword");

    success = mailman.Pop3BeginSession();
    if (success == false) {
        Log.i(TAG, mailman.lastErrorText());
        return;
        }

    //  Mark a message for deletion...
    success = mailman.DeleteByMsgnum(1);
    if (success == false) {
        Log.i(TAG, mailman.lastErrorText());
        return;
        }

    //  ...but end the session without QUIT, so the deletion is NOT committed and the message
    //  remains in the mailbox.
    success = mailman.Pop3EndSessionNoQuit();
    if (success == false) {
        Log.i(TAG, mailman.lastErrorText());
        return;
        }

    Log.i(TAG, "Session closed without committing the pending deletion.");

  }

  static {
      System.loadLibrary("chilkat");

      // Note: If the incorrect library name is passed to System.loadLibrary,
      // then you will see the following error message at application startup:
      //"The application <your-application-name> has stopped unexpectedly. Please try again."
  }
}