com.arsdigita.acs.spam
Class Spam

java.lang.Object
  |
  +--com.arsdigita.acs.spam.Spam

public class Spam
extends Object

Utility classes and procedural abstractions for spam.


Constructor Summary
Spam()
           
 
Method Summary
static int checkpointLoggingFrequency()
          Checkpoint the last user_id message was sent to, every n msgs
static void checkSpamDropZone()
          Look for a set of files with names specified from the daily_spam_files table.
static String createMultiPartHtmlMessageBody(String qp_body_plain, String qp_body_html)
          Creates a multipart/alternative MIME message with a plain text part and HTML part The two parts should be passed in encoded as quoted-printable text.
static String dateWidget(String column)
          Return html code fragment for date input
static String encodeQuotedPrintable(String msg)
          Replaces/removes bad characters from msg
static String fileLocation(String filename)
          Returns the absolute path to the spam file.
static String getDaemonEnabledP()
          Returns the state of the spam daemon.
static String getEmailSendingEnabledP()
          Returns the state of sending spam.
static String getSpamFromFilesystem(String filename)
          Returns the file from the dropzone as a string.
static String getUseBulkmailP()
          Returns the state of using bulkmail.
static String htmlSelectValueOptions(String[] option, String[] value, String selected_value)
          Generate html option tags with values for an html selection widget.
static String htmlSelectValueOptions(String sql, String option, String value, String selected_value)
          Generate html option tags with values for an html selection widget.
static String integerOptionList(int begin, int end, String selected_value)
          Returns html code fragment for an option list of integer values
static String postNewSpamMessage(String spam_id, String template_p, String from_address, String title, String body_plain, String body_html, String body_aol, String target_users_description, String target_users_query, String send_date, String creation_user, String status)
          Insert a message to be sent by the spam daemon at a scheduled time send_date.
static String readFileAsString(String filename)
          Reads the file and returns the contents as a string
static String removalBlurb(String subsection, String filetype)
          Gets the standard site-wide or subsection-specific removal blurb, for attaching to outgoing email.
static String sanitizeFilename(String filename)
          Remove any pathname metachars from filename, allow only a very clean set of characters
static int sendMsgToRecipients(String recipients_query, String spam_id, String from_address, String body_plain, String body_html, String body_aol, AdSet msg_plain_headers, AdSet msg_html_headers, AdSet msg_aol_headers, String template_p, String title, String bulkmail_id)
          Sends out a spam for spam_id.
static String sendScheduledSpamMessages()
          Calls on the spam daemon to send out all spam.
static void sendSpamMessage(AdSet spam_row_set)
          Extract the msg bodies and target recipients list query from the spam msg, and send email to the recipients.
static void setDaemonActive(String val)
          Enable/disable the spam daemon.
static void setEmailSending(String val)
          Enable/disable the sending of spam.
static void setUseBulkMailP(String val)
          Enable/disable use of bulk mailer for sending of spam.
static String spamMimeBoundary()
          Really, this should make sure to generate a boundary string that does not appear in the content.
static String systemDefaultFromAddress()
          Returns the default from address for spam messages set in the parameters file
static String timeWidget(String column)
          Returns html code fragment for time input
static String userClassDescription(AdSet setid)
          Takes an AdSet of key/value pairs and produces a human-readable description of the class of users specified.
static Vector userClassParameters()
          Returns the list of parameter var names used to define a user class.
static String userClassQuery(AdSet setid)
          Takes an AdSet of key/value pairs and produces a query for the class of users specified (one user per row returned).
static String verifyDate(AdSet date)
          Takes date values from an AdSet and checks that they are valid.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Spam

public Spam()
Method Detail

getDaemonEnabledP

public static String getDaemonEnabledP()
Returns the state of the spam daemon.

getEmailSendingEnabledP

public static String getEmailSendingEnabledP()
Returns the state of sending spam.

getUseBulkmailP

public static String getUseBulkmailP()
Returns the state of using bulkmail.

setEmailSending

public static void setEmailSending(String val)
Enable/disable the sending of spam.

setDaemonActive

public static void setDaemonActive(String val)
Enable/disable the spam daemon.

setUseBulkMailP

public static void setUseBulkMailP(String val)
Enable/disable use of bulk mailer for sending of spam.

sendScheduledSpamMessages

public static String sendScheduledSpamMessages()
                                        throws SQLException,
                                               ACSException,
                                               FileNotFoundException,
                                               IOException
Calls on the spam daemon to send out all spam.

sendSpamMessage

public static void sendSpamMessage(AdSet spam_row_set)
                            throws SQLException
Extract the msg bodies and target recipients list query from the spam msg, and send email to the recipients.
Parameters:
spam_row_set - Contains a spam row from spam_history.

timeWidget

public static String timeWidget(String column)
                         throws SQLException,
                                ACSException
Returns html code fragment for time input
Parameters:
column - The base name for the input variables in a form.

dateWidget

public static String dateWidget(String column)
                         throws SQLException,
                                ACSException
Return html code fragment for date input
Parameters:
column - The base name for the input variables in a form.

htmlSelectValueOptions

public static String htmlSelectValueOptions(String sql,
                                            String option,
                                            String value,
                                            String selected_value)
                                     throws SQLException,
                                            ACSException
Generate html option tags with values for an html selection widget. If select_option is passed and there exists a value for it in the values list, this option will be marked as selected.
Parameters:
sql - The sql query used to obtain values
option - The column from sql to use as the value of the option.
value - The column from sql to use as the name of the option.
selected_value - The value to mark as selected.

htmlSelectValueOptions

public static String htmlSelectValueOptions(String[] option,
                                            String[] value,
                                            String selected_value)
Generate html option tags with values for an html selection widget. If select_option is passed and there exists a value for it in the values list, this option will be marked as selected.
Parameters:
option - An array containing the values for each option.
value - An array contaiing the names for each option.
selected_value - The value to mark as selected.

verifyDate

public static String verifyDate(AdSet date)
                         throws SQLException,
                                ACSException
Takes date values from an AdSet and checks that they are valid.
Parameters:
date - An AdSet containing "year", "month", and "day" fields.

integerOptionList

public static String integerOptionList(int begin,
                                       int end,
                                       String selected_value)
Returns html code fragment for an option list of integer values
Parameters:
begin - The begin number for option list.
end - The end number for the option list.
selected_value - the value to mark as selected.

postNewSpamMessage

public static String postNewSpamMessage(String spam_id,
                                        String template_p,
                                        String from_address,
                                        String title,
                                        String body_plain,
                                        String body_html,
                                        String body_aol,
                                        String target_users_description,
                                        String target_users_query,
                                        String send_date,
                                        String creation_user,
                                        String status)
                                 throws DataSourceException,
                                        ACSException
Insert a message to be sent by the spam daemon at a scheduled time send_date.
Parameters:
spam_id - Spam_id of the message.
template_p - Is this message in template format?
from_address - Address to send from.
title - Title of the spam.
body_plain - Message body for plain messages.
body_html - Message body for html messages.
body_aol - Message body for aol messages.
target_users_description - Description for the group of users to send spam to.
target_users_query - Query that returns the group of users to spam.
send_date - A string of the form "YYYY-MM-DD HH24:MI:SS" or else an empty string.
creation_user - User_id of creator.
status - Status of spam state.
Returns:
Return "0" if no errors, else returns the error message.

userClassParameters

public static Vector userClassParameters()
Returns the list of parameter var names used to define a user class.

userClassDescription

public static String userClassDescription(AdSet setid)
                                   throws ACSException,
                                          SQLException
Takes an AdSet of key/value pairs and produces a human-readable description of the class of users specified.

userClassQuery

public static String userClassQuery(AdSet setid)
                             throws SQLException,
                                    ACSException
Takes an AdSet of key/value pairs and produces a query for the class of users specified (one user per row returned).
Parameters:
set_id - An AdSet containing all the parameters of the user class.
Returns:
Returns an sql query string that returns the users to spam.

sanitizeFilename

public static String sanitizeFilename(String filename)
Remove any pathname metachars from filename, allow only a very clean set of characters
Parameters:
filename - The filename to sanitize.

fileLocation

public static String fileLocation(String filename)
Returns the absolute path to the spam file.
Parameters:
filename - The name of the file.
Returns:
Spam dropzone directory with filename appended to the end.

getSpamFromFilesystem

public static String getSpamFromFilesystem(String filename)
                                    throws FileNotFoundException,
                                           IOException
Returns the file from the dropzone as a string.
Parameters:
filename - The name of the file.
Returns:
The contents of the file from the dropzone as a string.

checkSpamDropZone

public static void checkSpamDropZone()
                              throws SQLException,
                                     ACSException,
                                     FileNotFoundException,
                                     IOException
Look for a set of files with names specified from the daily_spam_files table.

spamMimeBoundary

public static String spamMimeBoundary()
Really, this should make sure to generate a boundary string that does not appear in the content.

checkpointLoggingFrequency

public static int checkpointLoggingFrequency()
Checkpoint the last user_id message was sent to, every n msgs

sendMsgToRecipients

public static int sendMsgToRecipients(String recipients_query,
                                      String spam_id,
                                      String from_address,
                                      String body_plain,
                                      String body_html,
                                      String body_aol,
                                      AdSet msg_plain_headers,
                                      AdSet msg_html_headers,
                                      AdSet msg_aol_headers,
                                      String template_p,
                                      String title,
                                      String bulkmail_id)
                               throws SQLException
Sends out a spam for spam_id.

encodeQuotedPrintable

public static String encodeQuotedPrintable(String msg)
Replaces/removes bad characters from msg
Parameters:
msg - The message to encode

removalBlurb

public static String removalBlurb(String subsection,
                                  String filetype)
Gets the standard site-wide or subsection-specific removal blurb, for attaching to outgoing email. txt=plain, htm=html mail, aol = aol mail
Parameters:
subsection -  
filetype -  

readFileAsString

public static String readFileAsString(String filename)
                               throws FileNotFoundException,
                                      IOException
Reads the file and returns the contents as a string
Parameters:
filename - The file to read
Returns:
The contents of the file as a string.

systemDefaultFromAddress

public static String systemDefaultFromAddress()
Returns the default from address for spam messages set in the parameters file

createMultiPartHtmlMessageBody

public static String createMultiPartHtmlMessageBody(String qp_body_plain,
                                                    String qp_body_html)
Creates a multipart/alternative MIME message with a plain text part and HTML part The two parts should be passed in encoded as quoted-printable text.
Parameters:
qp_body_plain - Alternative plain message
qp_body_html - Alternative html message