Skip to content

Commit 3f06b8c

Browse files
author
pborissow
committed
- Added logic to retrieve email addresses in the EmailFolder.getMessages() method. Updated the Email.parseNode() method accordingly. As part of this, added logic to get/set domain addresses in the Mailbox class.
- Added new parameter to the Folder.getItems() method to allow users to set a restriction. git-svn-id: svn://192.168.0.80/JavaXT/javaxt-exchange@421 2c7b0aa6-e0b2-3c4e-bb4a-8b65b6c465ff
1 parent 57b3d30 commit 3f06b8c

File tree

11 files changed

+149
-21
lines changed

11 files changed

+149
-21
lines changed

src/javaxt/exchange/CalendarEvent.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public CalendarEvent(javaxt.exchange.CalendarEvent event){
5151
this.attachments = event.attachments;
5252
this.updates = event.updates;
5353
this.lastModified = event.lastModified;
54+
this.additionalProperties = event.additionalProperties;
5455
this.extendedProperties = event.extendedProperties;
5556

5657
//Calendar specific information

src/javaxt/exchange/CalendarFolder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public CalendarEvent[] getEvents() throws ExchangeException {
5353
*/
5454
public CalendarEvent[] getEvents(int offset, int limit) throws ExchangeException {
5555
java.util.ArrayList<CalendarEvent> events = new java.util.ArrayList<CalendarEvent>();
56-
org.w3c.dom.Document xml = getItems(offset, limit, props, null);
56+
org.w3c.dom.Document xml = getItems(offset, limit, props, null, null);
5757
org.w3c.dom.Node[] nodes = javaxt.xml.DOM.getElementsByTagName("CalendarItem", xml);
5858

5959
for (org.w3c.dom.Node node : nodes){
@@ -118,7 +118,7 @@ public CalendarEvent[] getEvents(javaxt.utils.Date start, javaxt.utils.Date end)
118118
String EndDate = FolderItem.formatDate(end);
119119

120120
java.util.ArrayList<CalendarEvent> events = new java.util.ArrayList<CalendarEvent>();
121-
org.w3c.dom.Document xml = getItems("<m:CalendarView StartDate=\"" + StartDate + "\" EndDate=\"" + EndDate + "\"/>", props, null);
121+
org.w3c.dom.Document xml = getItems("<m:CalendarView StartDate=\"" + StartDate + "\" EndDate=\"" + EndDate + "\"/>", props, null, null);
122122
org.w3c.dom.Node[] nodes = javaxt.xml.DOM.getElementsByTagName("CalendarItem", xml);
123123

124124
for (org.w3c.dom.Node node : nodes){

src/javaxt/exchange/Contact.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ public Contact(javaxt.exchange.Contact contact){
8484
this.attachments = contact.attachments;
8585
this.updates = contact.updates;
8686
this.lastModified = contact.lastModified;
87+
this.additionalProperties = contact.additionalProperties;
8788
this.extendedProperties = contact.extendedProperties;
8889

8990
//Contact specific information

src/javaxt/exchange/ContactsFolder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public Contact[] getContacts() throws ExchangeException {
5858
*/
5959
public Contact[] getContacts(int offset, int limit) throws ExchangeException {
6060
java.util.ArrayList<Contact> contacts = new java.util.ArrayList<Contact>();
61-
org.w3c.dom.NodeList nodes = getItems(offset, limit, null, null).getElementsByTagName("t:Contact");
61+
org.w3c.dom.NodeList nodes = getItems(offset, limit, null, null, null).getElementsByTagName("t:Contact");
6262
for (int i=0; i<nodes.getLength(); i++){
6363
org.w3c.dom.Node node = nodes.item(i);
6464
if (node.getNodeType()==1){

src/javaxt/exchange/Email.java

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ private void init(javaxt.exchange.Email message){
6262
this.attachments = message.attachments;
6363
this.updates = message.updates;
6464
this.lastModified = message.lastModified;
65+
this.additionalProperties = message.additionalProperties;
6566
this.extendedProperties = message.extendedProperties;
6667

6768
//Email specific information
@@ -99,8 +100,8 @@ protected Email(org.w3c.dom.Node messageNode) {
99100
//**************************************************************************
100101
/** Creates a new instance of this class
101102
*/
102-
public Email(String exchangeID, Connection conn, ExtendedFieldURI[] AdditionalProperties) throws ExchangeException{
103-
super(exchangeID, conn, AdditionalProperties);
103+
public Email(String exchangeID, Connection conn, ExtendedFieldURI[] additionalProperties) throws ExchangeException{
104+
super(exchangeID, conn, additionalProperties);
104105
parseMessage();
105106
}
106107

@@ -230,6 +231,32 @@ else if(nodeName.equalsIgnoreCase("DateTimeReceived")){
230231
break;
231232
}
232233
}
234+
235+
236+
//Find the PR_SENDER_EMAIL_ADDRESS (0x0c1f001e) extended MAPI property
237+
it = extendedProperties.keySet().iterator();
238+
while(it.hasNext()){
239+
ExtendedFieldURI property = it.next();
240+
if (property.getName().equalsIgnoreCase("0xC1F")){
241+
String email = extendedProperties.get(property).toString();
242+
if (from!=null){
243+
if (from.getEmailAddress()==null){
244+
245+
if (!email.contains("@")){
246+
from.setDomainAddress(email); //<--For performance reasons, don't resolve the domain address!
247+
}
248+
else{
249+
try{
250+
from.setEmailAddress(email);
251+
}
252+
catch(ExchangeException e){}
253+
}
254+
}
255+
}
256+
extendedProperties.remove(property);
257+
break;
258+
}
259+
}
233260
}
234261

235262

@@ -355,7 +382,14 @@ public void setSensitivity(String sensitivity){
355382
//**************************************************************************
356383
//** getFrom
357384
//**************************************************************************
358-
/** Returns the Mailbox associated with the sender.
385+
/** Returns the Mailbox associated with the sender. Returns null if there
386+
* is no sender associated with this message (e.g. draft message). <p/>
387+
* Note that when a Mailbox is returned, the Mailbox may not always include
388+
* an email address. This is especially true for emails originating from
389+
* another Exchange account. In this case, you can try to retrieve the
390+
* domain address associated with the Mailbox and resolve it to an email
391+
* address via the Mailbox.getDomainAddress() and Mailbox.resolveName()
392+
* methods.
359393
*/
360394
public Mailbox getFrom(){
361395
return from;
@@ -630,7 +664,7 @@ public void save(Connection conn) throws ExchangeException {
630664
}
631665

632666
//Reset all the attributes of this item to reflect what's in Exchange
633-
init(new Email(id, conn));
667+
init(new Email(id, conn, additionalProperties));
634668
}
635669

636670

src/javaxt/exchange/EmailFolder.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ public EmailFolder(String folderName, Connection conn) throws ExchangeException
3636
//This property represents the date/time associated with the last action
3737
//performed on individual mail items.
3838
props.add(new ExtendedFieldURI(null, "0x1082", "SystemTime"));
39+
40+
//Add the PR_SENDER_EMAIL_ADDRESS (0x0c1f001e) extended MAPI property.
41+
props.add(new ExtendedFieldURI(null, "0x0C1F", "String"));
3942
}
4043

4144

@@ -68,11 +71,15 @@ public static Folder[] getMailFolders(Connection conn) throws ExchangeException
6871
* This parameter is optional. A null value will return no additional or
6972
* extended attributes.
7073
*
74+
* @param where. XML fragment representing a
75+
* <a href="http://msdn.microsoft.com/en-us/library/aa563791%28v=exchg.140%29.aspx">
76+
* Restriction</a>. Null values imply no restriction.
77+
*
7178
* @param orderBy. SQL-style order by clause used to sort the response
7279
* (e.g. "item:DateTimeReceived DESC"). This parameter is optional. A null
7380
* value implies no sort preference.
7481
*/
75-
public Email[] getMessages(int offset, int limit, FieldURI[] additionalProperties, String orderBy) throws ExchangeException {
82+
public Email[] getMessages(int offset, int limit, FieldURI[] additionalProperties, String where, String orderBy) throws ExchangeException {
7683

7784
//Merge additional properties
7885
java.util.HashSet<FieldURI> props = getDefaultProperties();
@@ -81,7 +88,7 @@ public Email[] getMessages(int offset, int limit, FieldURI[] additionalPropertie
8188
}
8289

8390
java.util.ArrayList<Email> messages = new java.util.ArrayList<Email>();
84-
org.w3c.dom.NodeList nodes = getItems(offset, limit, props, orderBy).getElementsByTagName("t:Message");
91+
org.w3c.dom.NodeList nodes = getItems(offset, limit, props, where, orderBy).getElementsByTagName("t:Message");
8592
for (int i=0; i<nodes.getLength(); i++){
8693
org.w3c.dom.Node node = nodes.item(i);
8794
if (node.getNodeType()==1){

src/javaxt/exchange/ExtendedFieldURI.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class ExtendedFieldURI extends FieldURI {
2020
/** Creates a new instance of this class.
2121
* @param id A unique id in the form of a Microsoft GUID.
2222
* @param name Property name.
23-
* @param name Property type (e.g. "String").
23+
* @param name Property type (e.g. "String", "Integer", "SystemTime", etc).
2424
*/
2525
public ExtendedFieldURI(String id, String name, String type){
2626
this.id = id;
@@ -156,7 +156,7 @@ else if(operation.equalsIgnoreCase("delete")){
156156
}
157157

158158

159-
protected String toXML(String namespace){
159+
public String toXML(String namespace){
160160
String idAttr = (id==null ? "" : "PropertySetId=\"" + id + "\"");
161161
String nameAttr = (name.startsWith("0x") ? "PropertyTag=\"" + name + "\"" : "PropertyName=\"" + name + "\"");
162162
String typeAttr = "PropertyType=\"" + type + "\"";

src/javaxt/exchange/FieldURI.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public boolean equals(Object obj){
3131
return false;
3232
}
3333

34-
protected String toXML(String namespace){
34+
public String toXML(String namespace){
3535
return "<" + namespace + ":FieldURI FieldURI=\"" + this.toString() + "\"/>";
3636
}
3737

src/javaxt/exchange/Folder.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -375,11 +375,11 @@ public String toString(){
375375
* @param offset Item offset. 0 implies no offset.
376376
* @param limit Maximum number of items to return.
377377
*/
378-
protected org.w3c.dom.Document getItems(int offset, int limit, java.util.HashSet<FieldURI> additionalProperties, String orderBy) throws ExchangeException {
378+
protected org.w3c.dom.Document getItems(int offset, int limit, java.util.HashSet<FieldURI> additionalProperties, String where, String orderBy) throws ExchangeException {
379379
if (offset<1) offset = 0;
380380
if (limit<1) limit = 1;
381381
return getItems("<m:IndexedPageItemView MaxEntriesReturned=\"" + limit + "\" Offset=\"" + offset + "\" BasePoint=\"Beginning\"/>",
382-
additionalProperties, orderBy);
382+
additionalProperties, where, orderBy);
383383
}
384384

385385

@@ -400,7 +400,7 @@ protected org.w3c.dom.Document getItems(int offset, int limit, java.util.HashSet
400400
* @param orderBy SQL-style order by clause used to sort the results
401401
* (e.g. "item:DateTimeReceived DESC").
402402
*/
403-
protected org.w3c.dom.Document getItems(String view, java.util.HashSet<FieldURI> additionalProperties, String orderBy) throws ExchangeException {
403+
protected org.w3c.dom.Document getItems(String view, java.util.HashSet<FieldURI> additionalProperties, String where, String orderBy) throws ExchangeException {
404404

405405

406406
//Parse order by statement
@@ -428,6 +428,11 @@ else if (str.toUpperCase().endsWith(" DESC")){
428428
}
429429
}
430430

431+
//Parse where clasue and create restriction
432+
if (where==null) where = "";
433+
else where = where.trim();
434+
String restriction = where;
435+
431436

432437
//Update the view xml node. Make sure the node name is prefixed with a "m:" namespace
433438
if (view==null) view = "";
@@ -463,7 +468,7 @@ else if (str.toUpperCase().endsWith(" DESC")){
463468
}
464469
}
465470
}
466-
System.out.println(props);
471+
//System.out.println(props);
467472

468473
String msg =
469474
"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
@@ -486,6 +491,7 @@ else if (str.toUpperCase().endsWith(" DESC")){
486491
+ "</m:ItemShape>"
487492

488493
+ view
494+
+ restriction
489495
+ sort
490496

491497
+ "<m:ParentFolderIds>"

src/javaxt/exchange/FolderItem.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public class FolderItem {
6565
protected java.util.HashSet<String> categories = new java.util.HashSet<String>();
6666
protected java.util.HashSet<Attachment> attachments = new java.util.HashSet<Attachment>();
6767
protected javaxt.utils.Date lastModified;
68+
protected ExtendedFieldURI[] additionalProperties;
6869
protected java.util.HashMap<ExtendedFieldURI, Value> extendedProperties =
6970
new java.util.HashMap<ExtendedFieldURI, Value>();
7071

@@ -81,12 +82,13 @@ protected FolderItem(){}
8182
//** Constructor
8283
//**************************************************************************
8384
/** Creates a new instance of this class
84-
* @param AdditionalProperties A list of attributes you wish to see
85+
* @param additionalProperties A list of attributes you wish to see
8586
*/
86-
protected FolderItem(String exchangeID, Connection conn, ExtendedFieldURI[] AdditionalProperties) throws ExchangeException{
87+
protected FolderItem(String exchangeID, Connection conn, ExtendedFieldURI[] additionalProperties) throws ExchangeException{
8788

8889
if (exchangeID==null) throw new ExchangeException("Exchange ID is required.");
8990
if (conn==null) throw new ExchangeException("Exchange Web Services Connection is required.");
91+
this.additionalProperties = additionalProperties;
9092

9193
StringBuffer str = new StringBuffer();
9294

@@ -105,8 +107,8 @@ protected FolderItem(String exchangeID, Connection conn, ExtendedFieldURI[] Addi
105107
//str.append("<t:FieldURI FieldURI=\"item:LastModifiedTime\"/>"); //<--This doesn't work...
106108
str.append("<t:ExtendedFieldURI PropertyTag=\"0x3008\" PropertyType=\"SystemTime\" />"); //<--This returns the LastModifiedTime!
107109

108-
if (AdditionalProperties!=null){
109-
for (ExtendedFieldURI property : AdditionalProperties){
110+
if (additionalProperties!=null){
111+
for (ExtendedFieldURI property : additionalProperties){
110112

111113
String name = property.getName();
112114
String type = property.getType();

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy