例: MIMEEntity class

  1. 次の例は、文書 (複数の場合もあります) の MIME のコンテントを取得し、メインパート (あるいは唯一のパート) のプロパティを表示します。
    import lotus.domino.*;
    
    public class JavaAgent extends AgentBase {
    
      public void NotesMain() {
    
        try {
          Session session = getSession();
          AgentContext agentContext = session.getAgentContext();
    
          // (Your code goes here)
          Stream stream = session.createStream();
          // Do not convert MIME to rich text
          session.setConvertMIME(false);
          DocumentCollection dc = agentContext.getUnprocessedDocuments();
          Document doc = dc.getFirstDocument();
          while (doc != null) {
            System.out.println("Subject:¥t¥t" +
            doc.getItemValueString("Subject"));
            MIMEEntity mime = doc.getMIMEEntity();
            if (mime != null) {
              System.out.println("Content type:¥t" + 
                mime.getContentType());
              System.out.println("Content subtype:¥t" + 
                mime.getContentSubType());
              System.out.println("Character set:¥t" + mime.getCharset());
              System.out.println("Encoding:¥t¥t" + mime.getEncoding());
              System.out.println("*Headers*");
              System.out.println(mime.getHeaders());
              System.out.println("*Content*");
              System.out.println(mime.getContentAsText());
            }
            else
            {
              System.out.println("Not MIME");
            }
            doc = dc.getNextDocument(doc);
          }
          // Restore conversion
          session.setConvertMIME(true);
         
        } catch(Exception e) {
          e.printStackTrace();
        }
      }
    }
  2. 次の例は、マルチパート MIME エンティティのすべてのパートを表示します。
    import lotus.domino.*;
    
    public class JavaAgent extends AgentBase {
    
      public void NotesMain() {
    
        try {
          Session session = getSession();
          AgentContext agentContext = session.getAgentContext();
    
          // (Your code goes here)
          Stream stream = session.createStream();
          // Do not convert MIME to rich text
          session.setConvertMIME(false);
          DocumentCollection dc = agentContext.getUnprocessedDocuments();
          Document doc = dc.getFirstDocument();
          while (doc != null) {
            System.out.println("Subject:¥t¥t" +
            doc.getItemValueString("Subject"));
            MIMEEntity mime = doc.getMIMEEntity();
            if (mime != null) {
              // If multipart MIME entity
              if (mime.getContentType().equals("multipart")) {
                // Print preamble
                if (!mime.getPreamble().equals("")) {
                  System.out.println("Preamble:¥t" + mime.getPreamble());
                }
                // Print content of each child entity
                MIMEEntity child1 = mime.getFirstChildEntity();
                while (child1 != null) {
                  System.out.println("*Content of child*");
                  System.out.println(child1.getContentAsText());
                  MIMEEntity child2 = child1.getFirstChildEntity();
                  if (child2 == null) {
                      child2 = child1.getNextSibling();
                    if (child2 == null) {
                      child2 = child1.getParentEntity();
                      if (child2 != null)
                        child2 = child2.getNextSibling();
                    }
                  }
                  child1 = child2;
                }
              }
              // If not multipart, just print content
              else {
                System.out.println(mime.getContentAsText());
              }
            }
            else {
              System.out.println("Not MIME");
            }
            doc = dc.getNextDocument(doc);
          }
          // Restore conversion
          session.setConvertMIME(true);
         
        } catch(Exception e) {
          e.printStackTrace();
        }
      }
    }