siuying.gm
Class GMConnector

java.lang.Object
  extended by siuying.gm.GMConnector

public class GMConnector
extends java.lang.Object

Main class to establish connection to GMail and perform actions Since 0.3.6, underlying HTTP is done by Multi-Threaded HTTPClient Thus multiple request can be sent at same time

Version:
0.3.17
Author:
siuying

Field Summary
protected static java.lang.String LINK_ATTACHMENT
           
protected static java.lang.String LINK_GMAIL
           
protected static java.lang.String LINK_LOGIN
           
protected static java.lang.String LINK_LOGIN2
           
protected static java.lang.String LINK_LOGOUT
           
protected static java.lang.String LINK_REFER
           
protected static int LOGON_PORT
           
protected static java.lang.String LOGON_SITE
           
protected static int STATUS_CONNECTED
           
protected static int STATUS_INITED
           
protected static int STATUS_NOT_INIT
           
protected static java.lang.String USER_AGENT
           
protected static java.lang.String VER
           
 
Constructor Summary
GMConnector()
          Create an GMConnector object to connect and request gmail for various tasks
GMConnector(java.lang.String user, java.lang.String passwd, int tz)
          Create an GMConnector object to connect and request gmail for various tasks
 
Method Summary
 boolean connect()
          Connect and login to gmail
 void disconnect()
          disconnect to gmail network
 java.lang.String fetchOriginalMail(java.lang.String id)
          Request gmail for the original source of the email Use this method if you do NOT want to get the gmail/gmailer processed message and instead get the untouched form of the original message
 java.io.InputStream getAttachmentAsStream(java.lang.String attid, java.lang.String msgid)
          Open an Attachment in GMal as an InputStream
 GMContact[] getContact(int type, java.lang.String search)
          Request GMail for list of contacts
 org.apache.commons.httpclient.HttpClient getHttpClient()
           
 java.lang.String getPasswd()
          Get password of the connection
 java.lang.String getProxyHost()
          Get proxy host address
 int getProxyPort()
          Get the proxy host port
 java.lang.String getTimezone()
          Get timezone of the connection
 java.lang.String getUser()
          Get username of the connection
 boolean isConnected()
          Check if we had connected to gmail
 GMResponse request(byte type, java.lang.String box, java.lang.String pos)
          Send request to gmail
 GMResponse request(byte type, java.lang.String box, java.lang.String pos, java.lang.String[] msgs)
          Send request to gmail
 boolean send(GMSendMailBody mailbody)
           
 void setPasswd(java.lang.String passwd)
          Get password of the connection
 void setProxy(java.lang.String phost, int pport)
          Set the HTTP proxy host address and port
 void setTimezone(java.lang.String timezone)
          Set timezone of the connection
 void setUser(java.lang.String user)
          Set username of the connection
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LINK_GMAIL

protected static final java.lang.String LINK_GMAIL
See Also:
Constant Field Values

LINK_LOGIN

protected static final java.lang.String LINK_LOGIN
See Also:
Constant Field Values

LINK_LOGOUT

protected static final java.lang.String LINK_LOGOUT
See Also:
Constant Field Values

LINK_LOGIN2

protected static final java.lang.String LINK_LOGIN2
See Also:
Constant Field Values

LINK_REFER

protected static final java.lang.String LINK_REFER
See Also:
Constant Field Values

LINK_ATTACHMENT

protected static final java.lang.String LINK_ATTACHMENT
See Also:
Constant Field Values

USER_AGENT

protected static final java.lang.String USER_AGENT
See Also:
Constant Field Values

VER

protected static final java.lang.String VER
See Also:
Constant Field Values

LOGON_SITE

protected static final java.lang.String LOGON_SITE
See Also:
Constant Field Values

LOGON_PORT

protected static final int LOGON_PORT
See Also:
Constant Field Values

STATUS_NOT_INIT

protected static final int STATUS_NOT_INIT
See Also:
Constant Field Values

STATUS_INITED

protected static final int STATUS_INITED
See Also:
Constant Field Values

STATUS_CONNECTED

protected static final int STATUS_CONNECTED
See Also:
Constant Field Values
Constructor Detail

GMConnector

public GMConnector()
Create an GMConnector object to connect and request gmail for various tasks


GMConnector

public GMConnector(java.lang.String user,
                   java.lang.String passwd,
                   int tz)
Create an GMConnector object to connect and request gmail for various tasks

Parameters:
user - String
passwd - String
tz - int timezone
Method Detail

disconnect

public void disconnect()
disconnect to gmail network


connect

public boolean connect()
Connect and login to gmail

Returns:
boolean

isConnected

public boolean isConnected()
Check if we had connected to gmail

Returns:
boolean

request

public GMResponse request(byte type,
                          java.lang.String box,
                          java.lang.String pos)
                   throws java.io.IOException,
                          ParsePacketException
Send request to gmail

Parameters:
type - byte Must be one of GM_REQ_STANDARD, GM_REQ_LABEL, GM_REQ_QUERY or GM_REQ_CONVERSATION
box - String label name or directory name or query, e.g. "Inbox"
pos - String Postion of the search as String
Returns:
GMResponse response from gmail
Throws:
java.io.IOException - When reading error from connection
ParsePacketException - When GMail send something we dont expect
To do:
figure out in conversation request, what the array parameters do

request

public GMResponse request(byte type,
                          java.lang.String box,
                          java.lang.String pos,
                          java.lang.String[] msgs)
                   throws java.io.IOException,
                          ParsePacketException
Send request to gmail

Parameters:
type - byte
box - String
pos - String
msgs - String[] array of msg id, if it is null no such id is sent
Returns:
GMResponse
Throws:
java.io.IOException
ParsePacketException
To do:
test request with multiple msg id attached

fetchOriginalMail

public java.lang.String fetchOriginalMail(java.lang.String id)
                                   throws java.io.IOException
Request gmail for the original source of the email Use this method if you do NOT want to get the gmail/gmailer processed message and instead get the untouched form of the original message

Parameters:
String - id ID of the thread
Throws:
java.io.IOException
To do:
retry id HttpRecoverableException occurs

send

public boolean send(GMSendMailBody mailbody)
             throws java.io.IOException
Throws:
java.io.IOException

getContact

public GMContact[] getContact(int type,
                              java.lang.String search)
                       throws java.io.IOException,
                              ParsePacketException,
                              java.lang.IllegalArgumentException
Request GMail for list of contacts

Parameters:
int - type,
  • 0 - GMConstants.GM_CONTACT_FREQ_MAILED,
  • 1 - GMConstants.M_CONTACT_ALL,
  • 2 - GM_CONTACT_SEARCH
String - search, the Search string, only usefule when searching (type=GM_CONTACT_SEARCH)
Returns:
GMContact[] ArrayList of GMailContact
Throws:
java.io.IOException - When reading error from connection
ParsePacketException - When GMail send something we dont expect
java.lang.IllegalArgumentException
See Also:
GMConstants

getAttachmentAsStream

public java.io.InputStream getAttachmentAsStream(java.lang.String attid,
                                                 java.lang.String msgid)
                                          throws java.io.IOException
Open an Attachment in GMal as an InputStream

Parameters:
attid - String Attachment ID
msgid - String Message ID
Returns:
InputStream
Throws:
java.io.IOException - Error reading from gmail

getPasswd

public java.lang.String getPasswd()
Get password of the connection

Returns:
String

setPasswd

public void setPasswd(java.lang.String passwd)
Get password of the connection

Parameters:
passwd - String

getTimezone

public java.lang.String getTimezone()
Get timezone of the connection

Returns:
String A Integer String

setTimezone

public void setTimezone(java.lang.String timezone)
Set timezone of the connection

Parameters:
timezone - String

setUser

public void setUser(java.lang.String user)
Set username of the connection

Parameters:
user - String

getUser

public java.lang.String getUser()
Get username of the connection

Returns:
String

getProxyHost

public java.lang.String getProxyHost()
Get proxy host address

Returns:
String the http proxy host address

getProxyPort

public int getProxyPort()
Get the proxy host port

Returns:
int

setProxy

public void setProxy(java.lang.String phost,
                     int pport)
Set the HTTP proxy host address and port

Parameters:
phost - String
pport - int

getHttpClient

public org.apache.commons.httpclient.HttpClient getHttpClient()