Skip to content

Commit edc1c07

Browse files
author
pborissow
committed
- Updated constructor in the Mailbox class to search for email addresses in the Name field.
- Updated constructor CalendarEvent class to use the Mailbox.resolveName() static method when parsing Calendar Items. The Mailbox.resolveName() requires a Connection object so the CalendarEvent constructor has been updated to require a Connection object as well. git-svn-id: svn://192.168.0.80/JavaXT/javaxt-exchange@927 2c7b0aa6-e0b2-3c4e-bb4a-8b65b6c465ff
1 parent a07a8fc commit edc1c07

4 files changed

Lines changed: 226 additions & 13 deletions

File tree

src/javaxt/exchange/CalendarEvent.java

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public CalendarEvent(String title, String description, String location, Mailbox
8787
*/
8888
public CalendarEvent(String exchangeID, Connection conn, ExtendedFieldURI[] AdditionalProperties) throws ExchangeException{
8989
super(exchangeID, conn, AdditionalProperties);
90-
parseCalendarItem();
90+
parseCalendarItem(conn);
9191
}
9292

9393

@@ -119,9 +119,9 @@ public CalendarEvent(String iCalendar) throws Exception{
119119
//**************************************************************************
120120
/** Creates a new instance of CalendarEvent. */
121121

122-
protected CalendarEvent(org.w3c.dom.Node calendarItemNode) throws ExchangeException {
122+
protected CalendarEvent(org.w3c.dom.Node calendarItemNode, Connection conn) throws ExchangeException {
123123
super(calendarItemNode);
124-
parseCalendarItem();
124+
parseCalendarItem(conn);
125125
}
126126

127127

@@ -130,7 +130,7 @@ protected CalendarEvent(org.w3c.dom.Node calendarItemNode) throws ExchangeExcept
130130
//**************************************************************************
131131
/** Used to parse an xml node with event information.
132132
*/
133-
private void parseCalendarItem() throws ExchangeException {
133+
private void parseCalendarItem(Connection conn) throws ExchangeException {
134134

135135
String timezone = null;
136136

@@ -167,23 +167,47 @@ else if(nodeName.equalsIgnoreCase("LegacyFreeBusyStatus")){
167167
}
168168
else if(nodeName.equalsIgnoreCase("Organizer")){
169169
org.w3c.dom.Node[] mailbox = javaxt.xml.DOM.getElementsByTagName("Mailbox", outerNode);
170-
if (mailbox.length>0) organizer = new Mailbox(mailbox[0]);
170+
if (mailbox.length>0) organizer = getMailbox(mailbox[0], conn);
171171
}
172172
else if(nodeName.equalsIgnoreCase("RequiredAttendees")){
173173
for (org.w3c.dom.Node node : javaxt.xml.DOM.getElementsByTagName("Mailbox", outerNode)){
174-
attendees.put(new Mailbox(node), true);
174+
attendees.put(getMailbox(node, conn), true);
175175
}
176176
}
177177
else if(nodeName.equalsIgnoreCase("OptionalAttendees")){
178178
for (org.w3c.dom.Node node : javaxt.xml.DOM.getElementsByTagName("Mailbox", outerNode)){
179-
attendees.put(new Mailbox(node), false);
179+
attendees.put(getMailbox(node, conn), false);
180180
}
181181
}
182182
}
183183
}
184184
setTimeZone(timezone);
185185
}
186186

187+
188+
//**************************************************************************
189+
//** getMailbox
190+
//**************************************************************************
191+
private Mailbox getMailbox(org.w3c.dom.Node node, Connection conn){
192+
try{
193+
return new Mailbox(node);
194+
}
195+
catch(ExchangeException e){
196+
String err = e.getMessage();
197+
try{
198+
if (err.startsWith("Invalid Email Address:")){
199+
String invalidEmail = err.substring(err.indexOf(":")+1).trim();
200+
return Mailbox.resolveName(invalidEmail, conn);
201+
}
202+
}
203+
catch(Exception ex){
204+
ex.printStackTrace();
205+
}
206+
207+
return null;
208+
}
209+
}
210+
187211

188212
//**************************************************************************
189213
//** setTimeZone

src/javaxt/exchange/CalendarFolder.java

Lines changed: 155 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
public class CalendarFolder extends Folder {
1212

1313
private java.util.HashSet<FieldURI> props = new java.util.HashSet<FieldURI>();
14+
private Connection conn;
1415

1516
//**************************************************************************
1617
//** Constructor
@@ -20,6 +21,7 @@ public class CalendarFolder extends Folder {
2021
public CalendarFolder(Connection conn) throws ExchangeException {
2122
super("calendar", conn);
2223
props.add(new FieldURI("calendar:TimeZone"));
24+
this.conn = conn;
2325
}
2426

2527
/*
@@ -57,7 +59,7 @@ public CalendarEvent[] getEvents(int offset, int limit) throws ExchangeException
5759
org.w3c.dom.Node[] nodes = javaxt.xml.DOM.getElementsByTagName("CalendarItem", xml);
5860

5961
for (org.w3c.dom.Node node : nodes){
60-
events.add(new CalendarEvent(node));
62+
events.add(new CalendarEvent(node, conn));
6163
}
6264
return events.toArray(new CalendarEvent[events.size()]);
6365
}
@@ -122,17 +124,167 @@ public CalendarEvent[] getEvents(javaxt.utils.Date start, javaxt.utils.Date end)
122124
org.w3c.dom.Node[] nodes = javaxt.xml.DOM.getElementsByTagName("CalendarItem", xml);
123125

124126
for (org.w3c.dom.Node node : nodes){
125-
CalendarEvent event = new CalendarEvent(node);
127+
CalendarEvent event = new CalendarEvent(node, conn);
126128
if (event.isAllDayEvent() && event.getStartTime().compareTo(start, "days")==-1){
127129

128130
}
129131
else{
130-
events.add(new CalendarEvent(node));
132+
events.add(new CalendarEvent(node, conn));
131133
}
132134
}
133135

134136

135137

136138
return events.toArray(new CalendarEvent[events.size()]);
137139
}
140+
141+
142+
143+
/*
144+
public void sendSharingRequest(Mailbox recipient, Mailbox sender, Connection conn) throws ExchangeException {
145+
146+
if (true) throw new ExchangeException("not implemented");
147+
148+
149+
javaxt.exchange.Email email = new javaxt.exchange.Email();
150+
email.setSubject("I'd like to share my calendar with you");
151+
email.setBody("<div style=\"color:blue;\"><span>Do you see this in blue?</div>", "HTML");
152+
email.addRecipient("To", recipient);
153+
email.setMessageClass("IPM.Sharing"); //"PidTagMessageClass", "IPM.Sharing"
154+
//email.setMessageType("Sharing"); //"PidNameContentClass", "Sharing"
155+
156+
157+
//Create attachment
158+
StringBuffer str = new StringBuffer();
159+
str.append("<?xml version=\"1.0\"?>");
160+
str.append("<SharingMessage xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ");
161+
str.append("xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" ");
162+
str.append("xmlns=\"http://schemas.microsoft.com/sharing/2008\">");
163+
str.append("<DataType>calendar</DataType>");
164+
str.append("<Initiator>");
165+
str.append("<Name>" + sender.getName() + "</Name>");
166+
str.append("<SmtpAddress>" + sender.getEmailAddress() + "</SmtpAddress>");
167+
//str.append("<EntryId>" + sender.getEntryID() + "</EntryId>");
168+
str.append("</Initiator>");
169+
str.append("<Invitation>");
170+
str.append("<Providers>");
171+
str.append("<Provider Type=\"ms-exchange-internal\" TargetRecipients=\"" + recipient.getEmailAddress() + "\">");
172+
str.append("<FolderId xmlns=\"http://schemas.microsoft.com/exchange/sharing/2008\">");
173+
str.append(this.getID());
174+
str.append("</FolderId>");
175+
str.append("<MailboxId xmlns=\"http://schemas.microsoft.com/exchange/sharing/2008\">");
176+
str.append(sender.getID());
177+
str.append("</MailboxId>");
178+
str.append("</Provider>");
179+
str.append("</Providers>");
180+
str.append("</Invitation>");
181+
str.append("</SharingMessage>");
182+
//email.addAttachment(str.toString());
183+
184+
185+
186+
java.util.HashMap<String, String> headers = new java.util.HashMap<String, String>();
187+
188+
189+
190+
// X-MS-Exchange-Organization-AuthAs: Internal
191+
// X-MS-Exchange-Organization-AuthMechanism: 04
192+
// X-MS-Exchange-Organization-AuthSource: exchange2010.example.com
193+
// X-MS-Has-Attach: yes
194+
// X-MS-Exchange-Organization-SCL: -1
195+
// X-MS-TNEF-Correlator:
196+
// x-sharing-capabilities: 402B0
197+
// x-sharing-flavor: 310
198+
// x-sharing-provider-guid: AEF0060000000000C000000000000046
199+
// x-sharing-provider-name: Microsoft Exchange
200+
// x-sharing-provider-url: http://www.microsoft.com/exchange/
201+
// x-sharing-remote-path:
202+
// x-sharing-remote-name: =?iso-8859-1?Q?Jane=B4s_her_share_calendar?=
203+
// x-sharing-remote-uid: 00000000BC5AB69D4370454FB480A15DB2A7E93C0100DCB29F06B087BB439B542470E7A5D6E300002DAFEAEA0000
204+
// x-sharing-remote-store-uid: 0000000038A1BB1005E5101AA1BB08002B2A56C20000454D534D44422E444C4C00000000000000001B55FA20AA6611CD9BC800AA002FC45A0C00000045584348414E474532303130002F6F3D4669727374204F7267616E697A6174696F6E2F6F753D45786368616E67652041646D696E6973747261746976652047726F7570202846594449424F484632335350444C54292F636E3D526563697069656E74732F636E3D4A616E6520446F6534633900
205+
// x-sharing-remote-type: IPF.Appointment
206+
207+
208+
209+
// Section 2.2.2
210+
headers.put("x-sharing-capabilities", "40290"); //Test representation of SharingCapabilities value
211+
headers.put("x-sharing-flavor", "20310"); //Text representation of SharingFlavor value [MS-OXSHARE] 2.2.2.6
212+
213+
214+
215+
headers.put("x-sharing-local-type", "IPF.Appointment"); //MUST be set to same value as PidLidSharingLocalType
216+
headers.put("x-sharing-provider-guid", "AEF0060000000000C000000000000046"); //Constant Required Value [MS-OXSHARE] 2.2.2.13
217+
headers.put("x-sharing-provider-name", "Microsoft Exchange"); //Constant Required Value [MS-OXSHARE] 2.2.2.15]
218+
headers.put("x-sharing-provider-url", "HTTP://www.microsoft.com/exchange"); //Constant Required Value [MS-OXSHARE] 2.2.2.17
219+
220+
// Section 2.2.3
221+
headers.put("x-sharing-remote-name", "Calendar"); //MUST be set to same value as PidLidSharingRemoteName
222+
headers.put("x-sharing-remote-store-uid", sender.getID()); //MUST be set to same value as PidLidSharingRemoteStoreUid
223+
headers.put("x-sharing-remote-type", "IPF.Appointment"); //Constant Required Value [MS-OXSHARE] 2.2.3.6
224+
headers.put("x-sharing-remote-uid", this.getID()); //Must be set to same value as PidLidSharingRemoteUid
225+
226+
227+
228+
229+
230+
String action = "SendOnly";
231+
232+
//Send the message and create a copy in the "sentitems" folder
233+
StringBuffer msg = new StringBuffer();
234+
msg.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
235+
msg.append("<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:t=\"http://schemas.microsoft.com/exchange/services/2006/types\" xmlns:m=\"http://schemas.microsoft.com/exchange/services/2006/messages\">");
236+
msg.append("<soap:Body>");
237+
msg.append("<m:CreateItem MessageDisposition=\"" + action + "\">");
238+
239+
240+
241+
msg.append("<m:SavedItemFolderId>");
242+
243+
String folderName = "drafts";
244+
if (action.equals("SendOnly") || action.equals("SendAndSaveCopy")) folderName = "sentitems";
245+
msg.append("<t:DistinguishedFolderId Id=\"" + folderName + "\" />");
246+
247+
msg.append("</m:SavedItemFolderId>");
248+
msg.append("<m:Items>");
249+
250+
251+
252+
253+
String messageType = "Message";
254+
255+
msg.append("<t:" + messageType + ">");
256+
msg.append("<t:ItemClass>" + email.getMessageClass() + "</t:ItemClass>"); //<--New for sharing requests
257+
msg.append("<t:Subject>" + email.getSubject() + "</t:Subject>");
258+
msg.append("<t:Sensitivity>" + email.getSensitivity() + "</t:Sensitivity>");
259+
260+
261+
//Set body
262+
if (email.getBody()!=null){
263+
msg.append("<t:Body BodyType=\"" + email.getBodyType() + "\">");
264+
//msg.append(wrap(body));
265+
msg.append("</t:Body>");
266+
};
267+
268+
269+
msg.append("<t:Importance>" + email.getImportance() + "</t:Importance>");
270+
271+
272+
msg.append("<t:ToRecipients>");
273+
msg.append(recipient.toXML("t"));
274+
msg.append("</t:ToRecipients>");
275+
276+
277+
msg.append("</t:" + messageType + ">");
278+
279+
280+
281+
msg.append("</m:Items>");
282+
msg.append("</m:CreateItem>");
283+
msg.append("</soap:Body>");
284+
msg.append("</soap:Envelope>");
285+
286+
conn.execute(msg.toString(), headers);
287+
288+
}
289+
*/
138290
}

src/javaxt/exchange/EmailAddress.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public EmailAddress(String email) throws ExchangeException {
3535
}
3636

3737
if (emailAddress==null){
38-
throw new ExchangeException("Invalid Email Address: " + email);
38+
throw new ExchangeException("Invalid Email Address: " + email); //<--DO NOT CHANGE THIS ERROR MESSAGE! Check code for usage...
3939
}
4040

4141
this.emailAddress = emailAddress;

src/javaxt/exchange/Mailbox.java

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ public class Mailbox {
2626

2727
protected Mailbox(org.w3c.dom.Node mailboxNode) throws ExchangeException {
2828
org.w3c.dom.NodeList mailboxItems = mailboxNode.getChildNodes();
29-
29+
ExchangeException ex = null;
30+
3031
for (int i=0; i<mailboxItems.getLength(); i++){
3132
org.w3c.dom.Node node = mailboxItems.item(i);
3233
if (node.getNodeType()==1){
@@ -38,7 +39,18 @@ protected Mailbox(org.w3c.dom.Node mailboxNode) throws ExchangeException {
3839
Name = javaxt.xml.DOM.getNodeValue(node);
3940
}
4041
else if(nodeName.equalsIgnoreCase("EmailAddress")){
41-
EmailAddress = new EmailAddress(javaxt.xml.DOM.getNodeValue(node));
42+
try{
43+
EmailAddress = new EmailAddress(javaxt.xml.DOM.getNodeValue(node));
44+
}
45+
catch(ExchangeException e){
46+
String err = e.getMessage();
47+
if (err.startsWith("Invalid Email Address:")){
48+
ex = e;
49+
}
50+
else{
51+
throw e;
52+
}
53+
}
4254
}
4355
else if(nodeName.equalsIgnoreCase("RoutingType")){
4456
RoutingType = javaxt.xml.DOM.getNodeValue(node);
@@ -51,6 +63,31 @@ else if(nodeName.equalsIgnoreCase("ItemId")){
5163
}
5264
}
5365
}
66+
67+
68+
//Try extracting email address from other fields (e.g. Name)
69+
if (EmailAddress==null){
70+
71+
/*
72+
if (Name.contains("@")){
73+
String str = Name.trim();
74+
75+
76+
//This logic is a little hacky. I found email addresses embedded in names
77+
int idx = str.indexOf("(");
78+
if (idx>-1 && str.endsWith(")")){
79+
String _email = str.substring(idx+1, str.length()-1).trim();
80+
System.out.println(_email);
81+
EmailAddress = new EmailAddress(_email);
82+
Name = str.substring(0, idx);
83+
System.out.println(Name);
84+
}
85+
}
86+
else{
87+
throw ex;
88+
}
89+
*/
90+
}
5491
}
5592

5693
public Mailbox(String name, EmailAddress email) {

0 commit comments

Comments
 (0)