lsimoncini
Hello,

being a great believer of "PB as the center of the world" (TM) I would have liked to be able to import entire and untouched mail msgs in my brain

see http://thebrain.uservoice.com/pages/general/suggestions/73208

While I wait for this to become a standard feature I tried to develop a macro to get the same result

Disclaimer: I take no responsibility for whatever result you could get from using the code and information below including loss of personal and/or business data, unusable systems, breach of licence agreements or other bad events. All this information is provided "as is" with no guarantees on future improvements or even on present behavior of the given and derived code. All the content of this message/thread is to be intended as experimental. Constructive feedback on the other hand is greatly appreciated. In any case DO NOT try to use this information if you're not an experienced programmer.

OK, I had to state this upfront given the (awful but hopefully somehow effective) approach that I followed, I like sleeping well at night.

The basic idea is to simulate the clicks and keyboard typing necessary to actually import an outlook msg into PB, this can make wonders but also cause an horrendous mess if st goes wrong.

Essentially I save the message to a temporary directory and then import the folder in PB under the current thought

Requirements
-PB 5.x (some menu items can be opened by typing a letter in this version)
-AutoIt 3 (http://www.autoitscript.com/autoit3/index.shtml) free scripting/automation tool for Windows (guess similar tools exist for Mac/Unix)
-a temporary dir on you hard drive for staging your .msg files (in this case C:\PBMAILS)

Code below is pretty self explanatory I think.

CONS:
-notice the numerous sleep() commands, these are intended to avoid typing/clicking before either Outlook or PB are not ready to accept the intended input. The parameters in the code won't probably work on any system but mine, maybe not even on mine under different load conditions (eg more open programs)
-doesn't work for PB in auto hide (my favourite)
-maybe doesn't work with special characters in the msg subject (I didn't test too extensively)

PROS:
-Should be able to get a cleaner inbox, keep original, untouched messages in a single copy in PB
-Theoretically one could try and generate some additional links/tags immediately after importing the message (eg to a thought representing the sender)
-Autoit can generate an executable from the macro code, this can then be tied to a thought, pinned, invoked directly from PB
-Hopefully shows how important this feature could be, motivates TB R&D to include it natively in the future
-Same as above for automation and PB in general (essential if Tb wants to generate an ecosystem of 3rd party apps)
-Approach is not the best for high volumes, avoiding cannibalization of EKP business

OTHER NOTES:
-the original mail won't be automatically deleted from Outlook or from the staging dir

EDIT: code modified to
-diminish the number of sleep commands (waiting for correct window to open instead)
-import both mail messages and appointments/meetings
-code tries to create thought named with msg date + subject or start date + subject
-original mails/meetings/appointments still not deleted from Outlook

;
; AutoIT Macro (trying to) import an entire mail message as an .msg file attached
; to a PB Brain thought instead of just copying the msg body in the thought notes
;


Opt("WinTitleMatchMode", 2) ; this is to match windows without specifiyng the beginning of the window title (ie the brain name)
opt("SendKeyDelay", 1)

$startdate = ""
if WinActivate ("Microsoft Outlook") Then ; move Outlook inbox in the foreground if not already so
       
if WinActive("Calendar") Then
send("{ENTER}") ; open selected item
        ;WinWaitActive("[REGEXPTITLE: Appointment | Meeting]")
        send("{ALTDOWN}{SHIFTDOWN}:{ALTUP}{SHIFTUP}")
        sleep(10)
        WinWaitActive("[REGEXPTITLE: Appointment | Meeting]")
        send("^c") ; copy appointment start date
        sleep(200)
        $startdate = stringright(Clipget(), stringlen(Clipget()) - 4) & " "
                WinWaitActive("[REGEXPTITLE: Appointment | Meeting]")
        $startdate = inputbox("Specify Date", "Date", $startdate)
        if @Error = 1 Then
        Exit
EndIf
        ;msgbox(0, "Startdate", $startdate)
        $act = WinGetTitle("[active]")
        ;msgbox(0, "active title", $act)
        if StringInStr ($act, "Appointment") <> 0 then
                        WinClose("Appointment")
                ElseIf StringInStr ($act, "Meeting") <> 0 then
                        WinClose("Meeting")
        EndIf
        sleep(100)
ElseIf WinActive("Microsoft Outlook") Then
        send("{ENTER}") ; open selected item
sleep(10)
        send("{SHIFTDOWN}{TAB 4}{END}{SHIFTUP}")
        sleep(10)
        send("{CTRLDOWN}c{CTRLUP}{ESC}") ; copy message send date
        sleep(200)
        $startdate = stringleft(stringright(Clipget(), stringlen(Clipget()) - 4), 10) & " "
        ;msgbox(0, "Startdate", $startdate)
        sleep(100)
EndIf


send("!fa") ; save as (for currently selected message)
sleep(10)
send("{TAB}{DOWN}{HOME}o{DOWN}{ENTER}+{TAB}") ; choose Outlook 'msg' format
sleep(200)
send("^c") ; CTRL-C to copy message file name (<msg subject>.msg)
sleep(10)
; msgbox(0, "Filename", Clipget()) visually check that everything is OK

$myfile = StringStripWS(stringleft(Clipget(), stringlen(Clipget()) - 4), 3) ; take subject
$myfile = StringReplace($myfile, "^", " ") ; clean special char
;$startdate = inputbox("Specify Date", "Date", $startdate)
if @Error = 1 Then
        Exit
EndIf
$myfile = inputbox("Specify Item name", "Item name", $myfile)
if @Error = 1 Then
        Exit
EndIf
$mydir = "c:\PBMAILS\" & $startdate & $myfile ; temporary dir for msg file
;msgbox(0, "Filename", $mydir) visually check that everything is OK
DirRemove($mydir, 1) ; prune entire subdir in case same subject msg was saved before
if DirCreate($mydir) then ; recreate empty temp dir
;msgbox(0, "Filename", $mydir & "\" & $myfile) visually check that everything is OK
WinWaitActive("Save As")
       
send($mydir & "\" & $myfile, 1) ; specify location to "Save as" window
        WinWaitActive("Save As")
send("{ENTER}")
WinWaitActive("Microsoft Outlook")

if WinActivate ("PersonalBrain") Then

$size = WinGetPos("PersonalBrain") ; where's the window? NOTE that this WILL NOT work in auto-hide mode
MouseMove($size[0] + 200, $size[1] +200,5) ; Awful but seems necessary: move and click somewhere in the plex
MouseClick ("")
sleep(50)
        send("{ALTDOWN}") ; (ALT) File - Import - Folder
Send("f")
        sleep(5)
        send("{ALTUP}")
        sleep(80)
        send("i")
        sleep(50)
        send("f")
WinWaitActive("Select Folder to Import")
send($mydir,1) ; Type folder name to import from before        
        sleep(200)
send("{ENTER}") ; Trying to press all the OKs here (somehow it doesn't seem to work properly)
        sleep(10)
        send("{ENTER}")
WinWaitActive("Confirm")
send("{ENTER}")
WinWaitActive("Confirm Directory Import")
send("{ENTER}")
        WinWaitActive("PersonalBrain")

EndIf
EndIf
EndIf




Quote
homer007
hello lsimoncini,

I do agree that having PersonalBrain be the storage tool for everything is one of the reasons we are all using it.  I too have attempted to get all of my emails from outlook into personalbrain, but my approach was to use .NET and C# to communicate directly with Outlook. 

One of the main issues I found was that email messages saved as .msg format are not indexed, so instead I had outlook save the messages as .html.  I would generate these in a structure like: outlookemails \ email folder \ year \ month \ day \ email_subject_sender.html and save attachments inside a folder named attachments in the same area.  The end result is a folder structure that I could import into personal brain directly, in one command (though very long to complete).

I still haven't made the shift over to my main personalbrain file though, due to the need to have insta-search find emails much easier, and the question of how to update the archive as I go.  Maybe i'll start working on it again if I have time


Quote

Add a Website Forum to your website.

Newsletter Signup  Newsletter Signup        Visit TheBrain Blog   Visit TheBrain Blog       Follow us on Twitter   Follow Us       Like Us on Facebook   Like Us         Circle Us on Google+  Circle Us         Watch Us on Youtube  Watch Us       

TheBrain Mind Map & Mindmapping Software     Download TheBrain Mind Mapping Software