Saving files to a desktop from Thunderbird

Posted on 2009-04-27
Last Modified: 2012-05-06
Hello everyone, I am currently using Thunderbird email client..and get an automated emailed sent to me everyday with a file in it..I was wondering if there was any way to save it to my PC everyday without me doing anything?
Question by:dealstrike
    LVL 97

    Expert Comment

    Hello dealstrike,

    Thunderbird does not have a function or addin to auto save the file from email comming into itself.  You need to double click on the file to start the save process.  You can automate the save process by

    Thunderbird will auto save a particular type of attachment.  In Tbird, go to Tools > Options > Attachment. Select "Save all attachment to this folder. Type in folder.  Click OK.
    Double click on attachment.  Check to auto save this type of file..

    Hope this helps!

    Author Comment

    I there a way to do this via vb or vb script or something? Is it possible to automate saving of the email the file is in?
    LVL 97

    Expert Comment

    I do not know of a vb script to use.
    LVL 2

    Accepted Solution


    I have a quite different solution with a VBscript which works quite well.
    Thunderbird naturally stores it's mail data in standard MBOX format, which can be handled as a simple text file.

    1. Create a Mail folder inside Thunderbird where it will store the daily mails which attachments need to be extracted, call it for example Logfiles.

    2. Create a Mail filter in Thunderbird which makes a copy of the desired mails to the newly created folder (you can filter by subject or what you like).

    This way you have a separate folder which only contains the mails from which you want to extract the attachments.

    3. Save this VBScript, and set up the first two constants to fit your system (the path to the newly created folder file, and the path for the wanted output directory)

    4. Make a Scheduled job which daily calls it (for example 10-20-30 minutes after the mail arrives).



    P.s. I've left the information about the author of the Base64 Decoder Function inside the code, just to be correct.

    Option Explicit
    Const MBOXFileLocation="C:\vbs\tstfolder\test_folder" ' Location of the file which contains the desired mails, for example "C:\Documents and Settings\User\Application Data\Thunderbird\Profiles\ib4qdqna.default\Mail\Local Folders\Logfiles" 
    Const OutputFolder="C:\vbs\tstfolder\output" ' Path to the output directory, for example C:\Documents and Settings\User\Desktop\Daily Logfiles
    Dim objFSO,objFile,objReadFile
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFile = objFSO.GetFile(MBOXFileLocation)
    Dim CurrentLine,CurrentFile,CurrentFileDataEncoded,CurrentFileDataDecoded
    Dim Status  ' 0 - Nothing,  1 - Start of attachment found, searching for end,  2 - End marker found, processing BASE64 decode.
    If objFile.Size > 0 Then
        Set objReadFile = objFSO.OpenTextFile(MBOXFileLocation, 1)
        Do Until objReadFile.AtEndOfStream
    		If Status=1 Then
    			' Add current line to CurrentLineData
    			CurrentFileDataEncoded=CurrentFileDataEncoded & CurrentLine
    		End If
    		If InStr(1,CurrentLine,"Content-disposition: attachment;") > 0 Then 
    			' Start of attachment found
    		End If
    		If (Status=1) and (CurrentLine="") and (CurrentFileDataEncoded<>"") and (InStr(1,CurrentLine,"Content-disposition: attachment;") = 0)Then
    			' End of attachment found after a start
    			WriteDecodedToFile OutputFolder & "\" & CurrentFile,CurrentFileDataDecoded
    		End If
        'Nothing to do
    End If
    Sub WriteDecodedToFile(Target,SourceString)
    	Dim objFSO, objWriteFile, nIndex
    	Set objFSO = CreateObject("Scripting.FileSystemObject")
        Set objWriteFile = objFSO.OpenTextFile(Target, 2, True)
    	For nIndex = 1 to Len(SourceString)
    		objWriteFile.write Chr(Asc(Mid(SourceString,nIndex,1)))
    End Sub
    ' Decodes a base-64 encoded string (BSTR type).
    ' 1999 - 2004 Antonin Foller,
    ' 1.01 - solves problem with Access And 'Compare Database' (InStr)
    Function Base64Decode(base64String)
      '1999 Antonin Foller, Motobit Software,
      Const Base64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
      Dim dataLength, sOut, groupBegin
      'remove white spaces, If any
      base64String = Replace(base64String, vbCrLf, "")
      base64String = Replace(base64String, vbTab, "")
      base64String = Replace(base64String, " ", "")
      'The source must consists from groups with Len of 4 chars
      dataLength = Len(base64String)
      If dataLength Mod 4 <> 0 Then
        Err.Raise 1, "Base64Decode", "Bad Base64 string."
        Exit Function
      End If
      ' Now decode each group:
      For groupBegin = 1 To dataLength Step 4
        Dim numDataBytes, CharCounter, thisChar, thisData, nGroup, pOut
        ' Each data group encodes up To 3 actual bytes.
        numDataBytes = 3
        nGroup = 0
        For CharCounter = 0 To 3
          ' Convert each character into 6 bits of data, And add it To
          ' an integer For temporary storage.  If a character is a '=', there
          ' is one fewer data byte.  (There can only be a maximum of 2 '=' In
          ' the whole string.)
          thisChar = Mid(base64String, groupBegin + CharCounter, 1)
          If thisChar = "=" Then
            numDataBytes = numDataBytes - 1
            thisData = 0
            thisData = InStr(1, Base64, thisChar, vbBinaryCompare) - 1
          End If
          If thisData = -1 Then
            Err.Raise 2, "Base64Decode", "Bad character In Base64 string. Char: " & thisChar
            Exit Function
          End If
          nGroup = 64 * nGroup + thisData
        'Hex splits the long To 6 groups with 4 bits
        nGroup = Hex(nGroup)
        'Add leading zeros
        nGroup = String(6 - Len(nGroup), "0") & nGroup
        'Convert the 3 byte hex integer (6 chars) To 3 characters
        pOut = Chr(CByte("&H" & Mid(nGroup, 1, 2))) + _
          Chr(CByte("&H" & Mid(nGroup, 3, 2))) + _
          Chr(CByte("&H" & Mid(nGroup, 5, 2)))
        'add numDataBytes characters To out string
        sOut = sOut & Left(pOut, numDataBytes)
      Base64Decode = sOut
    End Function

    Open in new window


    Author Comment

    SWEET deal! Thanks, I will try this out in the next few days and let you know
    Much obliged...I LOVE how vb has a solution to almost everything

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
    Email signatures have numerous marketing benefits. Here are 8 top reasons to turn your email signature into a marketing channel.
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now