Skip to content

Commit

Permalink
Merge pull request #1 from Dijji/Divided
Browse files Browse the repository at this point in the history
Divided
  • Loading branch information
iluvadev authored Dec 28, 2020
2 parents b09b191 + daca136 commit c56295e
Show file tree
Hide file tree
Showing 11 changed files with 278 additions and 159 deletions.
34 changes: 34 additions & 0 deletions FolderView.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright (c) 2020, Dijji, and released under Ms-PL. This can be found in the root of this distribution.

using System;
using System.Collections.ObjectModel;

namespace XstReader
{
public class FolderView
{
public Folder Folder { get; private set; }
public string Name { get { return Folder.Name; } }
public uint ContentCount { get { return Folder.ContentCount; } }
public string Description { get { return String.Format("{0} ({1})", Name, ContentCount); } }
public ObservableCollection<FolderView> FolderViews { get; private set; } = new ObservableCollection<FolderView>();
public ObservableCollection<MessageView> MessageViews { get; private set; } = new ObservableCollection<MessageView>();

public FolderView(Folder folder)
{
if (folder == null)
throw new XstException("FolderView requires a Folder object");

Folder = folder;

// Recursively add views for any subfolders
foreach (Folder f in folder.Folders)
FolderViews.Add(new FolderView(f));
}

public void AddMessage(Message m)
{
MessageViews.Add(new MessageView(m));
}
}
}
6 changes: 3 additions & 3 deletions MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
<RowDefinition Height="*"/>
<RowDefinition Height="30"/>
</Grid.RowDefinitions>
<TreeView Grid.Column="0" Grid.Row="0" Name="treeFolders" ItemsSource="{Binding Path=RootFolders}" FontSize="12" SelectedItemChanged="treeFolders_SelectedItemChanged">
<TreeView Grid.Column="0" Grid.Row="0" Name="treeFolders" ItemsSource="{Binding Path=RootFolderViews}" FontSize="12" SelectedItemChanged="treeFolders_SelectedItemChanged">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Path=Folders}">
<HierarchicalDataTemplate ItemsSource="{Binding Path=FolderViews}">
<Grid>
<TextBlock Text="{Binding Path=Description}" />
</Grid>
Expand Down Expand Up @@ -66,7 +66,7 @@
</StackPanel>
</Grid>
<GridSplitter Grid.Row="0" Grid.Column="1" Width="3" HorizontalAlignment="Stretch" />
<ListView Grid.Row="0" Grid.Column="2" Name="listMessages" Margin="0,0,0,0" DataContext="{Binding Path=SelectedFolder}" ItemsSource="{Binding Path=Messages}"
<ListView Grid.Row="0" Grid.Column="2" Name="listMessages" Margin="0,0,0,0" DataContext="{Binding Path=SelectedFolder}" ItemsSource="{Binding Path=MessageViews}"
SelectionChanged="listMessages_SelectionChanged" FontSize="12"
ItemContainerStyle="{StaticResource ResourceKey=ListViewSelect}">
<ListView.View>
Expand Down
137 changes: 68 additions & 69 deletions MainWindow.xaml.cs

Large diffs are not rendered by default.

132 changes: 132 additions & 0 deletions MessageView.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
// Copyright (c) 2016,2019,2020, 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.IO;
using System.Linq;

namespace XstReader
{
// Provides a view of a Message object for the UI

public class MessageView : INotifyPropertyChanged
{
private bool isSelected = false;

public MessageView(Message message)
{
if (message == null)
throw new XstException("MessageView requires a Message object");
Message = message;
}

public Message Message { get; private set; }
public string From { get { return Message.From; } }
public string To { get { return Message.To; } }
public string Cc { get { return Message.Cc; } }
public string FromTo { get { return Message.Folder.Name.StartsWith("Sent") ? To : From; } }
public string Subject { get { return Message.Subject; } }
public DateTime? Received { get { return Message.Received; } }
public DateTime? Submitted { get { return Message.Submitted; } }
public DateTime? Modified { get { return Message.Modified; } } // When any attachment was last modified
public DateTime? Date { get { return Received ?? Submitted; } }
public string DisplayDate { get { return Date != null ? ((DateTime)Date).ToString("g") : "<unknown>"; } }
public BodyType NativeBody { get { return Message.NativeBody; } }
public string Body { get { return Message.Body; } }
public string BodyHtml { get { return Message.BodyHtml; } }
public byte[] Html { get { return Message.Html; } }
public byte[] RtfCompressed { get { return Message.RtfCompressed; } }
public ObservableCollection<Attachment> Attachments { get; private set; } = new ObservableCollection<Attachment>();
public List<Recipient> Recipients { get { return Message.Recipients; } }
public List<Property> Properties { get { return Message.Properties; } }
public bool MayHaveInlineAttachment { get { return Message.MayHaveInlineAttachment; } }
public bool IsEncryptedOrSigned { get { return Message.IsEncryptedOrSigned; } }

// The following properties are used in XAML bindings to control the UI
public bool HasAttachment { get { return Message.HasAttachment; } }
public bool HasFileAttachment { get { return Message.HasFileAttachment; } }
public bool HasVisibleFileAttachment { get { return (Attachments.FirstOrDefault(a => a.IsFile && !a.Hide) != null); } }
public bool HasEmailAttachment { get { return (Attachments.FirstOrDefault(a => a.IsEmail) != null); } }
public bool ShowText { get { return Message.IsBodyText; } }
public bool ShowHtml { get { return Message.IsBodyHtml; } }
public bool ShowRtf { get { return Message.IsBodyRtf; } }

public bool HasToDisplayList { get { return ToDisplayList.Length > 0; } }
public string ToDisplayList { get { return Message.ToDisplayList; } }
public bool HasCcDisplayList { get { return CcDisplayList.Length > 0; } }
public string CcDisplayList { get { return Message.CcDisplayList; } }
public bool HasBccDisplayList { get { return BccDisplayList.Length > 0; } }
public string BccDisplayList { get { return Message.BccDisplayList; } }
public string FileAttachmentDisplayList { get { return Message.FileAttachmentDisplayList; } }
public string ExportFileName { get { return Message.ExportFileName; } }

public bool IsSelected
{
get { return isSelected; }
set
{
if (value != isSelected)
{
isSelected = value;
OnPropertyChanged(nameof(IsSelected));
}
}
}


public void ClearContents()
{
Message.ClearContents();
Attachments.Clear();
}

public void ReadSignedOrEncryptedMessage(XstFile xstFile)
{
Attachment a = Message.Attachments[0];

//get attachment bytes
var ms = new MemoryStream();
xstFile.SaveAttachment(ms, a);
byte[] attachmentBytes = ms.ToArray();

Message.ReadSignedOrEncryptedMessage(attachmentBytes);
}

public void SortAndSaveAttachments(List<Attachment> atts = null)
{
// If no attachments are supplied, sort the list we already have
if (atts == null)
atts = new List<Attachment>(Attachments);

atts.Sort((a, b) =>
{
if (a == null)
return -1;
else if (b == null)
return 1;
else if (a.Hide != b.Hide)
return a.Hide ? 1 : -1;
else
return 0;
});

Attachments.Clear();
foreach (var a in atts)
Attachments.Add(a);
}

public event PropertyChangedEventHandler PropertyChanged;

private void OnPropertyChanged(String info)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}

}

}
30 changes: 15 additions & 15 deletions View.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ namespace XstReader

public class View : INotifyPropertyChanged
{
private Folder selectedFolder = null;
private Message currentMessage = null;
private FolderView selectedFolder = null;
private MessageView currentMessage = null;
private bool isBusy = false;
private Stack<Message> stackMessage = new Stack<Message>();
private Stack<MessageView> stackMessage = new Stack<MessageView>();
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
public ObservableCollection<FolderView> RootFolderViews { get; private set; } = new ObservableCollection<FolderView>();
public FolderView SelectedFolder
{
get { return selectedFolder; }
set { selectedFolder = value; OnPropertyChanged(nameof(SelectedFolder), nameof(CanExportFolder)); }
Expand All @@ -43,7 +43,7 @@ public Folder SelectedFolder
public bool IsEmailAttachmentPresent { get { return (ShowContent && CurrentMessage != null && CurrentMessage.HasEmailAttachment); } }
public bool IsEmailAttachmentSelected { get { return emailAttachmentSelected; } set { emailAttachmentSelected = value; OnPropertyChanged(nameof(IsEmailAttachmentSelected)); } }

public Message CurrentMessage
public MessageView CurrentMessage
{
get { return currentMessage; }
private set
Expand Down Expand Up @@ -102,18 +102,18 @@ public void SelectedAttachmentsChanged(IEnumerable<Attachment> selection)
}
}

public void SetMessage(Message m)
public void SetMessage(MessageView mv)
{
if (CurrentMessage != null)
CurrentMessage.ClearContents();
stackMessage.Clear();
UpdateCurrentMessage(m);
UpdateCurrentMessage(mv);
}

public void PushMessage(Message m)
public void PushMessage(MessageView mv)
{
stackMessage.Push(CurrentMessage);
UpdateCurrentMessage(m);
UpdateCurrentMessage(mv);
}

public void PopMessage()
Expand All @@ -125,15 +125,15 @@ public void Clear()
{
SelectedFolder = null;
CurrentMessage = null;
RootFolders.Clear();
RootFolderViews.Clear();
stackMessage.Clear();
}

private void UpdateCurrentMessage(Message m)
private void UpdateCurrentMessage(MessageView mv)
{
CurrentMessage = m;
if (m != null)
CurrentProperties.PopulateWith(m.Properties);
CurrentMessage = mv;
if (mv != null)
CurrentProperties.PopulateWith(mv.Properties);
else
CurrentProperties.Clear();

Expand Down
Loading

0 comments on commit c56295e

Please sign in to comment.