-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmailFolder.java
More file actions
147 lines (119 loc) · 5.86 KB
/
EmailFolder.java
File metadata and controls
147 lines (119 loc) · 5.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package javaxt.exchange;
//******************************************************************************
//** EmailFolder Class
//******************************************************************************
/**
* Used to represent an mail folder (e.g. "Inbox", "Sent Items", etc.).
*
******************************************************************************/
public class EmailFolder extends Folder {
private java.util.HashSet<FieldURI> props = new java.util.HashSet<FieldURI>();
//**************************************************************************
//** Constructor
//**************************************************************************
/** Creates a new instance of this class.
* @param folderName Distinguished name or unique ID of the folder (e.g.
* "inbox", "drafts", "deleteditems", "junkemail", "outbox", etc.).
*/
public EmailFolder(String folderName, Connection conn) throws ExchangeException {
super(folderName, conn);
init();
}
//**************************************************************************
//** Constructor
//**************************************************************************
/** Creates a new instance of this class.
*/
public EmailFolder(Folder folder) throws ExchangeException {
super(folder);
init();
}
//**************************************************************************
//** init
//**************************************************************************
private void init(){
props.add(new FieldURI("item:Importance"));
props.add(new FieldURI("item:DateTimeReceived"));
props.add(new FieldURI("item:IsDraft"));
//Add the PR_LAST_VERB_EXECUTED (0x10810003) extended MAPI property. This
//property represents the last action performed on individual mail items.
//Possible values include 102 (replied), 103 (reply all), and 104 (forwarded).
props.add(new ExtendedFieldURI(null, "0x1081", "Integer"));
//Add the PR_LAST_VERB_EXECUTION_TIME (0x10820040) extended MAPI property.
//This property represents the date/time associated with the last action
//performed on individual mail items.
props.add(new ExtendedFieldURI(null, "0x1082", "SystemTime"));
//Add the PR_SENDER_EMAIL_ADDRESS (0x0c1f001e) extended MAPI property.
props.add(new ExtendedFieldURI(null, "0x0C1F", "String"));
//Add the PR_HASATTACH (0x0e1b000b) extended MAPI property. This property
//is used to indicate whether the message has an attachment. Note that
//the item:HasAttachments doesn't reveal "hidden" attachments. Also,
//you cannot perform compound (multidimensional) sorts on the
//item:HasAttachments field.
props.add(new ExtendedFieldURI(null, "0x0E1B", "Boolean"));
}
//**************************************************************************
//** getMailFolders
//**************************************************************************
/** Returns an array of folders that contain, or are associated with, email
* messages (e.g. "Inbox", "Deleted Items", "Drafts", "Junk E-mail",
* "Outbox", "Sent Items", etc). This is a convenience method and is
* identical to calling:
* <pre>new javaxt.exchange.Folder("msgfolderroot", conn).getFolders();</pre>
*/
public static Folder[] getMailFolders(Connection conn) throws ExchangeException {
return new javaxt.exchange.Folder("msgfolderroot", conn).getFolders();
}
//**************************************************************************
//** getMessages
//**************************************************************************
/** Returns a shallow representation of email messages found in this folder.
*
* @param offset Item offset. 0 implies no offset.
*
* @param limit Maximum number of items to return.
*
* @param additionalProperties By default, this method returns a shallow
* representation messages found in this folder. You can retrieve additional
* attributes by providing an array of FieldURI (including ExtendedFieldURIs).
* This parameter is optional. A null value will return no additional or
* extended attributes.
*
* @param where. XML fragment representing a
* <a href="http://msdn.microsoft.com/en-us/library/aa563791%28v=exchg.140%29.aspx">
* Restriction</a>. Null values imply no restriction.
*
*/
public Email[] getMessages(int offset, int limit, FieldURI[] additionalProperties, String where, FieldOrder[] sortOrder) throws ExchangeException {
//Merge additional properties with default properties
java.util.HashSet<FieldURI> props = getDefaultProperties();
if (additionalProperties!=null){
for (FieldURI property : additionalProperties) props.add(property);
}
//Execute GetItems request
java.util.ArrayList<Email> messages = new java.util.ArrayList<Email>();
org.w3c.dom.Document xml = getItems(offset, limit, props, where, sortOrder);
//Parse email messages
org.w3c.dom.NodeList nodes = xml.getElementsByTagName("t:Message");
for (int i=0; i<nodes.getLength(); i++){
org.w3c.dom.Node node = nodes.item(i);
if (node.getNodeType()==1){
messages.add(new Email(node));
}
}
//Parse Item nodes (e.g. Sharing Request)
nodes = xml.getElementsByTagName("t:Item");
for (int i=0; i<nodes.getLength(); i++){
org.w3c.dom.Node node = nodes.item(i);
if (node.getNodeType()==1){
messages.add(new Email(node));
}
}
return messages.toArray(new Email[messages.size()]);
}
private java.util.HashSet<FieldURI> getDefaultProperties(){
java.util.HashSet<FieldURI> map = new java.util.HashSet<FieldURI>();
map.addAll(props);
return map;
}
}