@Override
public Document send() {
try {
Stream stream;
MIMEEntity mimeEntity;
MIMEHeader mimeHeader;
Database currDb;
Session currSess = getSession();
currSess.setConvertMime(false); // in case Khan is still in suspended animation!
// Create memo doc
try {
currDb = currSess.getCurrentDatabase();
if (null == currDb) {
// Will this work if we're running from DOTS or OSGi plugin??
currDb = currSess.getDatabase(currSess.getServerName(), "mail.box");
}
} catch (Throwable t) {
currDb = currSess.getDatabase(currSess.getServerName(), "mail.box");
}
Document memo = currDb.createDocument();
memo.put("RecNoOutOfOffice", "1"); //no replies from out of office agents
MIMEEntity mimeRoot = memo.createMIMEEntity("Body");
mimeHeader = mimeRoot.createHeader("To");
mimeHeader.setHeaderVal(join(getTo(), ""));
memo.replaceItemValue("sendTo", getTo());
if (cc_.size() > 0) {
mimeHeader = mimeRoot.createHeader("CC");
mimeHeader.setHeaderVal(join(getCC(), ""));
memo.replaceItemValue("cc", getCC());
}
if (bcc_.size() > 0) {
mimeHeader = mimeRoot.createHeader("BCC");
mimeHeader.setHeaderVal(join(getBCC(), ""));
memo.replaceItemValue("bcc", getBCC());
}
//set subject
mimeHeader = mimeRoot.createHeader("Subject");
mimeHeader.setHeaderVal(getSubject());
//create text/alternative directive: text/plain and text/html part will be childs of this entity
MIMEEntity mimeRootChild = mimeRoot.createChildEntity();
String mimeBoundary = memo.getUniversalID().toLowerCase();
mimeHeader = mimeRootChild.createHeader("Content-Type");
mimeHeader.setHeaderVal("multipart/alternative; boundary=\"" + mimeBoundary + "\"");
//create plain text part
if (getText().size() > 0) {
mimeEntity = mimeRootChild.createChildEntity();
stream = currSess.createStream();