Skip to content

Commit

Permalink
Added online installer and adjusted offline installer to not require …
Browse files Browse the repository at this point in the history
…admin permissions.
  • Loading branch information
browlry authored and browlry committed Oct 9, 2019
1 parent 91030ce commit 2c2dae6
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 8 deletions.
Binary file added Screenshots/OutlookSelectFolderDialog.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Screenshots/OutlookSelectFromAddress.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Screenshots/SentFolderByFromConfirmation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions SentFolderByFrom/My Project/AssemblyInfo.vb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ Imports System.Security

' Review the values of the assembly attributes

<Assembly: AssemblyTitle("SentFolderByFrom")>
<Assembly: AssemblyDescription("")>
<Assembly: AssemblyTitle("SentFolderByFrom")>
<Assembly: AssemblyDescription("Choose a Sent Items folder for each From address.")>
<Assembly: AssemblyCompany("")>
<Assembly: AssemblyProduct("SentFolderByFrom")>
<Assembly: AssemblyCopyright("Copyright © 2019")>
Expand Down
41 changes: 37 additions & 4 deletions SentFolderByFrom/SentFolderByFrom.vbproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,38 @@
<OutputType>Library</OutputType>
<RootNamespace>SentFolderByFrom</RootNamespace>
<AssemblyName>SentFolderByFrom</AssemblyName>
<LoadBehavior>3</LoadBehavior>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<DefineConstants>VSTO40</DefineConstants>
<StartupObject>
</StartupObject>
<IsWebBootstrapper>True</IsWebBootstrapper>
<BootstrapperEnabled>true</BootstrapperEnabled>
<BootstrapperComponentsLocation>HomeSite</BootstrapperComponentsLocation>
<PublishUrl>publish\</PublishUrl>
<InstallUrl>https://github.com/browlry/SentFolderByFrom/tree/master/publish/</InstallUrl>
<TargetCulture>en</TargetCulture>
<ApplicationVersion>1.0.0.4</ApplicationVersion>
<AutoIncrementApplicationRevision>true</AutoIncrementApplicationRevision>
<UpdateEnabled>true</UpdateEnabled>
<UpdateInterval>4</UpdateInterval>
<UpdateIntervalUnits>weeks</UpdateIntervalUnits>
<ProductName>SentFolderByFrom</ProductName>
<PublisherName>browlry</PublisherName>
<SupportUrl>https://github.com/browlry/SentFolderByFrom/issues</SupportUrl>
<FriendlyName>SentFolderByFrom</FriendlyName>
<OfficeApplicationDescription>Prompts you to pick a "Sent Items" folder for each "From" address you use.</OfficeApplicationDescription>
<LoadBehavior>3</LoadBehavior>
</PropertyGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.5.2">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4.5.2 %28x86 and x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.VSTORuntime.4.0">
<Visible>False</Visible>
<ProductName>Microsoft Visual Studio 2010 Tools for Office Runtime %28x86 and x64%29</ProductName>
Expand Down Expand Up @@ -176,6 +199,7 @@
<Compile Include="ThisAddIn.vb">
<SubType>Code</SubType>
</Compile>
<None Include="SentFolderByFrom_TemporaryKey.pfx" />
<None Include="ThisAddIn.Designer.xml">
<DependentUpon>ThisAddIn.vb</DependentUpon>
</None>
Expand Down Expand Up @@ -217,6 +241,15 @@
<PropertyGroup>
<OptionStrict>Off</OptionStrict>
</PropertyGroup>
<PropertyGroup>
<SignManifests>true</SignManifests>
</PropertyGroup>
<PropertyGroup>
<ManifestKeyFile>SentFolderByFrom_TemporaryKey.pfx</ManifestKeyFile>
</PropertyGroup>
<PropertyGroup>
<ManifestCertificateThumbprint>22E5D0AEABC8515B3624BE2B895D4C9FF8442776</ManifestCertificateThumbprint>
</PropertyGroup>
<!-- Include the build rules for a Visual Basic project. -->
<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
<!-- Include additional build rules for an Office application add-in. -->
Expand All @@ -226,8 +259,8 @@
<VisualStudio>
<FlavorProperties GUID="{BAA0C2D2-18E2-41B9-852F-F413020CAA33}">
<ProjectProperties HostName="Outlook" HostPackage="{29A7B9D7-A7F1-4328-8EF0-6B2D1A56B2C1}" OfficeVersion="15.0" VstxVersion="4.0" ApplicationType="Outlook" Language="vb" TemplatesPath="" DebugInfoExeName="#Software\Microsoft\Office\16.0\Outlook\InstallRoot\Path#outlook.exe" AddItemTemplatesGuid="{5D898164-AEB5-470F-97BA-9253F022FD71}" />
<Host Name="Outlook" IconIndex="0">
<HostItem Name="ThisAddIn" Code="ThisAddIn.vb" CanonicalName="ThisAddIn" CanActivate="false" IconIndex="1" Blueprint="ThisAddIn.Designer.xml" GeneratedCode="ThisAddIn.Designer.vb" />
<Host Name="Outlook" PublishedHash="69C324AB27932AA2FBF2B7EA72250886FF164DE6" IconIndex="0">
<HostItem Name="ThisAddIn" Code="ThisAddIn.vb" CanonicalName="AddIn" PublishedHash="341B421006973DA6ECFF9E7771C273C5532C588D" CanActivate="false" IconIndex="1" Blueprint="ThisAddIn.Designer.xml" GeneratedCode="ThisAddIn.Designer.vb" />
</Host>
</FlavorProperties>
</VisualStudio>
Expand Down
110 changes: 108 additions & 2 deletions SentFolderByFrom/ThisAddIn.vb
Original file line number Diff line number Diff line change
@@ -1,11 +1,117 @@
Public Class ThisAddIn

Private Sub ThisAddIn_Startup() Handles Me.Startup
Private OSentItemsFolder As Outlook.Folder
Public WithEvents OSentItems As Outlook.Items
Private mapiNameSpace As Outlook.NameSpace
Private primaryEmail As String
Private SentItemFolders As Dictionary(Of String, String)
Private binarify As New Runtime.Serialization.Formatters.Binary.BinaryFormatter()
Private UserConfigFolder As String = Environment.GetEnvironmentVariable("appdata") & "\browlry\SentFolderByFrom"
Private UserConfigPath As String = UserConfigFolder & "\userconfig.bin"

'When Outlook starts:
Private Sub ThisAddIn_Startup() Handles Me.Startup
' Create the folder for storing user settings, if it doesn't exist
If (Not System.IO.Directory.Exists(UserConfigFolder)) Then
System.IO.Directory.CreateDirectory(UserConfigFolder)
End If
primaryEmail = Application.Session.CurrentUser.Address
'Monitor the messages in the Sent Items folder; trigger OSentItems_ItemAdd when a new message is added
mapiNameSpace = Application.GetNamespace("MAPI")
OSentItemsFolder = mapiNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail)
OSentItems = OSentItemsFolder.Items
AddHandler OSentItems.ItemAdd, AddressOf OSentItems_ItemAdd
'Load the user settings file into the SentItemsFolders dictionary, or create the dictionary if the file doesn't exist or is empty.
If IO.File.Exists(UserConfigPath) Then
Dim fsRead As New IO.FileStream(UserConfigPath, IO.FileMode.Open, IO.FileAccess.Read, IO.FileShare.None)
If fsRead.Length > 0 Then
SentItemFolders = binarify.Deserialize(fsRead)
Else
SentItemFolders = New Dictionary(Of String, String)
End If
fsRead.Close()
Else
SentItemFolders = New Dictionary(Of String, String)
End If
End Sub

Private Sub ThisAddIn_Shutdown() Handles Me.Shutdown

End Sub

End Class
Private Sub OSentItems_ItemAdd(ByVal myItem As Object) 'specifies the actions when a new item is added to the Sent Items folder
'Determine if the item sent is MailItem
If TypeName(myItem) = "MailItem" Then
Call MoveToNewSentFolder(myItem) 'calls the ChangeSentFolder function when a mail item is sent
End If
End Sub

Private Sub MoveToNewSentFolder(myItem As Object)
' Inspired by https://www.itprotoday.com/management-mobility/outlook-2010-move-mailitems-after-sending
Dim NewSentItemsFolder As Outlook.Folder
Dim NewSentItemsPath As String
Dim fromAddress As String
'Identify sender address
If myItem.Sender IsNot Nothing Then
fromAddress = myItem.Sender.Address.ToString
' If the item is not sent from the primary email address...
If (fromAddress <> primaryEmail) Then
' See if there is a saved "Sent" folder for that address, and if not
If Not SentItemFolders.ContainsKey(fromAddress) Then
' Prompt the user to choose a folder for the sent items.
System.Windows.Forms.MessageBox.Show("Click OK to select the 'Sent Items' folder for items sent from " & fromAddress)
NewSentItemsFolder = mapiNameSpace.PickFolder
'If the user doesn't pick anything, stop
If NewSentItemsFolder Is Nothing Then
Exit Sub
End If
'Save the path of the folder chosen for future reference.
NewSentItemsPath = NewSentItemsFolder.FolderPath
SentItemFolders.Add(fromAddress, NewSentItemsPath)
Dim fs As IO.FileStream = New IO.FileStream(UserConfigPath, IO.FileMode.Create, IO.FileAccess.Write, IO.FileShare.None)
binarify.Serialize(fs, SentItemFolders)
fs.Close()
Else
' If there is a "Sent" folder associated with that email aleady, retrieve that folder.
NewSentItemsPath = SentItemFolders(fromAddress)
NewSentItemsFolder = GetFolder(NewSentItemsPath)
End If
' Move the mail item to the appropriate folder.
myItem.Move(NewSentItemsFolder)
End If
End If
End Sub

Function GetFolder(ByVal FolderPath As String) As Outlook.Folder
'This function courtesy of https://docs.microsoft.com/en-us/office/vba/outlook/how-to/items-folders-and-stores/obtain-a-folder-object-from-a-folder-path
Dim TestFolder As Outlook.Folder
Dim FoldersArray As Object
Dim i As Integer

On Error GoTo GetFolder_Error
If Left(FolderPath, 2) = "\\" Then
FolderPath = Right(FolderPath, Len(FolderPath) - 2)
End If
'Convert folderpath to array
FoldersArray = Split(FolderPath, "\")
TestFolder = Application.Session.Folders.Item(FoldersArray(0))
If Not TestFolder Is Nothing Then
For i = 1 To UBound(FoldersArray, 1)
Dim SubFolders As Outlook.Folders
SubFolders = TestFolder.Folders
TestFolder = SubFolders.Item(FoldersArray(i))
If TestFolder Is Nothing Then
GetFolder = Nothing
End If
Next
End If
'Return the TestFolder
GetFolder = TestFolder
Exit Function

GetFolder_Error:
GetFolder = Nothing
Exit Function
End Function

End Class

0 comments on commit 2c2dae6

Please sign in to comment.