* Allow to directly pass a javax.mail.BodyPart to addPart().

This commit is contained in:
hns 2006-11-27 12:47:04 +00:00
parent 9a98f81710
commit fb77729856

View file

@ -9,9 +9,9 @@
* Copyright 1998-2006 Helma Software. All Rights Reserved. * Copyright 1998-2006 Helma Software. All Rights Reserved.
* *
* $RCSfile: Mail.js,v $ * $RCSfile: Mail.js,v $
* $Author: czv $ * $Author: hannes $
* $Revision: 1.2 $ * $Revision: 1.3 $
* $Date: 2006/04/24 07:02:17 $ * $Date: 2006/06/28 20:06:03 $
*/ */
@ -43,6 +43,7 @@ helma.Mail = function(smtp) {
var DataHandler = Packages.javax.activation.DataHandler; var DataHandler = Packages.javax.activation.DataHandler;
var Address = MAILPKG.Address; var Address = MAILPKG.Address;
var BodyPart = MAILPKG.BodyPart;
var Message = MAILPKG.Message; var Message = MAILPKG.Message;
var Multipart = MAILPKG.Multipart; var Multipart = MAILPKG.Multipart;
var Session = MAILPKG.Session; var Session = MAILPKG.Session;
@ -215,17 +216,23 @@ helma.Mail = function(smtp) {
obj = obj.unwrap(); obj = obj.unwrap();
} }
var part = new MimeBodyPart(); var part;
if (typeof obj == "string") { if (obj instanceof BodyPart) {
part.setContent(obj.toString(), "text/plain"); // we already got a body part, no need to convert it
} else if (obj instanceof File) { part = obj;
// FIXME: the following line did not work under windows: } else {
//var source = new FileDataSource(obj); part = new MimeBodyPart();
var source = new FileDataSource(obj.getPath()); if (typeof obj == "string") {
part.setDataHandler(new DataHandler(source)); part.setContent(obj.toString(), "text/plain");
} else if (obj instanceof MimePart) { } else if (obj instanceof File) {
var source = new MimePartDataSource(obj); // FIXME: the following line did not work under windows:
part.setDataHandler(new DataHandler(source)); //var source = new FileDataSource(obj);
var source = new FileDataSource(obj.getPath());
part.setDataHandler(new DataHandler(source));
} else if (obj instanceof MimePart) {
var source = new MimePartDataSource(obj);
part.setDataHandler(new DataHandler(source));
}
} }
if (filename != null) { if (filename != null) {
try { try {