if (sSrc.startsWith("www."))
sSrc = "http://" + sSrc;
if (sSrc.startsWith("http://") || sSrc.startsWith("https://")) {
oImgBodyPart.setDataHandler(new DataHandler(new URL(Hosts.resolve(sSrc))));
}
else {
oImgBodyPart.setDataHandler(new DataHandler(new FileDataSource(sSrc)));
}
if (sSrc.endsWith(".png")) oImgBodyPart.setHeader("Content-Type", "image/png;name="+sCid);
oImgBodyPart.setDisposition("inline");
oImgBodyPart.setHeader("Content-ID", sCid);
oImgBodyPart.setFileName(sCid);
// Add image to multi-part
if (DebugFile.trace) DebugFile.writeln("MimeBodyPart(multipart/related).addBodyPart("+sCid+")");
oHtmlRelated.addBodyPart(oImgBodyPart);
} // wend
// Set html text alternative part (html text + inline images)
MimeBodyPart oTextHtmlRelated = new MimeBodyPart();
oTextHtmlRelated.setContent(oHtmlRelated);
if (DebugFile.trace) DebugFile.writeln("MimeBodyPart(multipart/alternative).addBodyPart(multipart/related)");
oTextHtmlAlt.addBodyPart(oTextHtmlRelated);
}
// ************************************************************************
// Create message to be sent and add main text body to it
if (0==iDraftParts) {
oSentMessage.setContent(oTextHtmlAlt);
} else {
MimeBodyPart oMixedPart = new MimeBodyPart();
oMixedPart.setContent(oTextHtmlAlt);
oSentMsgParts.addBodyPart(oMixedPart);
}
} else { // (sContentType=="plain")
// *************************************************
// If this is a plain text message just add the text
if (0==iDraftParts) {
oSentMessage.setText(sBody, Charset.forName(sEncoding).name(), "plain");
} else {
oMsgPlainText.setDisposition("inline");
oMsgPlainText.setText(sBody,Charset.forName(sEncoding).name(),"plain");
if (DebugFile.trace) DebugFile.writeln("MimeBodyPart(multipart/mixed).addBodyPart(text/plain)");
oSentMsgParts.addBodyPart(oMsgPlainText);
}
}
// fi (sContentType=="html")
// ************************************************************************
// Add attachments to message to be sent
if (iDraftParts>0) {
for (int p=0; p<iDraftParts; p++) {
DBMimePart oPart = (DBMimePart) oDraftParts.getBodyPart(p);
String sDisposition = oPart.getDisposition();
if (sDisposition==null)
sDisposition = "inline";
else if (sDisposition.equals("reference") || sDisposition.equals("pointer"))
sDisposition = "attachment";
int iSize = oPart.getSize();
if (iSize<=0) iSize = 4000;
InputStream oInStrm = oPart.getInputStream();
ByteArrayOutputStream oByStrm = new java.io.ByteArrayOutputStream(iSize);
new StreamPipe().between(oInStrm, oByStrm);
oInStrm.close();
if (DebugFile.trace) DebugFile.writeln("part " + String.valueOf(p) + " size is " + String.valueOf(oByStrm.size()));
ByteArrayDataSource oDataSrc = new ByteArrayDataSource(oByStrm.toByteArray(), oPart.getContentType());
MimeBodyPart oAttachment = new MimeBodyPart();
oAttachment.setDisposition(sDisposition);
if (sDisposition.equals("attachment"))
if (null==oPart.getDescription())
oAttachment.setFileName(oPart.getFileName());
else
oAttachment.setFileName(oPart.getDescription());
oAttachment.setHeader("Content-Transfer-Encoding", "base64");
oAttachment.setDataHandler(new DataHandler(oDataSrc));
oSentMsgParts.addBodyPart(oAttachment);
} // next
oSentMessage.setContent(oSentMsgParts);
} // fi (iDraftParts>0)