-
Email finder.
I have a directory where thousands of emails archived in eml/msg format.
What I want to do is to search in them with multiple conditions.
Like if a message having following characteristics.
From: [email protected]
To: [email protected]
Subject: abc
Body: abc
then it shows it in the search results but if I dont defined any above option then it do not look for it.
Date and time (in headers) feature will be a plus.
-
Re: Email finder.
Try something like this. Modify as necessary to fit your individual needs.
Code:
Private Sub Command1_Click()
Dim strLoad As String
Dim arrLines() As String
Dim lngCount As Long
Dim i As Long
List1.Clear
strLoad = Dir("d:\*.txt")
Do While strLoad > vbNullString
Open "d:\" & strLoad For Input As #1
arrLines = Split(Input(LOF(1), 1), vbCrLf)
Close #1
lngCount = UBound(arrLines)
For i = 0 To lngCount
If InStr(1, arrLines(i), "abc.com") > 0 Then
'your string is found, do something.
'for my example I'm simply loading the
'file name in a listbox
List1.AddItem strLoad
End If
Next
strLoad = Dir
Loop
End Sub
-
Re: Email finder.
How do I make classification between To, From, Body, Suject lines? This is the biggest issue for me i-e search two string in each line like for "Suject" if a single line has both "Subject:" and "Important" strings then it shows it, same goes to other items.
-
Re: Email finder.
If I understand correctly from your original post you are trying to search on 4 fields (From, To, Subject and Body) so you will have to modify Hack's code to take that into account.
Basically I suggest you search for "From:" then check whether the data following that meets your search criteria, if it does you then search for "To:" and check whether the data following matches your search criteria, then the same for "Subject:" and finally search the body of the message for whatever you are looking for. If any of the tests fail or any of your search criteria are null then stop / don't start the search.
-
Re: Email finder.
OK I am trying something like this.
If InStr(1, arrLines(i), "To:") And InStr(1, arrLines(i), "Azfar") > 0 Then
List1.AddItem strLoad
End If
Now few issues here.
1.How do I disable case-sensitive.
2. How do I remove duplicates from result. i-e it a set of string found in more then one place then from result (list1) how do I remove the duplicates.
-
Re: Email finder.
1. Use the UCase Function, vis:
Code:
If InStr(1, UCase(arrLines(i)), UCase("To:") And InStr(1, UCase(arrLines(i)), UCase("Azfar")) > 0 Then
2. You could use the SendMessage API and the LB_FindStringExact message (http://msdn.microsoft.com/en-us/library/ms929933.aspx) to check if the entry already exists before adding it to the ListBox.
-
Re: Email finder.