[cvs] expresso commit by mtraum: allow manually adding headers with
addHeader
JCorporate Ltd
jcorp at jcorporate.com
Thu Jan 6 21:52:39 UTC 2005
Log Message:
-----------
allow manually adding headers with addHeader (F. Galli)
Modified Files:
--------------
expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/core/misc:
EMailSender.java
Revision Data
-------------
Index: EMailSender.java
===================================================================
RCS file: /home/javacorp/.cvs/expresso/expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/core/misc/EMailSender.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -Lexpresso-web/WEB-INF/src/com/jcorporate/expresso/core/misc/EMailSender.java -Lexpresso-web/WEB-INF/src/com/jcorporate/expresso/core/misc/EMailSender.java -u -r1.20 -r1.21
--- expresso-web/WEB-INF/src/com/jcorporate/expresso/core/misc/EMailSender.java
+++ expresso-web/WEB-INF/src/com/jcorporate/expresso/core/misc/EMailSender.java
@@ -69,11 +69,14 @@
*/
package com.jcorporate.expresso.core.misc;
-import com.jcorporate.expresso.core.db.DBConnection;
-import com.jcorporate.expresso.core.db.DBException;
-import com.jcorporate.expresso.core.registry.RequestRegistry;
-import com.jcorporate.expresso.services.dbobj.Setup;
-import org.apache.log4j.Logger;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
+import java.util.Vector;
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
@@ -85,12 +88,13 @@
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Properties;
-import java.util.Vector;
+
+import org.apache.log4j.Logger;
+
+import com.jcorporate.expresso.core.db.DBConnection;
+import com.jcorporate.expresso.core.db.DBException;
+import com.jcorporate.expresso.core.registry.RequestRegistry;
+import com.jcorporate.expresso.services.dbobj.Setup;
/**
* EMailSender is a class that hides the details of sending email through an SMTP server
@@ -120,7 +124,8 @@
protected String dbName = null;
protected List attachments = null;
protected List dataSourceAttachments = null;
-
+ /** HTML custom Headers list (Francesco Galli - f.galli at inera.it) */
+ protected Hashtable headers = null;
protected boolean htmlFormat = false; // add boolean property for html format emails
private int maxConnectRetries = 0;
@@ -252,12 +257,24 @@
* @return the data context
*/
public String getDataContext() {
- if ((dbName == null) || (dbName.trim().equals(""))) {
+ if ((dbName == null) || (dbName.trim().equals(StringUtil.EMPTY_STRING))) {
dbName = getDataContextFromRegistry();
}
return dbName;
} /* getDataContext() */
+ /** Adds a header to the mail.
+ *
+ * @author Francesco Galli - Inera srl - f.galli at inera.it
+ * @param headerName
+ * @param headerValue
+ */
+ public void addHeader(String headerName, String headerValue) {
+ if (headers == null)
+ headers = new Hashtable();
+ headers.put(headerName, headerValue);
+ }
+
/**
* This method returns the email address to be shown in the "From" header of the
* email. It will return the address set by the setFromAddress() method. If null,
@@ -346,7 +363,7 @@
String myUser = StringUtil.notNull(user);
try {
- if (myUser.equals("")) {
+ if (myUser.equals(StringUtil.EMPTY_STRING)) {
myUser = Setup.getValueRequired(getDataContext(), "MAILUserName");
}
} catch (DBException dex) {
@@ -395,7 +412,7 @@
}
// If SMTP username is null or empty, use a "plain" non-authenticated
// SMTP sessions
- if (myUser != null && !myUser.trim().equals("")) {
+ if (myUser != null && !myUser.trim().equals(StringUtil.EMPTY_STRING)) {
useAuth = true;
}
@@ -484,7 +501,15 @@
msg.setRecipients(Message.RecipientType.TO, toAddr); // The To header
msg.setSubject(subject); // The Subject header
msg.setSentDate(new Date()); // The Date header
-
+ //Francesco Galli 20041117 custom header modification
+ if (headers != null) {
+ Enumeration headersEnum = headers.keys();
+ while (headersEnum.hasMoreElements()) {
+ String key = (String) headersEnum.nextElement();
+ msg.addHeader(key, (String) headers.get(key));
+ }
+ }
+
// A message contains a multi-part MIME container
// The multi-part MIME container contains multiple MIME body parts
MimeMultipart mp = new MimeMultipart();
@@ -622,7 +647,7 @@
public void setDataContext(String newDBName) {
dbName = StringUtil.notNull(newDBName);
- if (dbName.equals("")) {
+ if (dbName.equals(StringUtil.EMPTY_STRING)) {
dbName = "default"; // ?? leave null?
}
}
@@ -660,7 +685,7 @@
*/
public String getPersonal() {
if (personal == null) {
- return "";
+ return new String(StringUtil.EMPTY_STRING);
} else {
return this.personal;
}
More information about the cvs
mailing list