Add addHeader(), setHeader(), getHeader() and removeHeader() methods to Mail object.

Remove unused java class constants. Fix for bug 540 <http://helma.org/bugs/show_bug.cgi?id=540>
This commit is contained in:
hns 2008-10-30 16:01:06 +00:00
parent d0ede5de85
commit b9a776c979

View file

@ -56,17 +56,21 @@ if (!global.helma) {
*/ */
helma.Mail = function(host, port) { helma.Mail = function(host, port) {
// Error code values for this.status // Error code values for this.status
var OK = 0; var OK = 0;
var SUBJECT = 10; var SUBJECT = 10;
var TEXT = 11; var TEXT = 11;
var MIMEPART = 12; var MIMEPART = 12;
var TO = 20; var TO = 20;
var CC = 21; var CC = 21;
var BCC = 22; var BCC = 22;
var FROM = 23; var FROM = 23;
var REPLYTO = 24; var REPLYTO = 24;
var SEND = 30; var SETHEADER = 25;
var MAILPKG = Packages.javax.mail; var ADDHEADER = 26;
var GETHEADER = 27;
var REMOVEHEADER = 28;
var SEND = 30;
var MAILPKG = Packages.javax.mail;
var self = this; var self = this;
var errStr = "Error in helma.Mail"; var errStr = "Error in helma.Mail";
@ -81,12 +85,9 @@ helma.Mail = function(host, port) {
var MimePart = Packages.helma.util.MimePart; var MimePart = Packages.helma.util.MimePart;
var MimePartDataSource = Packages.helma.util.MimePartDataSource; var MimePartDataSource = Packages.helma.util.MimePartDataSource;
var Address = MAILPKG.Address;
var BodyPart = MAILPKG.BodyPart; var BodyPart = MAILPKG.BodyPart;
var Message = MAILPKG.Message; var Message = MAILPKG.Message;
var Multipart = MAILPKG.Multipart;
var Session = MAILPKG.Session; var Session = MAILPKG.Session;
var Transport = MAILPKG.Transport;
var InternetAddress = MAILPKG.internet.InternetAddress; var InternetAddress = MAILPKG.internet.InternetAddress;
var AddressException = MAILPKG.internet.AddressException; var AddressException = MAILPKG.internet.AddressException;
var MimeBodyPart = MAILPKG.internet.MimeBodyPart; var MimeBodyPart = MAILPKG.internet.MimeBodyPart;
@ -232,6 +233,74 @@ helma.Mail = function(host, port) {
} }
return; return;
}; };
/**
* Set a header in the e-mail message. If the given header is already set the previous
* value is replaced with the new one.
* @param name a header name
* @param value the header value
*/
this.setHeader = function(name, value) {
try {
message.addHeader(name, MimeUtility.encodeText(value));
} catch (mx) {
app.logger.error(errStr + ".setHeader(): " + mx);
setStatus(SETHEADER);
}
return;
}
/**
* Set a header in the e-mail message. If the given header is already set the previous
* value is replaced with the new one.
* @param name a header name
* @param value the header value
*/
this.addHeader = function(name, value) {
try {
message.addHeader(name, MimeUtility.encodeText(value));
} catch (mx) {
app.logger.error(errStr + ".addHeader(): " + mx);
setStatus(ADDHEADER);
}
return;
}
/**
* Get all the headers for this header name.
* Returns null if no headers for this header name are available.
* @param name a header name
* @return {String[]} a string array of header values, or null
*/
this.getHeader = function(name) {
var value = null;
try {
value = message.getHeader(name);
if (value && value.length) {
for (var i = 0; i < value.length; i++) {
value[i] = MimeUtility.decodeText(value[i]);
}
}
} catch (mx) {
app.logger.error(errStr + ".getHeader(): " + mx);
setStatus(GETHEADER);
}
return value;
}
/**
* Remove all headers with this name.
* @param name the header name
*/
this.removeHeader = function(name) {
try {
message.removeHeader(name);
} catch (mx) {
app.logger.error(errStr + ".removeHeader(): " + mx);
setStatus(REMOVEHEADER);
}
return;
}
/** /**
* Sets the Reply-To address of an e-mail message. * Sets the Reply-To address of an e-mail message.