|
From: <de...@us...> - 2003-10-13 07:24:47
|
Update of /cvsroot/babeldoc/babeldoc/modules/scanner/src/com/babeldoc/scanner/worker
In directory sc8-pr-cvs1:/tmp/cvs-serv14858/babeldoc/modules/scanner/src/com/babeldoc/scanner/worker
Modified Files:
MailboxScanner.java
Log Message:
Applying patch sent by Michael Ansley <mic...@ze...>
for RFE #753908 (filters in MailboxScanner)
Index: MailboxScanner.java
===================================================================
RCS file: /cvsroot/babeldoc/babeldoc/modules/scanner/src/com/babeldoc/scanner/worker/MailboxScanner.java,v
retrieving revision 1.28
retrieving revision 1.29
diff -C2 -d -r1.28 -r1.29
*** MailboxScanner.java 3 Oct 2003 13:05:45 -0000 1.28
--- MailboxScanner.java 13 Oct 2003 07:24:39 -0000 1.29
***************
*** 74,77 ****
--- 74,78 ----
import java.util.Properties;
+ import javax.mail.Address;
import javax.mail.BodyPart;
import javax.mail.Flags;
***************
*** 84,87 ****
--- 85,91 ----
import javax.mail.Store;
+ import java.util.regex.Pattern;
+ import java.util.regex.Matcher;
+
import com.babeldoc.core.I18n;
import com.babeldoc.core.option.ConfigOption;
***************
*** 108,111 ****
--- 112,118 ----
public static final String PASSWORD = "password";
public static final String GET_FROM = "getFrom";
+ public static final String FROM_FILTER = "fromFilter";
+ public static final String TO_FILTER = "toFilter";
+ public static final String SUBJECT_FILTER = "subjectFilter";
//Values for getFrom attribute
***************
*** 131,134 ****
--- 138,145 ----
public static final String SCAN_TO_KEY = "name";
+ private String fromFilter;
+ private String toFilter;
+ private String subjectFilter;
+
public MailboxScanner() {
super(new MailboxScannerInfo());
***************
*** 145,148 ****
--- 156,160 ----
Store store = null;
Session session = null;
+
try {
Properties props = new Properties();
***************
*** 152,161 ****
folder = store.getFolder(folder_);
folder.open(Folder.READ_WRITE);
Message[] messages = folder.getMessages();
for (int i = 0; i < messages.length; i++) {
! processMessage(messages[i]);
! deleteMessage(messages[i]);
! }
! } catch (Exception x) {
throw new ScannerException(
I18n.get("scanner.MailboxScanner.error.scanning"),
--- 164,182 ----
folder = store.getFolder(folder_);
folder.open(Folder.READ_WRITE);
+
Message[] messages = folder.getMessages();
+
+ // Get the filter parameter values
+ addFilter(FROM_FILTER);
+ addFilter(TO_FILTER);
+ addFilter(SUBJECT_FILTER);
+
for (int i = 0; i < messages.length; i++) {
! if (matchMessage(messages[i])) {
! processMessage(messages[i]);
! deleteMessage(messages[i]);
! }
! }
! } catch (Exception x) {
throw new ScannerException(
I18n.get("scanner.MailboxScanner.error.scanning"),
***************
*** 176,179 ****
--- 197,259 ----
/**
+ * Test a message against a set of filters.
+ * <p>
+ * This method currently only allows regex filters,
+ * only on the three specified fields, and only ORs them.
+ * The design is tied to the filter implementation in ScannerWorker
+ * so changing the ORing will involve changes to ScannerWorker.
+ *
+ * @param message the message to be tested against the current
+ * set of filters
+ * @return boolean true if the message matches any of the
+ * current filters
+ * @see Message ScannerWorker
+ */
+ private boolean matchMessage(Message m) throws javax.mail.MessagingException {
+
+ boolean fromMatch = false;
+ boolean toMatch = false;
+ boolean subjectMatch = false;
+
+ // Check for a match in the recipients
+ Address[] from = m.getFrom();
+ for (int j = 0; j < from.length; j++) {
+ if (getLog().isDebugEnabled()) {
+ getLog().logDebug("Testing " + from[j].toString() + " against " + getFilter(FROM_FILTER));
+ }
+ if (acceptEntry(TO_FILTER, from[j].toString())) {
+ fromMatch = true;
+ }
+ if (getLog().isDebugEnabled()) {
+ getLog().logDebug("Result: " + new Boolean(fromMatch).toString());
+ }
+ }
+
+ // Check for a match in the recipients
+ Address[] to = m.getRecipients(Message.RecipientType.TO);
+ for (int j = 0; j < to.length; j++) {
+ if (getLog().isDebugEnabled()) {
+ getLog().logDebug("Testing " + to[j].toString() + " against " + getFilter(TO_FILTER));
+ }
+ if (acceptEntry(TO_FILTER, to[j].toString())) {
+ toMatch = true;
+ }
+ if (getLog().isDebugEnabled()) {
+ getLog().logDebug("Result: " + new Boolean(toMatch).toString());
+ }
+ }
+
+ if (getLog().isDebugEnabled()) {
+ getLog().logDebug("Testing " + m.getSubject().toString() + " against " + getFilter(SUBJECT_FILTER));
+ }
+ subjectMatch = acceptEntry(SUBJECT_FILTER, m.getSubject());
+ if (getLog().isDebugEnabled()) {
+ getLog().logDebug("Result: " + new Boolean(subjectMatch).toString());
+ }
+
+ return (fromMatch && toMatch && subjectMatch);
+ }
+
+ /**
* Setup the options. Each of the options lives in the hashtable held by the
* superclass
***************
*** 187,190 ****
--- 267,273 ----
username = this.getInfo().getStrValue(USERNAME);
password = this.getInfo().getStrValue(PASSWORD);
+ fromFilter = this.getInfo().getStrValue(FROM_FILTER);
+ toFilter = this.getInfo().getStrValue(TO_FILTER);
+ subjectFilter = this.getInfo().getStrValue(SUBJECT_FILTER);
//Dejan 03.10.2002.
***************
*** 412,415 ****
--- 495,522 ----
false,
I18n.get("scanner.MailboxScannerInfo.option.getFrom")));
+
+ options.add(
+ new ConfigOption(
+ MailboxScanner.FROM_FILTER,
+ IConfigOptionType.STRING,
+ null,
+ true,
+ I18n.get("scanner.MailboxScannerInfo.option.fromFilter")));
+
+ options.add(
+ new ConfigOption(
+ MailboxScanner.TO_FILTER,
+ IConfigOptionType.STRING,
+ null,
+ true,
+ I18n.get("scanner.MailboxScannerInfo.option.toFilter")));
+
+ options.add(
+ new ConfigOption(
+ MailboxScanner.SUBJECT_FILTER,
+ IConfigOptionType.STRING,
+ null,
+ true,
+ I18n.get("scanner.MailboxScannerInfo.option.subjectFilter")));
return options;
|