Examples: closeMIMEEntities method

This agent changes a MIME header, closes MIME processing, and deletes the associated "Body" items. Closing MIME processing with the save option pushes the header change to the "Subject" item.

import lotus.domino.*;

public class JavaAgent extends AgentBase {

  public void NotesMain() {

    try {
      Session session = getSession();
      AgentContext agentContext = session.getAgentContext();

      // (Your code goes here)
      // Do not convert MIME to rich text
      session.setConvertMIME(false);
      DocumentCollection dc = agentContext.getUnprocessedDocuments();
      Document doc = dc.getFirstDocument();
      while (doc != null) {
        MIMEEntity mime = doc.getMIMEEntity();
        if (mime != null) {
          MIMEHeader header = mime.getNthHeader("Subject");
          if (header != null) {
            header.setHeaderVal
            (header.getHeaderVal() + " - Body removed");
            if (doc.closeMIMEEntities(true, "Body")) {
              doc.removeItem("Body");
            }
          }
          else {
            System.out.println
            ("No Subject header - " + doc.getItemValueString("Subject"));
          }
        }
        else {
          System.out.println
          ("Not MIME - " + doc.getItemValueString("Subject"));
        }
        doc.save(true, true);
        doc = dc.getNextDocument(doc);
      }
      // Restore MIME conversion
      session.setConvertMIME(true);
      
    } catch(Exception e) {
      e.printStackTrace();
    }
  }
}