From: Stig T. <jw...@us...> - 2005-03-20 17:43:06
|
Update of /cvsroot/mailsomething/mailsomething/src/net/sf/mailsomething/mail/imap In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23927/net/sf/mailsomething/mail/imap Added Files: ImapCommand.java ImapSelectResponse.java ImapListResponse.java ImapResponse.java ImapFetchCommand.java ImapSelectCommand.java ImapCommands.java Log Message: --- NEW FILE: ImapSelectCommand.java --- package net.sf.mailsomething.mail.imap; /** * @author Stig tanggaard * @since 2005-03-20 * **/ public class ImapSelectCommand extends ImapCommand { private String mailboxPath; /** * * @param path the path to the mailbox. */ public ImapSelectCommand(String path) { mailboxPath = path; } /* (non-Javadoc) * @see net.sf.mailsomething.mail.imap.ImapCommand#generateCommand() */ public String generateCommand() { String command = getTag() + " "; String commandMailboxPath = doSelect(mailboxPath); if (commandMailboxPath.indexOf(" ") != -1) { command += "SELECT " + '"' + commandMailboxPath + '"'; } else { command += "SELECT " + commandMailboxPath; } return command; } public String getCommand() { return ImapCommands.SELECT; } /* (non-Javadoc) * @see net.sf.mailsomething.mail.imap.ImapCommand#getResponseInstance() */ public ImapResponse getResponseInstance() { ImapSelectResponse response = new ImapSelectResponse(); response.setCommand(this); return response; } public static String doSelect(String mailboxPath) { String listCommand = ""; if (mailboxPath.equals("")) { return listCommand; } if (mailboxPath.charAt(0) == '/') { mailboxPath = mailboxPath.substring(1); } listCommand = mailboxPath; return listCommand; } } --- NEW FILE: ImapSelectResponse.java --- package net.sf.mailsomething.mail.imap; /** * @author Stig Tanggaard * @since 18-03-2005 * */ public class ImapSelectResponse extends ImapResponse { private int exists, recent, unseen, uidvalidity, uidnext; private int flags; public ImapSelectResponse() { } /* (non-Javadoc) * @see net.sf.mailsomething.mail.imap.ImapResponse#buildResponse(java.lang.String[]) */ public void buildResponse(String[] replyLines) { // TODO Auto-generated method stub super.buildResponse(replyLines); /* example C: A142 SELECT INBOX S: * 172 EXISTS S: * 1 RECENT S: * OK [UNSEEN 12] Message 12 is first unseen S: * OK [UIDVALIDITY 3857529045] UIDs valid S: * OK [UIDNEXT 4392] Predicted next UID S: * FLAGS (\Answered \Flagged \Deleted \Seen \Draft) S: * OK [PERMANENTFLAGS (\Deleted \Seen \*)] Limited S: A142 OK [READ-WRITE] SELECT completed */ } } --- NEW FILE: ImapResponse.java --- package net.sf.mailsomething.mail.imap; /** * Simple imap response, can be extended, is used for commands: * DELETE, CREATE, RENAME * * * @author Stig Tanggaard * @since 18-03-2005 * */ public class ImapResponse { public static final int OK = 1; public static final int NO = 2; public static final int BAD = 4; private int type; private ImapCommand command; public int getResponseType() { return type; } /** * Returns the command which this response is a response * to. * * @return */ public ImapCommand getCommand() { return command; } /** * Method for 'building' the response, ie parsing the * reply lines from the server into a ImapResponse. * This standard method checks for the status of the * reponse: OK, NO or BAD. * Can be called by subclasses. * * * @param replyLines */ public void buildResponse(String[] replyLines) { for(int i = 0; i < replyLines.length; i++) { if(replyLines[i].indexOf(command.getTag()) != -1) { if(replyLines[i].indexOf("OK") != -1) { type = ImapResponse.OK; } else if(replyLines[i].indexOf("BAD") != -1) { type = ImapResponse.BAD; } if(replyLines[i].indexOf("NO") != -1) { type = ImapResponse.NO; } } } } /** * @param command The command to set. */ public void setCommand(ImapCommand command) { this.command = command; } } --- NEW FILE: ImapCommand.java --- package net.sf.mailsomething.mail.imap; /** * @author Stig Tanggaard * @since 18-03-2005 * */ public class ImapCommand { private String command, tag; /** * @return Returns the tag. */ public String getTag() { return tag; } /** * @param tag The tag to set. */ public void setTag(String tag) { this.tag = tag; } /** * Generates a command line which can be issued to a server. * A command line contains as a minimum a tag, a command, * and perhabs a list of parameters (depending on the specific * command) * * @return */ public String generateCommand() { return null; } /** * If a subclass of ImapCommand needs/uses a specific * subclass of ImapResponse, this method should be overridden. * For example, ImapSelectCommand will return an instance of * ImapSelectResponse. * * @return */ public ImapResponse getResponseInstance() { return new ImapResponse(); } } --- NEW FILE: ImapFetchCommand.java --- package net.sf.mailsomething.mail.imap; /** * @author Stig Tanggaard * @since 18-03-2005 * */ public class ImapFetchCommand extends ImapCommand { //public static final int UID_FLAG = 1; //public static final int RFC822_SIZE_FLAG = 2; } --- NEW FILE: ImapListResponse.java --- package net.sf.mailsomething.mail.imap; import java.util.Vector; /** * @author Stig Tanggaard * @since 18-03-2005 * */ public class ImapListResponse extends ImapResponse { private Vector listEntries = new Vector(); /* (non-Javadoc) * @see net.sf.mailsomething.mail.imap.ImapResponse#buildResponse(java.lang.String[]) */ public void buildResponse(String[] replyLines) { // TODO Auto-generated method stub super.buildResponse(replyLines); for(int i = 0; i < replyLines.length; i++) { if(!replyLines[i].startsWith(getCommand().getTag())) { listEntries.add(getEntry(replyLines[i])); } } } public ImapListResponseEntry[] getEntries() { return (ImapListResponseEntry[]) listEntries.toArray(new ImapListResponseEntry[]{}); } public ImapListResponseEntry getEntry(String responseLine) { ImapListResponseEntry entry = new ImapListResponseEntry(); //consider making the responseline lowercase and //ignore case when checking for the flags if(responseLine.indexOf("\\Marked") != -1) { entry.Marked = true; } else { entry.Marked = false; } if(responseLine.indexOf("\\HasChildren") != -1) { entry.HasChildren = true; } else { entry.HasChildren = false; } if(responseLine.indexOf("\\HasNoChildren") != -1) { entry.HasNoChildren = true; } else { entry.HasNoChildren = false; } if(responseLine.indexOf("\\Noselect") != -1) { entry.Noselect = true; } else { entry.Noselect = false; } //TODO name attribute //should be checked for ?- instances and decoded if //it contains those (modified base 64 encoding) return null; } public class ImapListResponseEntry { boolean Marked = false; boolean HasChildren = false; boolean HasNoChildren = false; boolean Noselect = false; String name; } } --- NEW FILE: ImapCommands.java --- package net.sf.mailsomething.mail.imap; /** * @author Stig Tanggaard * @since 18-03-2005 * */ public interface ImapCommands { public static final String SELECT = "SELECT"; public static final String CREATE = "CREATE"; public static final String DELETE = "DELETE"; public static final String RENAME = "RENAME"; public static final String LIST = "LIST"; public static final String STATUS = "STATUS"; public static final String FETCH = "FETCH"; public static final String STORE = "STORE"; } |