JAVA/CORBA CLASSES
Examples: MIMEEntity class
1. The following example gets the MIME content of a document (or documents) and displays the properties of the main (or only) part.
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. The following example displays all the parts of a multipart MIME entity.
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();
}
}
}
See Also
MIMEEntity class
Glossary
Feedback on
Help
or
Product Usability
?
Help on Help
All Help Contents
Glossary