Skip to content

Commit

Permalink
Fixes from v 1.7 pre release testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Dijji committed Dec 4, 2019
1 parent b7d2ab6 commit 741adac
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 52 deletions.
11 changes: 7 additions & 4 deletions MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,9 @@
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Disabled">
<StackPanel Grid.Row="0" Orientation="Vertical">
<ScrollViewer Grid.Row="0" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Disabled"
Visibility="{Binding Path=DisplayHeaderFields, Converter={StaticResource VisibleIfTrue}}">
<StackPanel Margin="10,0,0,0" Orientation="Vertical">
<TextBlock DataContext="{Binding Path=CurrentMessage}" Text="{Binding Path=Subject}"
FontSize="14" FontWeight="Bold"/>
<TextBlock DataContext="{Binding Path=CurrentMessage}" Text="{Binding Path=From}"
Expand Down Expand Up @@ -170,11 +171,13 @@
</StackPanel>
</ScrollViewer>
<Grid Grid.Row="1" Visibility="{Binding ShowContent, Converter={StaticResource VisibleIfTrue}}">
<TextBox Name="txtMessage" DataContext="{Binding Path=CurrentMessage}"
<ScrollViewer Name="scrollTextMessage" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
<TextBox Name="txtMessage" Margin="10,10,0,0" BorderBrush="Transparent" TextWrapping="Wrap" DataContext="{Binding Path=CurrentMessage}"
Visibility="{Binding ShowText, Converter={StaticResource VisibleIfTrue}}"/>
</ScrollViewer>
<WebBrowser Name="wbMessage" DataContext="{Binding Path=CurrentMessage}"
Visibility="{Binding ShowHtml, Converter={StaticResource VisibleIfTrue}}"/>
<RichTextBox Name="rtfMessage" DataContext="{Binding Path=CurrentMessage}"
<RichTextBox Name="rtfMessage" Margin="5,10,0,0" BorderBrush="Transparent" DataContext="{Binding Path=CurrentMessage}"
Visibility="{Binding ShowRtf, Converter={StaticResource VisibleIfTrue}}"/>
</Grid>
<Grid Grid.Row="1" Visibility="{Binding ShowProperties, Converter={StaticResource VisibleIfTrue}}">
Expand Down
75 changes: 43 additions & 32 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ public MainWindow()
InitializeComponent();
this.DataContext = view;

// For testing purposes, set this to true to display print headers
// For testing purposes, use these flags to control the display of print headers
//view.DisplayPrintHeaders = true;
//view.DisplayEmailType = true;

// Supply the Search control with the list of sections
searchTextBox.SectionsList = new List<string> { "Subject", "From/To", "Date" };
Expand All @@ -55,9 +56,6 @@ public void OpenFile(string fileName)
if (!System.IO.File.Exists(fileName))
return;

Properties.Settings.Default.LastFolder = System.IO.Path.GetDirectoryName(fileName);
Properties.Settings.Default.Save();

view.Clear();
ShowStatus("Loading...");
Mouse.OverrideCursor = Cursors.Wait;
Expand Down Expand Up @@ -87,23 +85,13 @@ public void OpenFile(string fileName)
});
}


private void btnOpen_Click(object sender, RoutedEventArgs e)
{
// Ask for a .ost or .pst file to open
System.Windows.Forms.OpenFileDialog dialog = new System.Windows.Forms.OpenFileDialog();
string fileName = GetXstFileName();

dialog.Filter = "xst files (*.ost;*.pst)|*.ost;*.pst|All files (*.*)|*.*";
dialog.FilterIndex = 1;
dialog.InitialDirectory = Properties.Settings.Default.LastFolder;
if (dialog.InitialDirectory == "")
dialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
dialog.RestoreDirectory = true;

if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
OpenFile(dialog.FileName);
}
if (fileName != null)
OpenFile(fileName);
}

private void exportAllProperties_Executed(object sender, ExecutedRoutedEventArgs e)
Expand Down Expand Up @@ -362,7 +350,7 @@ private void SaveAllAttachmentsToFolder(string fullFolderName, Message m)
{
foreach (var a in m.Attachments.Where(a => a.IsFile))
{
xstFile.SaveAttachmentToFolder(fullFolderName, a);
xstFile.SaveAttachmentToFolder(fullFolderName, m.Date, a);
}
}

Expand Down Expand Up @@ -516,7 +504,7 @@ private void ShowMessage(Message m)
{
// For testing purposes, can show print header in main visualisation
if (view.DisplayPrintHeaders)
body = m.EmbedHtmlPrintHeader(body, true);
body = m.EmbedHtmlPrintHeader(body, view.DisplayEmailType);

wbMessage.NavigateToString(body);
if (m.MayHaveInlineAttachment)
Expand All @@ -532,7 +520,7 @@ private void ShowMessage(Message m)

// For testing purposes, can show print header in main visualisation
if (view.DisplayPrintHeaders)
m.EmbedRtfPrintHeader(body, true);
m.EmbedRtfPrintHeader(body, view.DisplayEmailType);

rtfMessage.Document = body;
}
Expand All @@ -543,9 +531,10 @@ private void ShowMessage(Message m)

// For testing purposes, can show print header in main visualisation
if (view.DisplayPrintHeaders)
body = m.EmbedTextPrintHeader(body, true);
body = m.EmbedTextPrintHeader(body, true, view.DisplayEmailType);

txtMessage.Text = body;
scrollTextMessage.ScrollToHome();
}
}
else
Expand All @@ -569,7 +558,29 @@ private void OpenEmailAttachment (Attachment a)
view.PushMessage(m);
}

#region File and folder dialogs
#region File and folder dialogs

private string GetXstFileName()
{
// Ask for a .ost or .pst file to open
System.Windows.Forms.OpenFileDialog dialog = new System.Windows.Forms.OpenFileDialog();

dialog.Filter = "xst files (*.ost;*.pst)|*.ost;*.pst|All files (*.*)|*.*";
dialog.FilterIndex = 1;
dialog.InitialDirectory = Properties.Settings.Default.LastFolder;
if (dialog.InitialDirectory == "")
dialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
dialog.RestoreDirectory = true;

if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
Properties.Settings.Default.LastFolder = Path.GetDirectoryName(dialog.FileName);
Properties.Settings.Default.Save();
return dialog.FileName;
}
else
return null;
}

private string GetAttachmentsSaveFolderName()
{
Expand All @@ -593,20 +604,20 @@ private string GetAttachmentsSaveFolderName()
return null;
}

private string GetSaveAttachmentFileNam(string defaultFileName)
private string GetSaveAttachmentFileName(string defaultFileName)
{
var dialog = new System.Windows.Forms.SaveFileDialog();

dialog.Title = "Specify file to save to";
dialog.InitialDirectory = Properties.Settings.Default.LastAttachmentFolder;
if (dialog.InitialDirectory == "")
dialog.InitialDirectory = Properties.Settings.Default.LastFolder;
dialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
dialog.Filter = "All Files (*.*)|*.*";
dialog.FileName = defaultFileName;

if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
Properties.Settings.Default.LastAttachmentFolder = Path.GetFullPath(dialog.FileName);
Properties.Settings.Default.LastAttachmentFolder = Path.GetDirectoryName(dialog.FileName);
Properties.Settings.Default.Save();
return dialog.FileName;
}
Expand Down Expand Up @@ -643,13 +654,13 @@ private string GetEmailExportFileName(string defaultFileName, string extension)
dialog.Title = "Specify file to save to";
dialog.InitialDirectory = Properties.Settings.Default.LastExportFolder;
if (dialog.InitialDirectory == "")
dialog.InitialDirectory = Properties.Settings.Default.LastFolder;
dialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
dialog.Filter = String.Format("{0} Files (*.{0})|*.{0}|All Files (*.*)|*.*", extension);
dialog.FileName = defaultFileName;

if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
Properties.Settings.Default.LastExportFolder = Path.GetFullPath(dialog.FileName);
Properties.Settings.Default.LastExportFolder = Path.GetDirectoryName(dialog.FileName);
Properties.Settings.Default.Save();
return dialog.FileName;
}
Expand All @@ -664,13 +675,13 @@ private string GetPropertiesExportFileName(string defaultName)
dialog.Title = "Specify properties export file";
dialog.InitialDirectory = Properties.Settings.Default.LastExportFolder;
if (dialog.InitialDirectory == "")
dialog.InitialDirectory = Properties.Settings.Default.LastFolder;
dialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
dialog.Filter = "csv files (*.csv)|*.csv";
dialog.FileName = defaultName;

if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
Properties.Settings.Default.LastExportFolder = System.IO.Path.GetFullPath(dialog.FileName);
Properties.Settings.Default.LastExportFolder = Path.GetDirectoryName(dialog.FileName);
Properties.Settings.Default.Save();
return dialog.FileName;
}
Expand Down Expand Up @@ -720,7 +731,7 @@ private string SaveAttachmentToTemporaryFile(Attachment a)

try
{
xstFile.SaveAttachment(fileFullName, listAttachments.SelectedItem as Attachment);
xstFile.SaveAttachment(fileFullName, null, listAttachments.SelectedItem as Attachment);
tempFileNames.Add(fileFullName);
return fileFullName;
}
Expand Down Expand Up @@ -799,13 +810,13 @@ private void openAttachmentWith_Executed(object sender, ExecutedRoutedEventArgs
private void saveAttachmentAs_Executed(object sender, ExecutedRoutedEventArgs e)
{
var a = listAttachments.SelectedItem as Attachment;
var fullFileName = GetSaveAttachmentFileNam(a.LongFileName);
var fullFileName = GetSaveAttachmentFileName(a.LongFileName);

if (fullFileName != null)
{
try
{
xstFile.SaveAttachment(fullFileName, a);
xstFile.SaveAttachment(fullFileName, view.CurrentMessage.Date, a);
}
catch (System.Exception ex)
{
Expand Down
26 changes: 13 additions & 13 deletions Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,26 +209,26 @@ public FlowDocument GetBodyAsFlowDocument()
return doc;
}

public string EmbedTextPrintHeader(string body, bool showType = false)
public string EmbedTextPrintHeader(string body, bool forDisplay = false, bool showEmailType = false)
{
string row = "{0,-10}: {1}\r\n";
string row = forDisplay ? "{0,-15}\t{1}\r\n" : "{0,-15}{1}\r\n";
StringBuilder header = new StringBuilder();
header.AppendFormat(row, "Sent", String.Format("{0:dd MMMM yyyy HHmm}", Date));
header.AppendFormat(row, showType ? "Text From" : "From", From);
header.AppendFormat(row, "To", ToDisplayList);
header.AppendFormat(row, "Sent:", String.Format("{0:dd MMMM yyyy HHmm}", Date));
header.AppendFormat(row, showEmailType ? "Text From:" : "From:", From);
header.AppendFormat(row, "To:", ToDisplayList);
if (HasCcDisplayList)
header.AppendFormat(row, "Cc", CcDisplayList);
header.AppendFormat(row, "Cc:", CcDisplayList);
if (HasBccDisplayList)
header.AppendFormat(row, "Bcc", BccDisplayList);
header.AppendFormat(row, "Subject", Subject);
header.AppendFormat(row, "Bcc:", BccDisplayList);
header.AppendFormat(row, "Subject:", Subject);
if (HasFileAttachment)
header.AppendFormat(row, "Attachments", FileAttachmentDisplayList);
header.AppendFormat(row, "Attachments:", FileAttachmentDisplayList);
header.Append("\r\n\r\n");

return header.ToString() + body ?? "";
}

public string EmbedHtmlPrintHeader(string body, bool showType = false)
public string EmbedHtmlPrintHeader(string body, bool showEmailType = false)
{
if (body == null)
return null;
Expand All @@ -248,7 +248,7 @@ public string EmbedHtmlPrintHeader(string body, bool showType = false)
//omit MyName and the line under it for now, as we have no reliable source for it
//header.AppendFormat("<h3>{0}</h3><hr/><table><tbody>", MyName);
header.Append("<table><tbody style=\"font-family:serif;font-size:12px;\">");
header.AppendFormat(row, showType ? "HTML From:" : "From:", From);
header.AppendFormat(row, showEmailType ? "HTML From:" : "From:", From);
header.AppendFormat(row, "Sent:", String.Format("{0:dd MMMM yyyy HH:mm}", Date));
header.AppendFormat(row, "To:", ToDisplayList);
if (HasCcDisplayList)
Expand Down Expand Up @@ -279,7 +279,7 @@ private bool LookForInsertionPoint(string body, string tag, out int insertAt)
}
}

public void EmbedRtfPrintHeader(FlowDocument doc, bool showType = false)
public void EmbedRtfPrintHeader(FlowDocument doc, bool showEmailType = false)
{
if (doc == null)
return;
Expand All @@ -297,7 +297,7 @@ public void EmbedRtfPrintHeader(FlowDocument doc, bool showType = false)
table1.Columns.Add(new TableColumn { Width = new GridLength(500) });
table1.RowGroups.Add(new TableRowGroup());

AddRtfTableRow(table1, showType ? "RTF From:" : "From:", From);
AddRtfTableRow(table1, showEmailType ? "RTF From:" : "From:", From);

AddRtfTableRow(table1, "Sent:", String.Format("{0:dd MMMM yyyy HH:mm}", Date));
AddRtfTableRow(table1, "To:", ToDisplayList);
Expand Down
2 changes: 2 additions & 0 deletions View.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ 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>();
Expand Down
8 changes: 5 additions & 3 deletions XstFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public List<Property> ReadAttachmentProperties(Attachment a)
}

const int MaxPath = 260;
public void SaveAttachmentToFolder(string folderpath, Attachment a)
public void SaveAttachmentToFolder(string folderpath, DateTime? creationTime, Attachment a)
{
var fullFileName = Path.Combine(folderpath, a.FileName);

Expand All @@ -255,15 +255,17 @@ public void SaveAttachmentToFolder(string folderpath, Attachment a)
.Truncate(MaxPath - folderpath.Length - ext.Length - 5) + ext;
fullFileName = Path.Combine(folderpath, att);
}
SaveAttachment(fullFileName, a);
SaveAttachment(fullFileName, creationTime, a);
}

public void SaveAttachment(string fullFileName, Attachment a)
public void SaveAttachment(string fullFileName, DateTime? creationTime, Attachment a)
{
using (var afs = new FileStream(fullFileName, FileMode.Create, FileAccess.Write))
{
SaveAttachment(afs, a);
}
if (creationTime != null)
File.SetCreationTime(fullFileName, (DateTime)creationTime);
}

public void SaveAttachment(Stream s, Attachment a)
Expand Down

0 comments on commit 741adac

Please sign in to comment.