Update of /cvsroot/mrpostman/mrpostman/src/org/mrbook/mrpostman/yahoo
In directory sc8-pr-cvs1:/tmp/cvs-serv27390
Modified Files:
YahooMailSession.java
Log Message:
Added unread TOP yahoo option
Index: YahooMailSession.java
===================================================================
RCS file: /cvsroot/mrpostman/mrpostman/src/org/mrbook/mrpostman/yahoo/YahooMailSession.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -C2 -d -r1.20 -r1.21
*** YahooMailSession.java 22 Nov 2003 14:58:44 -0000 1.20
--- YahooMailSession.java 10 Dec 2003 00:35:46 -0000 1.21
***************
*** 64,70 ****
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");
--- 64,71 ----
private static final ModuleOption[] OPTIONS = {
new ModuleOption("yahoo.https", "true"),
! new ModuleOption("yahoo.emptyTrash", "false"),
! new ModuleOption("yahoo.unreadAfterTop", "false")
};
! private static final ModuleInfo MODULE_INFO = new ModuleInfo("yahoo", AUTHORS, "0.7",
"http://mrpostman.sourceforge.net/updates/yahoo", "/en/yahoo/index.html", OPTIONS);
private static Logger logger = Logger.getLogger("org.mrbook.mrpostman.yahoo.YahooMailSession");
***************
*** 79,82 ****
--- 80,84 ----
private boolean useHttps = true;
private boolean emptyTrash = false; //empty trash after collection option - CH 3/10/03
+ private boolean leaveUnreadAfterTOP = false; //mark msg as unread after TOP command - CH 10/12/03
private String trashEmptyUrl = null;
***************
*** 597,601 ****
/* print the header first */
Pattern badHeader1 = Pattern.compile("\\AFrom\\s+");
!
try {
URL url = new URL(baseUrl + bodyPart1 + ((MailIdentifier) (filtereMessageIDS.elementAt(num - 1))).MailID
--- 599,603 ----
/* print the header first */
Pattern badHeader1 = Pattern.compile("\\AFrom\\s+");
!
try {
URL url = new URL(baseUrl + bodyPart1 + ((MailIdentifier) (filtereMessageIDS.elementAt(num - 1))).MailID
***************
*** 611,620 ****
cj.addAll(hrh.getCookieJar());
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
! String line = null;
!
while ((line = br.readLine()) != null) {
if (!badHeader1.matcher(line).find()) {
pw.print(line + "\r\n");
! }
}
/* now the text or body of the message */
--- 613,622 ----
cj.addAll(hrh.getCookieJar());
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
! String line = null;
!
while ((line = br.readLine()) != null) {
if (!badHeader1.matcher(line).find()) {
pw.print(line + "\r\n");
! }
}
/* now the text or body of the message */
***************
*** 641,646 ****
--- 643,711 ----
;
}
+
+ //Depending on option value, we may be required to mark the message as unread after TOP command
+ //we won't do it by default as it is quite expensive...
+ if (leaveUnreadAfterTOP) {
+ markMessageAsUnread(num);
+ }
}
+ protected void markMessageAsUnread(int num) {
+ if ((num > numMessages()) || (num < 1)) {
+ return;
+ }
+ logger.log(Level.INFO, "Marking letter as unread after TOP command: " + num);
+ String bodyPart1 = "/ym/ShowLetter?box=Inbox&MsgId=";
+ /* print the header first */
+ Pattern markUnreadUrlPattern = Pattern.compile("<a href=\"(\\S+)\">Mark as Unread</a>");
+ String unReadUrlStr = null;
+ try {
+ URL url = new URL(baseUrl + bodyPart1 + ((MailIdentifier) (filtereMessageIDS.elementAt(num - 1))).MailID);
+ 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;
+
+ Matcher unReadUrlMatcher = null;
+
+ while ((line = br.readLine()) != null) {
+ unReadUrlMatcher = markUnreadUrlPattern.matcher(line);
+ if (unReadUrlMatcher.find()) {
+ unReadUrlStr = unReadUrlMatcher.group(1);
+ logger.log(Level.FINE, "Found Unread URL: " + unReadUrlStr);
+ }
+ }
+
+ //mark the message as unread again...
+ url = new URL(baseUrl + unReadUrlStr);
+ conn = (HttpURLConnection) url.openConnection();
+ conn.setRequestProperty("User-Agent", UserAgent);
+ conn.setRequestProperty("Accept", "*/*");
+ conn.setRequestProperty("Allowed", "GET HEAD PUT");
+ conn.setInstanceFollowRedirects(false);
+ hrh = new HTTPRedirectHandler(conn);
+ hrh.setCookieJar(cj);
+ hrh.connect();
+ cj.addAll(hrh.getCookieJar());
+ br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
+ line = null;
+
+ while ((line = br.readLine()) != null) {
+ //do nothing
+ }
+
+ } catch (Exception e) {
+ logger.log(Level.SEVERE, "Exception in markMessageAsUnread", e);
+ ;
+ }
+ }
+
public String getUniqueMessageId(int num) throws MailSessionException {
int numMsgs = numMessages();
***************
*** 744,748 ****
useHttps = "true".equalsIgnoreCase(value);
} else if ("yahoo.emptyTrash".equals(optionName)) {
! emptyTrash = "true".equalsIgnoreCase(value);
}
}
--- 809,815 ----
useHttps = "true".equalsIgnoreCase(value);
} else if ("yahoo.emptyTrash".equals(optionName)) {
! emptyTrash = "true".equalsIgnoreCase(value);
! } else if ("yahoo.unreadAfterTop".equals(optionName)) {
! leaveUnreadAfterTOP = "true".equalsIgnoreCase(value);
}
}
|