Results 1 to 7 of 7

Thread: Email finder.

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2003
    Location
    Karachi
    Posts
    58

    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.
    Last edited by azfar; Dec 19th, 2008 at 06:50 AM.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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

  3. #3

    Thread Starter
    Member
    Join Date
    Jun 2003
    Location
    Karachi
    Posts
    58

    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.
    Last edited by azfar; Dec 20th, 2008 at 05:05 AM.

  4. #4
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    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.

  5. #5

    Thread Starter
    Member
    Join Date
    Jun 2003
    Location
    Karachi
    Posts
    58

    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.

  6. #6
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    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.

  7. #7

    Thread Starter
    Member
    Join Date
    Jun 2003
    Location
    Karachi
    Posts
    58

    Re: Email finder.

    thanks, I am trying it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width