-
Notifications
You must be signed in to change notification settings - Fork 87
/
Copy pathView.cs
365 lines (328 loc) · 14 KB
/
View.cs
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
// Copyright (c) 2016, Dijji, and released under Ms-PL. This can be found in the root of this distribution.
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Windows;
namespace XstReader
{
// These classes are the view of the xst (.ost and .pst) file rendered by XAML
// The data layer is effectively provided by the xst file itself
class View : INotifyPropertyChanged
{
private Folder selectedFolder = null;
private Message currentMessage = null;
private bool isBusy = false;
private Stack<Message> stackMessage = new Stack<Message>();
private bool fileAttachmentSelected = false;
private bool emailAttachmentSelected = false;
private bool showContent = true;
public ObservableCollection<Folder> RootFolders { get; private set; } = new ObservableCollection<Folder>();
public Folder SelectedFolder {
get { return selectedFolder; }
set { selectedFolder = value; OnPropertyChanged("SelectedFolder"); OnPropertyChanged("CanExportFolder"); } }
public bool DisplayPrintHeaders { get; set; } = false;
public bool DisplayEmailType { get; set; } = false;
public bool DisplayHeaderFields { get { return !DisplayPrintHeaders; } }
public bool IsBusy { get { return isBusy; } set { isBusy = value; OnPropertyChanged(nameof(IsBusy)); OnPropertyChanged(nameof(IsNotBusy)); OnPropertyChanged("CanExportFolder"); } }
public bool IsNotBusy { get { return !isBusy; } }
public ObservableCollection<Property> CurrentProperties { get; private set; } = new ObservableCollection<Property>();
public bool IsMessagePresent { get { return (CurrentMessage != null); } }
public bool CanSaveEmail { get { return ShowContent && CurrentMessage != null; } }
public bool CanPopMessage { get { return (stackMessage.Count > 0); } }
public bool CanExportFolder { get { return !IsBusy && SelectedFolder != null; } }
public bool CanExportProperties { get { return IsMessagePresent && ShowProperties; } }
public bool IsAttachmentPresent { get { return (ShowContent && CurrentMessage != null && CurrentMessage.HasAttachment); } }
public bool IsFileAttachmentPresent { get { return (ShowContent && CurrentMessage != null && CurrentMessage.HasFileAttachment); } }
public bool IsFileAttachmentSelected { get { return fileAttachmentSelected; } set { fileAttachmentSelected = value; OnPropertyChanged("IsFileAttachmentSelected"); } }
public bool IsEmailAttachmentPresent { get { return (ShowContent && CurrentMessage != null && CurrentMessage.HasEmailAttachment); } }
public bool IsEmailAttachmentSelected { get { return emailAttachmentSelected; } set { emailAttachmentSelected = value; OnPropertyChanged("IsEmailAttachmentSelected"); } }
public Message CurrentMessage
{
get { return currentMessage; }
private set
{
currentMessage = value;
OnPropertyChanged(nameof(IsMessagePresent));
OnPropertyChanged(nameof(CanSaveEmail));
OnPropertyChanged(nameof(IsAttachmentPresent));
OnPropertyChanged(nameof(IsFileAttachmentPresent));
OnPropertyChanged(nameof(IsEmailAttachmentPresent));
}
}
public bool ShowProperties { get { return !showContent; } }
public bool ShowContent {
get { return showContent; }
set
{
showContent = value;
OnPropertyChanged("ShowContent");
OnPropertyChanged("ShowProperties");
OnPropertyChanged("CanSaveEmail");
OnPropertyChanged("CanExportProperties");
OnPropertyChanged("IsAttachmentPresent");
OnPropertyChanged("IsFileAttachmentPresent");
OnPropertyChanged("IsFileAttachmentSelected");
OnPropertyChanged("IsEmailAttachmentPresent");
OnPropertyChanged("IsEmailAttachmentSelected");
}
}
public void SelectedRecipientChanged(Recipient recipient)
{
if (recipient != null)
{
CurrentProperties.PopulateWith(recipient.Properties);
OnPropertyChanged("CurrentProperties");
}
}
public void SelectedAttachmentsChanged(IEnumerable<Attachment> selection)
{
IsFileAttachmentSelected = selection.FirstOrDefault(a => a.IsFile) != null;
IsEmailAttachmentSelected = selection.FirstOrDefault(a => a.IsEmail) != null;
var firstAttachment = selection.FirstOrDefault(a => (a.IsFile || a.IsEmail));
if (firstAttachment != null)
{
CurrentProperties.PopulateWith(firstAttachment.Properties);
OnPropertyChanged("CurrentProperties");
}
}
public void SetMessage(Message m)
{
stackMessage.Clear();
UpdateCurrentMessage(m);
}
public void PushMessage(Message m)
{
stackMessage.Push(CurrentMessage);
UpdateCurrentMessage(m);
}
public void PopMessage()
{
UpdateCurrentMessage(stackMessage.Pop());
}
public void Clear()
{
SelectedFolder = null;
CurrentMessage = null;
RootFolders.Clear();
stackMessage.Clear();
}
private void UpdateCurrentMessage(Message m)
{
CurrentMessage = m;
if (m != null)
CurrentProperties.PopulateWith(m.Properties);
else
CurrentProperties.Clear();
OnPropertyChanged("CurrentMessage");
OnPropertyChanged("CurrentProperties");
OnPropertyChanged("IsMessagePresent");
OnPropertyChanged("CanExportProperties");
OnPropertyChanged("CanPopMessage");
OnPropertyChanged("IsAttachmentPresent");
OnPropertyChanged("IsFileAttachmentPresent");
OnPropertyChanged("IsFileAttachmentSelected");
OnPropertyChanged("IsEmailAttachmentPresent");
OnPropertyChanged("IsEmailAttachmentSelected");
}
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(String info)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}
}
class Folder
{
public string Name { get; set; }
public uint ContentCount { get; set; } = 0;
public bool HasSubFolders { get; set; } = false;
public string Description { get { return String.Format("{0} ({1})", Name, ContentCount); } }
public NID Nid { get; set; } // Where folder data is held
public ObservableCollection<Folder> Folders { get; private set; } = new ObservableCollection<Folder>();
public ObservableCollection<Message> Messages { get; private set; } = new ObservableCollection<Message>();
public void AddMessage(Message m)
{
m.Folder = this;
Messages.Add(m);
}
}
class Recipient
{
public RecipientType RecipientType { get; set; }
public string DisplayName { get; set; }
public string EmailAddress { get; set; }
public List<Property> Properties { get; private set; } = new List<Property>();
}
class Property
{
public EpropertyTag Tag { get; set; }
public dynamic Value { get; set; }
// Standard properties have a Tag value less than 0x8000,
// and identify a particular property
//
// Tag values from 0x8000 to 0x8fff are named properties,
// where the Tag Is the key into a per .ost or .pst dictionary of properties
// identified by a GUID (identifying a Property Set) and a name (identifying a property Within that set),
// which can be a string or a 32-bit value
//
public string Guid { get; set; } // String representation of hex GUID
public string GuidName { get; set; } // Equivalent name, where known e.g. PSETID_Common
public UInt32? Lid { get; set; } // Property identifier, when we know it
public string Name { get; set; } // String name of property, when we know it
public bool IsNamed { get { return (UInt16)Tag >= 0x8000 && (UInt16)Tag <= 0x8fff; } }
public string DisplayId
{
get
{
return String.Format("0x{0:x4}", (UInt16)Tag);
}
}
public string Description
{
get
{
string description;
if (IsNamed)
{
return String.Format("Guid: {0}\r\nName: {1}",
GuidName != null ? GuidName : Guid,
Name != null ? Name : String.Format("0x{0:x8}", Lid));
}
else if (StandardProperties.TagToDescription.TryGetValue(Tag, out description))
return description;
else
return null;
}
}
public string CsvId
{
get
{
if (IsNamed)
// Prefix with 80 In order to ensure they collate last
return String.Format("80{0}{1:x8}", Guid, Lid);
else
return String.Format("{0:x4}", (UInt16)Tag);
}
}
public string CsvDescription
{
get
{
string description;
if (IsNamed)
{
return String.Format("{0}: {1}",
GuidName != null ? GuidName : Guid,
Name != null ? Name : String.Format("0x{0:x8}", Lid));
}
else if (StandardProperties.TagToDescription.TryGetValue(Tag, out description))
{
if (description.StartsWith("undocumented"))
return "undocumented " + DisplayId;
else
return description;
}
else
return DisplayId;
}
}
public string DisplayValue
{
get
{
if (Value is byte[])
return BitConverter.ToString(Value);
else if (Value is Int32[])
return String.Join(", ", Value);
else if (Value is string[])
return String.Join(",\r\n", Value);
else if (Value is List<byte[]>)
return String.Join(",\r\n", ((List<byte[]>)Value).Select(v => BitConverter.ToString(v)));
else if (Value == null)
return null;
else
return Value.ToString();
}
}
}
class Attachment
{
private List<Property> properties = null;
public XstFile XstFile { get; set; }
public Message Parent { get; set; }
public BTree<Node> subNodeTreeProperties { get; set; } = null; // Used when handling attachments which are themselves messages
public string DisplayName { get; set; }
public string FileNameW { get; set; }
public string LongFileName { get; set; }
public AttachFlags Flags { get; set; }
public string MimeTag { get; set; }
public string ContentId { get; set; }
public bool Hidden { get; set; }
public string FileName { get { return LongFileName ?? FileNameW; } }
public int Size { get; set; }
public NID Nid { get; set; }
public AttachMethods AttachMethod { get; set; }
public dynamic Content { get; set; }
public bool IsFile { get { return AttachMethod == AttachMethods.afByValue; } }
public bool IsEmail { get { return /*AttachMethod == AttachMethods.afStorage ||*/ AttachMethod == AttachMethods.afEmbeddedMessage; } }
public bool WasRenderedInline { get; set; } = false;
public string Type
{
get
{
if (IsFile)
return "File";
else if (IsEmail)
return "Email";
else
return "Other";
}
}
public string Description
{
get
{
if (IsFile)
return FileName;
else
return DisplayName;
}
}
public bool Hide { get { return (Hidden || IsInlineAttachment); } }
public FontWeight Weight { get { return Hide ? FontWeights.ExtraLight: FontWeights.SemiBold; } }
public bool HasContentId { get { return (ContentId != null); } }
// To do: case where ContentLocation property is used instead of ContentId
public bool IsInlineAttachment
{
get
{
// It is an in-line attachment either if the flags say it is, or the content ID
// matched a reference in the body and it was rendered inline
return ((Flags & AttachFlags.attRenderedInBody) == AttachFlags.attRenderedInBody ||
WasRenderedInline) &&
HasContentId;
}
}
public List<Property> Properties
{
get
{
// We read the full set of attachment property values only on demand
if (properties == null)
{
properties = new List<Property>();
foreach (var p in XstFile.ReadAttachmentProperties(this))
{
properties.Add(p);
}
}
return properties;
}
}
}
}