Methods Summary |
---|
public org.apache.mailet.MailAddress | getListservAddress()The email address that this listserv processes on. If returns null, will use the
recipient of the message, which hopefully will be the correct email address assuming
the matcher was properly specified.
return listservAddress;
|
public java.lang.String | getMailetInfo()Return a string describing this mailet.
return "JDBC listserv mailet";
|
public java.util.Collection | getMembers()Returns a Collection of MailAddress objects of members to receive this email
if (!cacheSettings) {
loadSettings();
}
return members;
|
public java.lang.String | getSubjectPrefix()An optional subject prefix which will be surrounded by [].
return subjectPrefix;
|
public void | init()Initialize the mailet
if (getInitParameter("data_source") == null) {
throw new MailetException("data_source not specified for JDBCListserv");
}
if (getInitParameter("listserv_id") == null) {
throw new MailetException("listserv_id not specified for JDBCListserv");
}
if (getInitParameter("listserv_table") == null) {
throw new MailetException("listserv_table not specified for JDBCListserv");
}
if (getInitParameter("members_table") == null) {
throw new MailetException("members_table not specified for JDBCListserv");
}
String datasourceName = getInitParameter("data_source");
listservID = getInitParameter("listserv_id");
listservTable = getInitParameter("listserv_table");
membersTable = getInitParameter("members_table");
if (getInitParameter("cache_settings") != null) {
try {
cacheSettings = new Boolean(getInitParameter("cache_settings")).booleanValue();
} catch (Exception e) {
//ignore error
}
}
Connection conn = null;
try {
ServiceManager componentManager = (ServiceManager)getMailetContext().getAttribute(Constants.AVALON_COMPONENT_MANAGER);
// Get the DataSourceSelector service
DataSourceSelector datasources = (DataSourceSelector)componentManager.lookup(DataSourceSelector.ROLE);
// Get the data-source required.
datasource = (DataSourceComponent)datasources.select(datasourceName);
conn = datasource.getConnection();
// Check if the required listserv table exists. If not, complain.
DatabaseMetaData dbMetaData = conn.getMetaData();
// Need to ask in the case that identifiers are stored, ask the DatabaseMetaInfo.
// Try UPPER, lower, and MixedCase, to see if the table is there.
if (!(theJDBCUtil.tableExists(dbMetaData, listservTable))) {
StringBuffer exceptionBuffer =
new StringBuffer(128)
.append("Could not find table '")
.append(listservTable)
.append("' in datasource '")
.append(datasourceName)
.append("'");
throw new MailetException(exceptionBuffer.toString());
}
// Check if the required members table exists. If not, complain.
// Need to ask in the case that identifiers are stored, ask the DatabaseMetaInfo.
// Try UPPER, lower, and MixedCase, to see if the table is there.
if (!( theJDBCUtil.tableExists(dbMetaData, membersTable))) {
StringBuffer exceptionBuffer =
new StringBuffer(128)
.append("Could not find table '")
.append(membersTable)
.append("' in datasource '")
.append(datasourceName)
.append("'");
throw new MailetException(exceptionBuffer.toString());
}
StringBuffer queryBuffer =
new StringBuffer(256)
.append("SELECT members_only, attachments_allowed, reply_to_list, subject_prefix, list_address FROM ")
.append(listservTable)
.append(" WHERE listserv_id = ?");
listservQuery = queryBuffer.toString();
queryBuffer =
new StringBuffer(128)
.append("SELECT member FROM ")
.append(membersTable)
.append(" WHERE listserv_id = ?");
membersQuery = queryBuffer.toString();
//Always load settings at least once... if we aren't caching, we will load at each getMembers() call
loadSettings();
} catch (MailetException me) {
throw me;
} catch (Exception e) {
throw new MessagingException("Error initializing JDBCListserv", e);
} finally {
theJDBCUtil.closeJDBCConnection(conn);
}
|
public boolean | isAttachmentsAllowed()Returns whether this listserv allow attachments
return attachmentsAllowed;
|
public boolean | isMembersOnly()Returns whether this list should restrict to senders only
return membersOnly;
|
public boolean | isReplyToList()Returns whether listserv should add reply-to header
return replyToList;
|
protected void | loadSettings()Loads the configuration settings for this mailet from the database.
Connection conn = null;
PreparedStatement stmt = null;
ResultSet rs = null;
try {
//Load members
conn = datasource.getConnection();
try {
stmt = conn.prepareStatement(membersQuery);
stmt.setString(1, listservID);
rs = stmt.executeQuery();
Collection tmpMembers = new Vector();
while (rs.next()) {
String address = rs.getString(1);
try {
MailAddress mailAddress = new MailAddress(address);
tmpMembers.add(mailAddress);
} catch (ParseException pe) {
//don't stop... just log and continue
StringBuffer exceptionBuffer =
new StringBuffer(64)
.append("error parsing address '")
.append(address)
.append("' in listserv '")
.append(listservID)
.append("'");
log(exceptionBuffer.toString());
}
}
members = tmpMembers;
} finally {
ResultSet localRS = rs;
// Clear reference to result set
rs = null;
theJDBCUtil.closeJDBCResultSet(localRS);
Statement localStmt = stmt;
// Clear reference to statement
stmt = null;
theJDBCUtil.closeJDBCStatement(localStmt);
}
stmt = conn.prepareStatement(listservQuery);
stmt.setString(1, listservID);
rs = stmt.executeQuery();
if (!rs.next()) {
StringBuffer exceptionBuffer =
new StringBuffer(64)
.append("Could not find listserv record for '")
.append(listservID)
.append("'");
throw new MailetException(exceptionBuffer.toString());
}
membersOnly = rs.getBoolean("members_only");
attachmentsAllowed = rs.getBoolean("attachments_allowed");
replyToList = rs.getBoolean("reply_to_list");
subjectPrefix = rs.getString("subject_prefix");
String address = rs.getString("list_address");
if (address == null) {
listservAddress = null;
} else {
try {
listservAddress = new MailAddress(address);
} catch (ParseException pe) {
//log and ignore
StringBuffer logBuffer =
new StringBuffer(128)
.append("invalid listserv address '")
.append(listservAddress)
.append("' for listserv '")
.append(listservID)
.append("'");
log(logBuffer.toString());
listservAddress = null;
}
}
} catch (SQLException sqle) {
throw new MailetException("Problem loading settings", sqle);
} finally {
theJDBCUtil.closeJDBCResultSet(rs);
theJDBCUtil.closeJDBCStatement(stmt);
theJDBCUtil.closeJDBCConnection(conn);
}
|