Update of /cvsroot/mrpostman/mrpostman/src/org/mrbook/mrpostman/yahoo
In directory sc8-pr-cvs1:/tmp/cvs-serv19719/src/org/mrbook/mrpostman/yahoo
Modified Files:
YahooMailSession.java
Log Message:
Yahoo Trash empty
Index: YahooMailSession.java
===================================================================
RCS file: /cvsroot/mrpostman/mrpostman/src/org/mrbook/mrpostman/yahoo/YahooMailSession.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -d -r1.16 -r1.17
*** YahooMailSession.java 22 Jul 2003 12:45:18 -0000 1.16
--- YahooMailSession.java 3 Oct 2003 13:53:17 -0000 1.17
***************
*** 63,69 ****
private static final String[] AUTHORS = {"Hector Urtubia <ur...@mr...>"};
private static final ModuleOption[] OPTIONS = {
! new ModuleOption("yahoo.https", "true")
};
! private static final ModuleInfo MODULE_INFO = new ModuleInfo("yahoo", AUTHORS, "0.5",
"http://mrpostman.sourceforge.net/updates/yahoo", "/en/yahoo/index.html", OPTIONS);
private static Logger logger = Logger.getLogger("org.mrbook.mrpostman.yahoo.YahooMailSession");
--- 63,70 ----
private static final String[] AUTHORS = {"Hector Urtubia <ur...@mr...>"};
private static final ModuleOption[] OPTIONS = {
! new ModuleOption("yahoo.https", "true"),
! new ModuleOption("yahoo.emptyTrash", "false")
};
! private static final ModuleInfo MODULE_INFO = new ModuleInfo("yahoo", AUTHORS, "0.6",
"http://mrpostman.sourceforge.net/updates/yahoo", "/en/yahoo/index.html", OPTIONS);
private static Logger logger = Logger.getLogger("org.mrbook.mrpostman.yahoo.YahooMailSession");
***************
*** 77,81 ****
private boolean gotNumMessages = false;
private boolean useHttps = true;
!
// private Map cookieJar=null;
private CookieJar cj = null;
--- 78,84 ----
private boolean gotNumMessages = false;
private boolean useHttps = true;
! private boolean emptyTrash = false; //empty trash after collection option - CH 3/10/03
! private String trashEmptyUrl = null;
!
// private Map cookieJar=null;
private CookieJar cj = null;
***************
*** 102,108 ****
} else {
logger.info("Log-in using http");
! url = new URL(httpLoginURL + "?" + postRequest);
conn = (HttpURLConnection) url.openConnection();
! }
// conn.setRequestMethod("POST");
--- 105,111 ----
} else {
logger.info("Log-in using http");
! url = new URL(httpLoginURL + "?" + postRequest);
conn = (HttpURLConnection) url.openConnection();
! }
// conn.setRequestMethod("POST");
***************
*** 119,123 ****
// wr.flush();
// wr.close();
!
/* get the cookies */
/*getCookies(conn);
--- 122,126 ----
// wr.flush();
// wr.close();
!
/* get the cookies */
/*getCookies(conn);
***************
*** 137,141 ****
Pattern unreadMessagesPattern = Pattern.compile("Inbox\\s\\(([0-9]+)\\)");
Pattern unreadMessagesPatternOld = Pattern.compile("Inbox\\s\\(([0-9]+)\\)");
!
Matcher unreadMessagesMatcher = null;
--- 140,144 ----
Pattern unreadMessagesPattern = Pattern.compile("Inbox\\s\\(([0-9]+)\\)");
Pattern unreadMessagesPatternOld = Pattern.compile("Inbox\\s\\(([0-9]+)\\)");
!
Matcher unreadMessagesMatcher = null;
***************
*** 148,158 ****
return WebMailSession.WMS_LOGIN_FAILED;
}
!
!
if (invalidPassword.matcher(line2).find()) {
logger.warning("Invalid Password");
return WebMailSession.WMS_LOGIN_FAILED;
}
!
unreadMessagesMatcher = unreadMessagesPattern.matcher(line2);
;
--- 151,161 ----
return WebMailSession.WMS_LOGIN_FAILED;
}
!
!
if (invalidPassword.matcher(line2).find()) {
logger.warning("Invalid Password");
return WebMailSession.WMS_LOGIN_FAILED;
}
!
unreadMessagesMatcher = unreadMessagesPattern.matcher(line2);
;
***************
*** 162,165 ****
--- 165,169 ----
logger.info("You have " + unread_messages + " unread messages");
}
+
}
rd.close();
***************
*** 188,192 ****
logger.warning("Invalid URL\n");
}
!
if (useHttps) {
return matcher.group(1).replaceAll("%3a", ":");
--- 192,196 ----
logger.warning("Invalid URL\n");
}
!
if (useHttps) {
return matcher.group(1).replaceAll("%3a", ":");
***************
*** 246,249 ****
--- 250,257 ----
Pattern noMessagesPattern = Pattern.compile("This\\s*folder\\s*has\\s*no\\s*messages");
Pattern noMessagesPatternOld = Pattern.compile("Folder\\s*Inbox\\s*has\\s*no\\s+");
+ //Added Trash Empty link pattern - CH 3/10/03
+ Pattern trashPattern = Pattern.compile("<a href=\"(\\S+)\">Trash</a>");
+ Pattern trashEmptyPattern = Pattern.compile("<a href=\"(\\S+)\">Empty</a>");
+
Matcher matcher = null;
***************
*** 280,283 ****
--- 288,313 ----
return 0;
}
+
+ //check for empty trash link - CH 03/10/03
+ //leave this at the end of the loop
+ matcher = trashPattern.matcher(line);
+ if (matcher.find()) {
+ logger.fine("Found Trash folder link, checking for empty url...");
+
+ //it could be on this line or the next line...
+ matcher = trashEmptyPattern.matcher(line);
+ if (!matcher.find()) {
+ line = br.readLine();
+ logger.finest("html: " + line);
+ if (line != null) {
+ matcher = trashEmptyPattern.matcher(line);
+ }
+ }
+ if (matcher.find()) {
+ trashEmptyUrl = matcher.group(1);
+ logger.fine("Found Trash Empty URL: " + trashEmptyUrl);
+ }
+ }
+
}
***************
*** 319,323 ****
logger.info("Found crumb = " + crumb);
}
!
matcher = msgidPattern.matcher(line);
--- 349,353 ----
logger.info("Found crumb = " + crumb);
}
!
matcher = msgidPattern.matcher(line);
***************
*** 626,630 ****
public void quitSession() {
! /* do nothing */
}
--- 656,687 ----
public void quitSession() {
! //Empty Trash folder if option is enabled and we have the url - ch 03/10/03
! if (emptyTrash && trashEmptyUrl != null) {
! logger.finest("About to Empty Trash....");
!
! try {
! URL url = new URL(baseUrl + trashEmptyUrl);
! logger.finest(url.toString());
! HttpURLConnection conn = (HttpURLConnection) url.openConnection();
! conn.setRequestProperty("User-Agent", UserAgent);
! conn.setRequestProperty("Accept", "*/*");
! conn.setRequestProperty("Allowed", "GET HEAD PUT");
! conn.setInstanceFollowRedirects(false);
! HTTPRedirectHandler hrh = new HTTPRedirectHandler(conn);
! hrh.setCookieJar(cj);
! hrh.connect();
! cj.addAll(hrh.getCookieJar());
! BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
! String line = null;
!
! while ((line = br.readLine()) != null) {
! logger.finest("html: " + line);
! }
!
! logger.finest("Trash Emptied.");
! } catch (Exception e) {
! logger.log(Level.SEVERE, "Exception whilst emptying trash!", e);
! }
! }
}
***************
*** 684,687 ****
--- 741,746 ----
if ("yahoo.https".equals(optionName)) {
useHttps = "true".equalsIgnoreCase(value);
+ } else if ("yahoo.emptyTrash".equals(optionName)) {
+ emptyTrash = "true".equalsIgnoreCase(value);
}
}
|