*/
@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();
stream.writeText(join(getText(), System.getProperty("line.separator")));
mimeEntity.setContentFromText(stream, "text/plain; charset=\"UTF-8\"", MIMEEntity.ENC_NONE);
stream.close();
}
//create HTML part
if (contentsHTML_.size() > 0) {
mimeEntity = mimeRootChild.createChildEntity();
stream = currSess.createStream();
stream.writeText(join(contentsHTML_, System.getProperty("line.separator")));
mimeEntity.setContentFromText(stream, "text/html; charset=\"UTF-8\"", MIMEEntity.ENC_NONE);
stream.close();
}
//create embedded JSON part
if (StringUtil.isEmpty(getJSON())) {
mimeEntity = mimeRootChild.createChildEntity();
stream = currSess.createStream();
String json = "{\"url\" : \"" + getJSON() + "\"}" + System.getProperty("line.separator");
stream.writeText(json);
mimeEntity.setContentFromText(stream, "application/embed+json; charset=\"UTF-8\"", MIMEEntity.ENC_NONE);
stream.close();