import com.intrinsyc.cdo.*; import com.linar.jintegra.AuthInfo;
public class CalendarFilter {
//TODO: Change the following parameters based on your setup and configuration static String domain = "MYDOMAIN"; static String user = "USERNAME"; static String password = "PASSWORD"; static String CDOmachine = "0.0.0.0"; static String exchangeServer = "0.0.0.0"; static String mailbox = "MAILBOX";
public void run() { boolean loggedon = false; Session cdoSession = null; try { AuthInfo.setDefault(domain, user, password); cdoSession = new Session(CDOmachine);
// Logon to the Exchange Server cdoSession.logon(null, null, new Boolean(false), new Boolean(true), new Integer(0), new Boolean(true), exchangeServer + "\n" + mailbox); loggedon = true;
System.out.println("Got CDO session"); Folder objCalendar = new FolderProxy( cdoSession.getDefaultFolder( new Integer(CdoDefaultFolderTypes.CdoDefaultFolderCalendar)) ); Messages oMsgColl = new MessagesProxy(objCalendar.getMessages()); MessageFilter oMsgFilter = new MessageFilterProxy(oMsgColl.getFilter());
/* Reference: * http://support.microsoft.com/?kbid=192404 */ new FieldsProxy(oMsgFilter.getFields()).add( new Integer(CdoPropTags.CdoPR_START_DATE), new String("10/1/06"), // Remember to reverse the date null, null ); new FieldsProxy(oMsgFilter.getFields()).add( new Integer(CdoPropTags.CdoPR_END_DATE), new String("9/1/06"), // Remember to reverse the date null, null ); AppointmentItem oAppt = new AppointmentItemProxy( oMsgColl.getFirst(oMsgFilter) ); System.out.println("Subject: " + oAppt.getSubject()); } catch (IllegalArgumentException e) { System.out.println( "No appointment found.\n" + "Make sure there is at least one appointment exists in you filter.\n" ); e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } finally { if (loggedon == true) { try { System.out.println("Logging off from Exchange."); cdoSession.logoff(); } catch(Exception ex) { ex.printStackTrace(); } } } }
public static void main(String[] args) { CalendarFilter example = new CalendarFilter(); example.run(); } } |