Hi Mike, Oleg :

I've been trying different things and it seems "MrPostman" (inside www.sf.net ) got me 
a little closer. I can use the following programs and try to log into Yahoo. Although 
I still can't see the logged-in page, but if I supply the wrong Id/password, it will 
tell me, seems to me it's a step closer than what I can get by using HttpClient. 

I hope there is something in MrPostman that HttpClient can absorb so that I only need 
to use HttpClient alone to login. I hope I just need to supply it with an url and 
HttpClient will handle all the troubles for me transparently without me knowing it (or 
is it posibble, just like a browser does ?). Thanks.

I am attaching :

Yahoo_Login.java
YahooMailSession.java

You still need "MrPostman-1.0.3beta2.jar" from the site : www.sf.net  

I tried to attach them to the email, didn't work.

Please let me know if someone get a break through ^_^

Frank

=============================================================================================================================================================

import java.net.*;
import java.io.*;
import com.sun.net.ssl.*;
import java.security.*;
import java.util.*;

public class Yahoo_Login
{
  YahooMailSession Y_M_S=new YahooMailSession();
  
  Yahoo_Login()
  {
    int Result;
    
    try
    {
      Result=Y_M_S.login("javamr","javatest", true);
      Out("Result="+1);
      
    } catch(Exception e) { System.out.println(e); }
    
  }
  
  public static void Out(String message) { System.out.println(message); }

  public static void main(String[] args)
  {
    Yahoo_Login Y_L=new Yahoo_Login();
    
  }
}

=============================================================================================================================================================

/*
 * -*- mode: java; c-basic-indent: 4; indent-tabs-mode: nil -*-
 * :indentSize=4:noTabs=true:tabSize=4:indentOnTab=true:indentOnEnter=true:mode=java:
 * ex: set tabstop=4 expandtab:
 *
 * MrPostman - webmail <-> email gateway
 * Copyright (C) 2002-2003 MrPostman Development Group
 * Projectpage: http://mrbook.org/mrpostman/
 *
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * In particular, this implies that users are responsible for
 * using MrPostman after reading the terms and conditions given
 * by their web-mail provider.
 *
 * You should have received a copy of the GNU General Public License
 * Named LICENSE in the base directory of this distribution,
 * if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

//package org.mrbook.mrpostman.yahoo;

import com.sonalb.net.http.HTTPRedirectHandler;
import com.sonalb.net.http.cookie.CookieJar;

import org.mrbook.mrpostman.MailSessionException;
import org.mrbook.mrpostman.ModuleInfo;
import org.mrbook.mrpostman.ModuleOption;
import org.mrbook.mrpostman.WebMailSession;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;

import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;

import java.util.Iterator;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


public class YahooMailSession extends WebMailSession
{
  public static final String CVSID = "$Id: YahooMailSession.java,v 1.22 2004/02/20 
20:09:42 chris_humphreys Exp $";
  
  /**
   * Our hardcoded ModuleInfo data.
   */
  private static final String[] AUTHORS = {"Hector Urtubia <[EMAIL PROTECTED]>"};
  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");
  private static String httpsLoginURL = "https://login.yahoo.com/config/login";;
  private static String httpLoginURL = "http://login.yahoo.com/config/login";;
  private static String UserAgent = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.4) 
Gecko/20010914";
  private String crumb = null;
  private String baseUrl = null;
  private Vector messageIDS = null;
  private Vector filtereMessageIDS = null;
  private boolean gotNumMessages = false;
  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;
  
  //    private Map cookieJar=null;
  private CookieJar cj = null;
  private boolean authenticated = false;
  private int unread_messages = 0;
  private int number_messages = 0;
  private int limit_number_messages = 350;
  
  public int login(String username, String password, boolean secureLogin)
  {
    String username2 = username.replaceAll("@.+\\Z", "");
    logger.fine("The username will be : " + username2);
    cj = new CookieJar();
    /* we have to construct the POST request */
    String postRequest = createPostRequest(username2, password);
    logger.fine(postRequest);
    
    try
    {
      URL url = null;
      HttpURLConnection conn = null;
      if (useHttps)
      {
        logger.info("Log-in using https");
        url = new URL(httpsLoginURL + "?" + postRequest);
        conn = (HttpURLConnection) url.openConnection();
      } 
      else
      {
        logger.info("Log-in using http");
        url = new URL(httpLoginURL + "?" + postRequest);
        conn = (HttpURLConnection) url.openConnection();
      }
      
      conn.setRequestProperty("User-Agent", UserAgent);
      conn.setRequestProperty("Conten-type", "application/x-www-form-urlencoded");
      conn.setRequestProperty("Accept", "*/*");
      conn.setRequestProperty("Allowed", "GET HEAD PUT");
      conn.setInstanceFollowRedirects(false);
      
      HTTPRedirectHandler hrh = new HTTPRedirectHandler(conn);
      hrh.connect();
      
      conn = (HttpURLConnection) hrh.getConnection();  //this could be either 
HttpURLConnection or HttpsURLConnection
      cj.addAll(hrh.getCookieJar());
      
      BufferedReader rd = new BufferedReader(new 
InputStreamReader(conn.getInputStream()));
      String line;
      Pattern invalidPassword = Pattern.compile("Invalid Password", 
Pattern.CASE_INSENSITIVE);
      Pattern invalidID = Pattern.compile("does not exist", Pattern.CASE_INSENSITIVE);
      Pattern unreadMessagesPattern = Pattern.compile("Inbox\\s\\(([0-9]+)\\)");
      Pattern unreadMessagesPatternOld = Pattern.compile("Inbox\\s\\(([0-9]+)\\)");
      
      Matcher unreadMessagesMatcher = null;
      
      String Result_Str="";
      
      while ((line = rd.readLine()) != null)
      {
        Result_Str+=line+"\n";
//        logger.finest("html: " + line);
        logger.info("html: " + line);
        String line2 = new String(line);
        
        if (invalidID.matcher(line).find())
        {
          logger.warning("ID does not exist");
          return WebMailSession.WMS_LOGIN_FAILED;
        }
        
        if (invalidPassword.matcher(line2).find())
        {
          logger.warning("Invalid Password");
          return WebMailSession.WMS_LOGIN_FAILED;
        }
        
        unreadMessagesMatcher = unreadMessagesPattern.matcher(line2);
        
        if (unreadMessagesMatcher.find())
        {
          unread_messages = (new Integer(unreadMessagesMatcher.group(1))).intValue();
          logger.info("You have " + unread_messages + " unread messages");
        }
        
      }
      rd.close();
      baseUrl = getBaseURL(conn.getURL());
      
      System.out.println("baseUrl="+baseUrl);

//      NM_Lib.Display_HTML_In_Browser(Result_Str);
      
      logger.fine("url: " + baseUrl.toString());
    } 
    catch (Exception e)
    {
      logger.log(Level.SEVERE, "should not happen", e);
      return WebMailSession.WMS_LOGIN_FAILED;
    }
    authenticated = true;
    return WebMailSession.WMS_LOGIN_OK;
  }
  
  private String getBaseURL(URL url)
  {
    Pattern pat = null;
    if (useHttps) { pat = Pattern.compile("(http%3a\\/\\/.*?)(\\/)"); } 
    else { pat = Pattern.compile("(http:\\/\\/.*?)(\\/)"); }
    logger.fine("url: " + url.toString());
    Matcher matcher = pat.matcher(url.toString());
    matcher.reset(url.toString());
    
    if (!matcher.find()) { logger.warning("Invalid URL\n"); }
    
    if (useHttps) { return matcher.group(1).replaceAll("%3a", ":"); } 
    else { return matcher.group(1); }
  }
  
  private String createPostRequest(String username, String password)
  {
    String line = null;
    
    try
    {
      line = URLEncoder.encode(".tries", "UTF-8") + "=" + URLEncoder.encode("1", 
"UTF-8") + "&";
      // line+= URLEncoder.encode(".done","UTF-8") + "=" + URLEncoder.encode("URL to 
go later","UTF-8");
      line += (URLEncoder.encode(".src", "UTF-8") + "=" + URLEncoder.encode("ym", 
"UTF-8") + "&");
      line += (URLEncoder.encode(".us", "UTF-8") + "=" + URLEncoder.encode("ym", 
"UTF-8") + "&");
      line += (URLEncoder.encode(".intl", "UTF-8") + "=" + URLEncoder.encode("us", 
"UTF-8") + "&");
      line += (URLEncoder.encode("login", "UTF-8") + "=" + URLEncoder.encode(username, 
"UTF-8") + "&");
      line += (URLEncoder.encode("passwd", "UTF-8") + "=" + 
URLEncoder.encode(password, "UTF-8"));
    } catch (Exception e)
    {
      logger.log(Level.SEVERE, "should not happen", e);
    }
    return line;
  }
  
  public int numMessages()
  {
    if (gotNumMessages)
    {
      logger.finest("numMessages() - " + filtereMessageIDS.size());
      return filtereMessageIDS.size();
    }
    int start_message = 0;
    int end_message = 0;
    int message_index = 0;
    int inbox_index = 0;
    String inboxPath = "/ym/ShowFolder?box=Inbox&Npos=";
    
    if (!authenticated)
    {
      return -1;
    }
    
    try
    {
      URL url = new URL(baseUrl + inboxPath + "0");
      HttpURLConnection conn = (HttpURLConnection) url.openConnection();
      conn.setRequestProperty("User-Agent", UserAgent);
      // conn.setRequestProperty("Content-type","application/x-www-form-urlencoded");
      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;
      Pattern messageRangePattern = Pattern.compile("Messages (\\d+)-(\\d+) of 
(\\d+)");
      Pattern messageRangePatternOld = Pattern.compile("showing (\\d+)-(\\d+) of 
(\\d+)");
      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;
      
      while ((line = br.readLine()) != null)
      {
        logger.finest("html: " + line);
        matcher = messageRangePattern.matcher(line);
        
        if (matcher.find())
        {
          start_message = (new Integer(matcher.group(1))).intValue();
          end_message = (new Integer(matcher.group(2))).intValue();
          number_messages = (new Integer(matcher.group(3))).intValue();
          logger.info("start/end/number of msgs: " + start_message + " " + end_message 
+ " "
          + number_messages);
        }
        matcher = messageRangePatternOld.matcher(line);
        
        if (matcher.find())
        {
          start_message = (new Integer(matcher.group(1))).intValue();
          end_message = (new Integer(matcher.group(2))).intValue();
          number_messages = (new Integer(matcher.group(3))).intValue();
          logger.info("start/end/number of msgs: " + start_message + " " + end_message 
+ " "
          + number_messages);
        }
        matcher = noMessagesPattern.matcher(line);
        
        if (matcher.find())
        {
          number_messages = 0;
          logger.info("No messages");
          return 0;
        }
        matcher = noMessagesPattern.matcher(line);
        
        if (matcher.find())
        {
          number_messages = 0;
          logger.info("No messages");
          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);
          }
        }
        
      }
      
      // Now that we know the total number of messages, parse the message
      // ID's
      if (messageIDS == null)
      {
        messageIDS = new Vector();
      }
      
      while ((message_index < number_messages) && (message_index < 
limit_number_messages))
      {
        url = new URL(baseUrl + inboxPath + inbox_index);
        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()));
        Pattern msgidPattern = Pattern.compile("ShowLetter\\?MsgId=([0-9_\\-]+)");
        Pattern flaggedPattern = Pattern.compile("flag\\.gif");
        Pattern unreadPattern = Pattern.compile("\\<b\\>");
        Pattern sizePattern = Pattern.compile("(\\<b\\>|\\A\\s+|\\A)([0-9]+)(b|k)");
        Pattern attchPattern = Pattern.compile("\\#attachments");
        Pattern crumbPattern = Pattern.compile("name=\".crumb\" value=\"(.*?)\"");
        Matcher crumbMatcher = null;
        Matcher attchMatcher = null;
        boolean flagged = false;
        boolean have_size = false;
        boolean have_msgid = false;
        MailIdentifier mi = new MailIdentifier();
        
        while ((line = br.readLine()) != null)
        {
          crumbMatcher = crumbPattern.matcher(line);
          if (crumbMatcher.find())
          {
            crumb = crumbMatcher.group(1);
            logger.info("Found crumb = " + crumb);
          }
          
          matcher = msgidPattern.matcher(line);
          
          if (matcher.find())
          {
            if (!foundID(matcher.group(1)))
            {
              logger.warning("Found a new message id: " + matcher.group(1));
              attchMatcher = attchPattern.matcher(line);
              
              if (attchMatcher.find())
              {
                // do nothing
              } else if (!have_msgid && have_size)
              {
                logger.finest("!have_msgid && have_size");
                mi.MailID = new String(matcher.group(1));
                mi.flagged = flagged;
                flagged = false;
                mi.unread = false;
                matcher = unreadPattern.matcher(line);
                
                if (matcher.find())
                {
                  mi.unread = true;
                }
                line = br.readLine();
                matcher = unreadPattern.matcher(line);
                
                if (matcher.find())
                {
                  mi.unread = true;
                }
                messageIDS.add(mi);
                message_index++;
                logger.fine("MsgId: " + mi + " added to message list (code section 
a)");
                mi = new MailIdentifier();
                have_msgid = false;
                have_size = false;
              } else if (!have_msgid && !have_size)
              {
                logger.finest("!have_msgid && !have_size");
                mi.MailID = new String(matcher.group(1));
                mi.flagged = flagged;
                flagged = false;
                mi.unread = false;
                matcher = unreadPattern.matcher(line);
                
                if (matcher.find())
                {
                  mi.unread = true;
                }
                line = br.readLine();
                matcher = unreadPattern.matcher(line);
                
                if (matcher.find())
                {
                  mi.unread = true;
                }
                have_msgid = true;
              }
            }
          }
          matcher = flaggedPattern.matcher(line);
          
          if (matcher.find())
          {
            logger.info("flag");
            flagged = true;
          }
          matcher = sizePattern.matcher(line);
          
          if (matcher.find())
          {
            logger.fine(matcher.group(0));
            logger.fine(line);
            int sizenn = (new Integer(matcher.group(2))).intValue();
            
            if (matcher.group(3).equals("k"))
            {
              sizenn *= 1024;
            }
            
            if (!have_msgid && !have_size)
            {
              mi.size = sizenn;
              have_size = true;
            } else if (have_msgid && !have_size)
            {
              logger.finest("have_msgid && !have_size");
              mi.size = sizenn;
              messageIDS.add(mi);
              logger.fine("MsgId: " + mi + " added to message list (code section b)");
              mi = new MailIdentifier();
              message_index++;
              have_msgid = false;
              have_size = false;
              flagged = false;
            }
          }
        }
        inbox_index++;
      }
    } catch (Exception e)
    {
      logger.log(Level.SEVERE, "should not happen", e);
    }
    
    if (filtereMessageIDS == null)
    {
      filtereMessageIDS = new Vector();
    }
    
    for (Iterator i = messageIDS.iterator(); i.hasNext();)
    {
      MailIdentifier mi = (MailIdentifier) i.next();
      
      // here is the filter
      // the default is if the message is unread
      if (mi.unread)
      {
        filtereMessageIDS.add(mi);
      }
    }
    gotNumMessages = true;
    if (filtereMessageIDS.size() == 0)
    {
      logger.info("No messages");
    }
    logger.finest("numMessages() - " + filtereMessageIDS.size());
    return filtereMessageIDS.size();
  }
  
  private boolean foundID(String messageID)
  {
    for (Iterator i = messageIDS.iterator(); i.hasNext();)
    {
      MailIdentifier mi = (MailIdentifier) i.next();
      
      if (mi.MailID.equals(messageID))
      {
        return true;
      }
    }
    return false;
  }
  
  public void printMessageNumber(int number)
  {
    if (number >= number_messages)
    {
      return;
    }
    String bodyPart1 = "/ym/ShowLetter?box=Inbox&MsgId=";
    String bodyPart2 = "&bodyPart=";
    
    /* print the header first */
    try
    {
      URL url = new URL(baseUrl + bodyPart1 + (String) messageIDS.elementAt(number) + 
bodyPart2 + "HEADER");
      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);
      }
      /* now the text or body of the message */
      url = new URL(baseUrl + bodyPart1 + (String) messageIDS.elementAt(number) + 
bodyPart2 + "TEXT");
      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)
      {
        logger.finest("html: " + line);
      }
    } catch (Exception e)
    {
      logger.log(Level.SEVERE, "should not happen", e);
    }
  }
  
  // num is not zero based!!! range is from 1 -> size
  public int getSizeOfMessage(int num)
  {
    if (filtereMessageIDS == null)
    {
      numMessages();
    }
    
    if ((num > filtereMessageIDS.size()) || (num < 1))
    {
      return -1;
    }
    MailIdentifier mi = (MailIdentifier) filtereMessageIDS.elementAt(num - 1);
    return mi.size;
  }
  
  //one based
  public void outputMessage(int num, PrintWriter pw)
  {
    if ((num > numMessages()) || (num < 1))
    {
      return;
    }
    String bodyPart1 = "/ym/ShowLetter?box=Inbox&MsgId=";
    String bodyPart2 = "&bodyPart=";
    /* print the header first */
    Pattern badHeader1 = Pattern.compile("\\AFrom\\s+");
    
    try
    {
      URL url = new URL(baseUrl + bodyPart1 + ((MailIdentifier) 
(filtereMessageIDS.elementAt(num - 1))).MailID
      + bodyPart2 + "HEADER");
      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)
      {
        if (!badHeader1.matcher(line).find())
        {
          pw.print(line + "\r\n");
        }
      }
      /* now the text or body of the message */
      url = new URL(baseUrl + bodyPart1 + ((MailIdentifier) 
(filtereMessageIDS.elementAt(num - 1))).MailID
      + bodyPart2 + "TEXT");
      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)
      {
        pw.print(line + "\r\n");
      }
    } catch (Exception e)
    {
      logger.log(Level.SEVERE, "should not happen", e);
    }
  }
  
  
  //one based
  public void outputLinesMessage(int num, PrintWriter pw, int numLines)
  {
    if ((num > numMessages()) || (num < 1))
    {
      return;
    }
    String bodyPart1 = "/ym/ShowLetter?box=Inbox&MsgId=";
    String bodyPart2 = "&bodyPart=";
    int linesSent = 0;
    /* print the header first */
    Pattern badHeader1 = Pattern.compile("\\AFrom\\s+");
    
    try
    {
      URL url = new URL(baseUrl + bodyPart1 + ((MailIdentifier) 
(filtereMessageIDS.elementAt(num - 1))).MailID
      + bodyPart2 + "HEADER");
      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)
      {
        if (!badHeader1.matcher(line).find())
        {
          pw.print(line + "\r\n");
        }
      }
      /* now the text or body of the message */
      url = new URL(baseUrl + bodyPart1 + ((MailIdentifier) 
(filtereMessageIDS.elementAt(num - 1))).MailID
      + bodyPart2 + "TEXT");
      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) && (linesSent < numLines))
      {
        pw.print(line + "\r\n");
        linesSent++;
      }
    } catch (Exception e)
    {
      logger.log(Level.SEVERE, "should not happen", e);
      ;
    }
    
    //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();
    if ((num > numMsgs) || (num < 1))
    {
      logger.info("getUniqueMessageId - id out of range (" + num + "/" + numMsgs);
      return "";
    }
    
    if (messageIDS == null)
    {
      return "";
    }
    MailIdentifier mi = (MailIdentifier) messageIDS.elementAt(num - 1);
    return mi.MailID;
  }
  
  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);
      }
    }
  }
  
  public boolean deleteMessage(int number) throws MailSessionException
  {
    if ((number > numMessages()) || (number < 1))
    {
      logger.info("DeleteMessage - id out of range (" + number + "/" + number_messages 
+ ")");
      return false;
    }
    logger.info("Deleting message id: " + number + " " + ((MailIdentifier) 
(filtereMessageIDS.elementAt(number - 1))).MailID);
    String bodyPart1 = "/ym/ShowFolder?box=Inbox&DEL=Delete&Mid=";
    
    /* print the header first */
    try
    {
      URL url = new URL(baseUrl + bodyPart1 + ((MailIdentifier) 
(filtereMessageIDS.elementAt(number - 1))).MailID + "&.crumb=" + crumb); //(String)( 
messageIDS.elementAt(number)));
      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); }
    } catch (Exception e)
    {
      logger.log(Level.SEVERE, "should not happen", e);
    }
    return true;
  }
  
  public String getModuleName()
  {
    return MODULE_INFO.getModuleID();
  }
  
  public String[] getRecognizedExtensions()
  {
    String[] extensions = {"@yahoo.com", "@yahoo.com.au", "@yahoo.co.uk", "@yahoo.ca", 
"@yahoo.fr", "@yahoo.com.hk", "@yahoo.de", "@yahoo.es", "@yahoo.co.in"};
    return extensions;
  }
  
  /**
   * Return the module info.
   */
  public ModuleInfo getModuleInfo() { return MODULE_INFO; }
  
  /**
   * Set a module option with a value from the preferences or from the GUI
   * Currently understood options are listed in the MODULE_INFO specification above.
   */
  public void setOption(String optionName, String value)
  {
    if ("yahoo.https".equals(optionName)) { useHttps = "true".equalsIgnoreCase(value); 
} 
    else if ("yahoo.emptyTrash".equals(optionName)) { emptyTrash = 
"true".equalsIgnoreCase(value); } 
    else if ("yahoo.unreadAfterTop".equals(optionName)) { leaveUnreadAfterTOP = 
"true".equalsIgnoreCase(value); }
  }
}

class MailIdentifier
{
  String MailID = null;
  boolean unread = false;
  boolean flagged = false;
  int size;
  
  public String toString() { return new String("MailID=" + MailID + ",  unread=" + 
unread + "   flagged=" + flagged + "    size=" + size); }
}
=============================================================================================================================================================

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to