/* * GmailHelper.java * * Created on November 18, 2005, 11:27 AM * * To change this template, choose Tools | Template Manager * and open the template in the editor. */ package gmailchecker.common; import gmailchecker.common.GmailCountUsage; import java.io.IOException; import java.util.ArrayList; import java.util.Iterator; import siuying.gm.GMConnector; import siuying.gm.GMConstants; import siuying.gm.GMResponse; import siuying.gm.ParsePacketException; import siuying.gm.structure.GMThread; /** * * @author Administrator */ public class GmailHelper { GMConnector connector = null; GMResponse res = null; GMThread th=null; ArrayList threads=null; public String Username="User name"; public String password="Password"; public String proxyHost="No Proxy"; public int port=0; public int timezoneOffset=0; /** Creates a new instance of GmailHelper */ public GmailHelper() { } public GmailHelper(String username , String password , String ProxyHost,int port,int timZoneOffset) { this.password=password; this.Username=username; this.proxyHost=ProxyHost; this.port=port; this.timezoneOffset=timZoneOffset; connector= new GMConnector(username,password,timZoneOffset); } public boolean connect(){ if (!proxyHost.equalsIgnoreCase("No Proxy")) connector.setProxy(proxyHost,port) ; return connector.connect(); } public GmailCountUsage getCountUsage(){ int totalnewMessage = 0; int percent=0; boolean problematic=false; if (connector.isConnected()) { try { res=connector.request(GMConstants.GM_REQ_STANDARD,"Inbox",""); } catch (IOException ex) { ex.printStackTrace(); problematic=true; } catch (ParsePacketException ex) { problematic=true; ex.printStackTrace(); } catch(NullPointerException npe){ npe.printStackTrace(); } totalnewMessage =Integer.parseInt( (String) res.getGminfo().get("stdbox.inbox") ); percent= Integer.parseInt( ( (String) res.getGminfo().get("quota.percent")).replaceAll("%", "")); return new GmailCountUsage(totalnewMessage,percent,false); } else return new GmailCountUsage(-1,-1,true); } public ArrayList getMailsInfo(){ return res.getGMThreads(); } }