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((sBasePath==null ? "" : sBasePath)+sSrc)));
}
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 (aAttachmentsPath==null) {
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 (aAttachmentsPath==null) {
oSentMessage.setText(sTextBody, sCharEnc);
} else {
oMsgPlainText.setDisposition("inline");
oMsgPlainText.setText(sTextBody, sCharEnc, "plain");
//oMsgPlainText.setContent(sTextBody, "text/plain; charset="+sCharEnc);
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 (aAttachmentsPath!=null) {
final int nAttachments = aAttachmentsPath.length;
FileSystem oFS = new FileSystem();
for (int p=0; p<nAttachments; p++) {
String sFilePath = aAttachmentsPath[p];
if (sBasePath!=null) {
if (!sFilePath.startsWith(sBasePath))
sFilePath = sBasePath + sFilePath;
}
File oFile = new File(sFilePath);
MimeBodyPart oAttachment = new MimeBodyPart();
oAttachment.setDisposition("attachment");
oAttachment.setFileName(oFile.getName());
oAttachment.setHeader("Content-Transfer-Encoding", "base64");
ByteArrayDataSource oDataSrc;
try {
oDataSrc = new ByteArrayDataSource(oFS.readfilebin(sFilePath), "application/octet-stream");
} catch (com.enterprisedt.net.ftp.FTPException ftpe) {
throw new IOException(ftpe.getMessage());
}
oAttachment.setDataHandler(new DataHandler(oDataSrc));
oSentMsgParts.addBodyPart(oAttachment);
} // next
oSentMessage.setContent(oSentMsgParts);
} // fi (iDraftParts>0)