?? gmailtester.java
字號:
package siuying.gm.test;
import siuying.gm.structure.GMSendMailBody;
import siuying.gm.GMConnector;
import java.util.logging.Logger;
import java.io.IOException;
import siuying.gm.ParsePacketException;
import siuying.gm.GMConstants;
import siuying.gm.GMResponse;
import java.util.ArrayList;
import java.io.InputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class GMailTester {
public static Logger logger = Logger.getLogger("Main");
public static void main(String[] args) throws IOException, ParsePacketException {
if (args.length != 3 && args.length != 5){
System.err.println("Usgae: siuying.gm.test.GMailTester <user> <passwd> <timezone> [<proxyhost> <proxyport>]");
System.exit(1);
}
GMConnector gm = null;
try{
gm = new GMConnector(args[0], args[1], Integer.parseInt(args[2]));
}catch(NumberFormatException nfe){
System.err.println("Usgae: siuying.gm.test.GMailTester <user> <passwd> <timezone> [<proxyhost> <proxyport>]");
System.err.println("\tError: timezone not a valid number: " + args[2]);
System.exit(1);
}
if (args.length == 5){
try{
gm.setProxy(args[3], Integer.parseInt(args[4]));
}catch(NumberFormatException nfe){
System.err.println("Usgae: siuying.gm.test.GMailTester <user> <passwd> <timezone> [<proxyhost> <proxyport>]");
System.err.println("\tError: proxy port not a valid port number: " + args[4]);
System.exit(1);
}
}
if (gm.connect()){
logger.info("Logged in.");
}else{
logger.info("Failed logging in!");
System.exit(1);
}
GMResponse resp;
try{
/** Test Label */
logger.info("Testing open label, Label=Test, pos=0");
resp = gm.request(GMConstants.GM_REQ_LABEL, "Test", "0");
logger.info("Response Type: " + resp.getClass().getName());
logger.info("Response Details: " + resp.toString());
/** Test Inbox */
logger.info("Testing open Inbox, Label=inbox, pos=0");
resp = gm.request(GMConstants.GM_REQ_STANDARD, "inbox", "0");
logger.info("Response Type: " + resp.getClass().getName());
logger.info("Response Details: " + resp.toString());
/** Test Conversion*/
logger.info("Testing open CONVERSATION, ID=feede5cea8203bb, pos=0");
resp = gm.request(GMConstants.GM_REQ_CONVERSATION, "feede5cea8203bb", "0");
logger.info("Response Type: " + resp.getClass().getName());
logger.info("Response Details:" + resp.toString());
/** Test Conversion*/
logger.info("Testing open origion msg, ID=feede5cea8203bb, pos=0");
String org = gm.fetchOriginalMail("feede5cea8203bb");
logger.info("Message Details: " + org);
GMSendMailBody body = new GMSendMailBody();
body.setMsgbody("<html><p><b>Hello!</b> World.</p></html>");
body.setSubject("Test Send Mail");
body.addTo("siu.ying@gmail.com");
gm.send(body);
/** Test Contact*/
//logger.info("Testing open Contacts");
//ArrayList contacts = gm.requestContact();
//logger.info("Contact List:" + contacts);
/** Test read attachment */
logger.info("Testing open attach");
InputStream in = gm.getAttachmentAsStream("0.1", "feede5cea8203bb");
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
StringBuffer buffer = new StringBuffer();
String line;
try{
while ( (line = reader.readLine()) != null) {
buffer.append(line + "\n");
}
logger.info("Attachemnt File: \n" + buffer.toString());
}finally{
try{
reader.close();
in.close();
}catch(Exception e){}
}
}catch(IOException ioe){
logger.warning("Connection failure! " + ioe);
}catch(ParsePacketException ppe){
logger.warning("Cannot parse response from google! \n" + ppe);
}finally{
/** logout **/
logger.info("disconnecting");
gm.disconnect();
logger.info("disconnected");
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -