WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Samples from Users

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

CSMail Search Inside Mime Messages


Extolling the virtues of CSMail from http://www.codestone.co.uk

Using CSMail and the new easier OLE abilities of WB, here's a function that takes a message, rumages around inside it looking for a certain named attachment filename, and then saves that attachment to an external file. It deals with arbitrariliy complex mime nesting and with nested rfc822 messages. 29 lines of code. -

Kirby

#DefineFunction findfile( m, fnwild, of) ; recursive
        sn = m.sections.count
        For i = 1 To sn
          ; handle embedded rfc822 messages
          If m.sections(i).type=="message" && m.sections(i).subtype=="rfc822"
            tf = FileCreateTemp("eml")
            m.sections(i).writebodytofile(tf)
            fclient = ObjectOpen("csmail.FileClient")
              x = findfile(fclient.read(tf), fnwild, of)
            ObjectClose(fclient)            
            FileDelete(tf)
            If x Then Return x
          Else
            ; handle nested sections
            If m.sections(i).sections.count > 0  
              x = findfile(m.sections(i), fnwild, of)
              If x Then Return x
            Else
              ; get this sections filename
              f = m.sections(i).filename
              ;is this it?
              If StrIndexWild(StrLower(f),StrLower(fnwild),1) Then Break
            EndIf
          EndIf
        Next
        If i > sn Then Return 0
        m.sections(i).writebodytofile(of)
        Return 1
    #EndFunction

Article ID:   W16652
File Created: 2005:02:18:12:21:46
Last Updated: 2005:02:18:12:21:46