Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Version 10.0

New Features
------------
- Editing HTML formated Outlook emails is now supported.  A new option has been added, g:outlook_supported_body_format, can have one of two values: plain or html.

NOTE: Outlook html contains a lot of markup tags.  It can make it difficult to find the body text within all the tags.

- A new option has been added, g:outlook_file_type, which defaults to 'mail'.  When opening the buffer within Vim, this file type is set for the buffer.   You may want to change this value if you are editig HTM emails.

- A new command has been added: OutlookNewEmail.  This will take the contents of the existing buffer and create a new Outlook email.  If the filetype is 'html' and g:outlook_supported_body_format = 'html', the email body will be html rather than plain text.  The command can be run as often as necessary, a new Outlook email will be created each time.

Bug Fixes
---------
- The additional changes to the VB code to support both 32-bit and 64-bit platforms does not work with Outlook 2007 32-bit (at least).  The new changes will work for either (Greg Dunn).
  • Loading branch information...
commit 6902837d65a2ad151ba57b548560656aa772abb5 1 parent d68c702
@dfishburn dfishburn authored committed
View
55 doc/outlook.txt
@@ -1,4 +1,4 @@
-outlook.txt* For Vim version 7.0. Last change: 2013 May 13
+outlook.txt* For Vim version 7.0. Last change: 2013 May 29
VIM REFERENCE MANUAL
@@ -6,7 +6,7 @@ outlook.txt* For Vim version 7.0. Last change: 2013 May 13
David Fishburn <dfishburn dot vim at gmail dot com>
Outlook Vim Plugin
- outlook.vim version 9.0
+ outlook.vim version 10.0
For instructions on installing this file, type
:help add-local-help
@@ -19,8 +19,8 @@ Homepage: http://www.vim.org/scripts/script.php?script_id=3087
1. Overview .................................... |outlook-overview|
2. Whats New ................................... |outlook-new|
-3. Installing the plugin ....................... |outlook-install|
-4. Installing the Outlook macro ................ |outlook-macro|
+3. Installing the Plugin ....................... |outlook-install|
+4. Installing the Outlook Macro ................ |outlook-macro|
5. Configuration ............................... |outlook-configuration|
6. Troubleshooting ............................. |outlook-troubleshooting|
@@ -35,10 +35,10 @@ Outlook
-------
Outlook includes a feature which allows macros to be created in Visual Basic.
Once the macro is imported / created, you can create buttons and place them
-on Outlooks email toolbars. The macro (when executed) does two
-things:
- 1. Writes the email body out to a file ending in .outlook
+on Outlook's toolbars. The macro (when executed) does several things:
+ 1. Writes the email body to a file ending in .outlook
2. Writes out a control file ending in .outlook.ctl
+ 3. Asks Vim to edit the .outlook file
Vim
---
@@ -46,6 +46,7 @@ The outlook.vim plugin is responsible for setting up some autocmds inside
of Vim. There are a number of configuration options which allows you to tweak
the behaviour of the plugin. The autocmds also set the Vim filetype to "mail"
which allows you to customize even further using the usual Vim filetype plugins.
+Setting of the filetype is also an option, you can choose any filetype you wish.
These autocmds are responsible for updating Outlook when the buffer (email) is
updated. Communication with Outlook is via the Windows Script Host (WSH
@@ -76,6 +77,31 @@ David Fishburn
==============================================================================
2. What's New *outlook-new*
+Version 10.0 (May 31, 2013)
+
+ New Features
+ ------------
+ - Editing HTML formated Outlook emails is now supported. A new option
+ has been added, g:outlook_supported_body_format, can have one of two
+ values: plain or html.
+ NOTE: Outlook html contains a lot of markup tags. It can make it difficult
+ to find the body text within all the tags.
+ - A new option has been added, g:outlook_file_type, which defaults to 'mail'.
+ When opening the buffer within Vim, this file type is set for the buffer.
+ You may want to change this value if you are editig HTM emails.
+ - A new command has been added: OutlookNewEmail. This will take the contents
+ of the existing buffer and create a new Outlook email. If the filetype
+ is 'html' and g:outlook_supported_body_format = 'html', the email body
+ will be html rather than plain text. The command can be run as often as
+ necessary, a new Outlook email will be created each time.
+
+ Bug Fixes
+ ---------
+ - The additional changes to the VB code to support both 32-bit and
+ 64-bit platforms does not work with Outlook 2007 32-bit (at least).
+ The new changes will work for either (Greg Dunn).
+
+
Version 9.0 (May 12, 2013)
New Features
@@ -180,7 +206,7 @@ Version 1.0 (May 7, 2010)
==============================================================================
-3. Installing the plugin *outlook-install*
+3. Installing the Plugin *outlook-install*
You can use this script as a plugin by copying it to your plugin directory.
See |add-global-plugin| for instructions.
@@ -211,7 +237,7 @@ Version 1.0 (May 7, 2010)
<
==============================================================================
-4. Installing the Outlook macro *outlook-macro*
+4. Installing the Outlook Macro *outlook-macro*
The macro is used to add a button in Outlook to lauch Vim. It is used to
create the files which Vim will edit. It will also add a shortcut key
@@ -240,7 +266,7 @@ Version 1.0 (May 7, 2010)
- For Outlook 2010, I had to restart Outlook with Admin rights
by holding down CTRL-SHIFT when I clicked on the Outlook icon.
3. From the menu File->Import File (or Ctrl-M)
- 4. Choose the file ...\vimfiles\plugin\OutlookVim.bas (where ever you
+ 4. Choose the file ...\vimfiles\plugin\OutlookVim.bas (depending on where you
installed the plugin).
5. Expand the Modules folder in the Project pane
- Right click on Module1 and choose Project Properties (if available)
@@ -410,6 +436,15 @@ Version 1.0 (May 7, 2010)
in Outlook to help identify issues. >
let g:outlook_debug = 1
<
+ This setting (default = plain) indicates which format of the Outlook message
+ to use when creating the buffer for Vim to edit. If the value is set to
+ "html", then if the Outlook email is using an "html" body, then the buffer
+ will contain html code. If the email is in rich text or plain text, then
+ the buffer will be in plain text. So you will only edit in html, if the
+ body of the Outlook message is already in html. To set this preference
+ add the following to your .vimrc: >
+ let g:outlook_supported_body_format = 'html'
+<
This setting (default = 0) can force all Outlook messages to be written
using the utf-16le encoding. See :h outlook-unicode. >
let g:outlook_always_use_unicode = 1
View
72 plugin/OutlookVim.bas
@@ -1,8 +1,8 @@
' OutlookVim.bas - Edit emails using Vim from Outlook
' ---------------------------------------------------------------
-' Version: 9.0
+' Version: 10.0
' Authors: David Fishburn <dfishburn dot vim at gmail dot com>
-' Last Modified: 2013 May 10
+' Last Modified: 2013 May 21
' Homepage: http://www.vim.org/scripts/script.php?script_id=3087
'
' This VBScript should be installed as a macro inside of Microsoft Outlook.
@@ -74,9 +74,15 @@ Private Type PROCESS_INFORMATION
dwThreadID As Long
End Type
+#If VBA7 Then
Private Declare PtrSafe Function WaitForSingleObject Lib "kernel32" (ByVal _
hHandle As Long, ByVal dwMilliseconds As Long) As Long
+#Else
+Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal _
+ hHandle As Long, ByVal dwMilliseconds As Long) As Long
+#End If
+#If VBA7 Then
Private Declare PtrSafe Function CreateProcessA Lib "kernel32" (ByVal _
lpApplicationName As Long, ByVal lpCommandLine As String, ByVal _
lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _
@@ -84,9 +90,23 @@ Private Declare PtrSafe Function CreateProcessA Lib "kernel32" (ByVal _
ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, _
lpStartupInfo As STARTUPINFO, lpProcessInformation As _
PROCESS_INFORMATION) As Long
+#Else
+Private Declare Function CreateProcessA Lib "kernel32" (ByVal _
+ lpApplicationName As Long, ByVal lpCommandLine As String, ByVal _
+ lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _
+ ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
+ ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, _
+ lpStartupInfo As STARTUPINFO, lpProcessInformation As _
+ PROCESS_INFORMATION) As Long
+#End If
+#If VBA7 Then
Private Declare PtrSafe Function CloseHandle Lib "kernel32" (ByVal _
hObject As Long) As Long
+#Else
+Private Declare Function CloseHandle Lib "kernel32" (ByVal _
+ hObject As Long) As Long
+#End If
Private Const NORMAL_PRIORITY_CLASS = &H20&
Private Const INFINITE = -1&
@@ -140,21 +160,24 @@ Sub Edit()
Dim ol, insp, item, fso, tempfile, tfolder, tname, tfile, cfile, entryID, appRef, x, index
- Dim body As String, bodyFormat As String
+ Dim body As String, bodyFormat As String, msg As String
Dim outlookVBVersion As String, outlookVimVersion As String
Dim startAt, allOccurrences
Dim Vim, vimKeys, vimResponse, vimServerName, vimEncoding, vimOLEInstance
Dim overwrite As Boolean, debugMode As Boolean
Dim isUnicodeWanted As Boolean, useUnicodeFileFormat As Boolean, isUnicodeAllowed As Boolean, isUnicodeScanWanted As Boolean
+ Dim isHTMLAllowed As Boolean, useHTML As Boolean
isUnicodeWanted = False
isUnicodeAllowed = False
isUnicodeScanWanted = False
useUnicodeFileFormat = False
+ isHTMLAllowed = False
+ useHTML = False
debugMode = False
startAt = 1
allOccurrences = -1
- outlookVBVersion = "9"
+ outlookVBVersion = "10"
' MsgBox ("Just starting LaunchVim")
Set ol = Application
@@ -275,11 +298,16 @@ Sub Edit()
vimResponse = Vim.Eval("(exists('g:outlook_body_format')?(g:outlook_body_format):'')")
If vimResponse <> "" Then
- bodyFormat = vimResponse
- Call ShowMsg("OutlookVim: Using body format[" & _
- bodyFormat & _
- "]" _
- , debugMode)
+ msg = "OutlookVim: Allowing body formats[plain"
+ Select Case vimResponse
+ Case "html", "HTML"
+ isHTMLAllowed = True
+ msg = msg & ",html"
+ Case Else
+ isHTMLAllowed = False
+ End Select
+ msg = msg & "]"
+ Call ShowMsg(msg, debugMode)
End If
vimResponse = Vim.Eval("match(&fileencodings, '\<ucs-bom\|utf\>')")
@@ -340,15 +368,23 @@ Sub Edit()
' MsgBox ("Temp folder:" & tfolder.ShortPath)
' MsgBox ("InternetCodePage:" & item.InternetCodepage)
- ' Always default to plain text
- Select Case bodyFormat
- Case "rtf", "RTF"
- body = StrConv(item.RTFBody, vbUnicode)
- Case "html", "HTML"
+ ' Only edit the email in HTML if it is already in HTML
+ ' otherwise, simply use the plain format.
+ bodyFormat = "plain"
+ ' Case "rtf", "RTF"
+ ' ' http://www.cryptosys.net/pki/manpki/pki_stringstobytes.html
+ ' body = StrConv(item.RTFBody, vbUnicode)
+ If item.bodyFormat = olFormatHTML Then
+ If isHTMLAllowed Then
body = item.HTMLBody
- Case Else
+ bodyFormat = "html"
+ Else
body = item.body
- End Select
+ End If
+ Else
+ body = item.body
+ End If
+
If useUnicodeFileFormat <> True Then
If isUnicodeScanWanted Then
@@ -466,7 +502,7 @@ Sub Edit()
End If
vimKeys = vimKeys & vimEncoding
End If
- vimKeys = vimKeys & "' )<Enter>"
+ vimKeys = vimKeys & "', '" & bodyFormat & "' )<Enter>"
Call ShowMsg("OutlookVim: vimKeys:" & vimKeys, debugMode)
' Use Vim's OLE feature to edit the email
@@ -501,5 +537,3 @@ Public Sub ExecCmd(cmdline$)
ReturnValue = CloseHandle(proc.hProcess)
End Sub
-
-
View
158 plugin/outlook.vim
@@ -1,8 +1,8 @@
" outlook.vim - Edit emails using Vim from Outlook
" ---------------------------------------------------------------
-" Version: 9.0
+" Version: 10.0
" Authors: David Fishburn <dfishburn dot vim at gmail dot com>
-" Last Modified: 2013 May 10
+" Last Modified: 2013 May 28
" Created: 2009 Jan 17
" Homepage: http://www.vim.org/scripts/script.php?script_id=3087
" Help: :h outlook.txt
@@ -80,48 +80,43 @@ if !exists('g:outlook_scan_email_body_unicode')
let g:outlook_scan_email_body_unicode = 1
endif
-if !exists('g:outlook_body_format')
- let g:outlook_body_format = ''
+if !exists('g:outlook_supported_body_format')
+ let g:outlook_supported_body_format = 'plain'
+endif
+
+if !exists('g:outlook_file_type')
+ let g:outlook_file_type = 'mail'
endif
" globpath uses wildignore and suffixes options unless a flag is provided
" to ignore those settings.
let s:ignore_wildignore_setting = 1
-function! Outlook_WarningMsg(msg)
+function! s:Outlook_WarningMsg(msg)
echohl WarningMsg
echomsg "outlook: ".a:msg
echohl None
endfunction
-function! Outlook_ErrorMsg(msg)
+function! s:Outlook_ErrorMsg(msg)
echohl ErrorMsg
echomsg "outlook: ".a:msg
echohl None
endfunction
-function! Outlook_ExecuteJS(filename)
- let cmd = "let result = system('cscript \""
- let cmd = cmd . expand(g:outlook_javascript)
- let cmd = cmd . '" "'.a:filename.'"'
- let cmd = cmd . " ')"
- exec cmd
-
- echomsg result
-endfunction
-
-function! Outlook_EditFile(filename, encoding)
+" Publicly available function
+function! Outlook_EditFile(filename, encoding, bodyFormat)
if g:outlook_servername == '' || g:outlook_servername == v:servername
let remove_bufnr = -1
if !filereadable(a:filename)
- call Outlook_ErrorMsg( 'Cannot find filename['.a:filename.']')
+ call s:Outlook_ErrorMsg( 'Cannot find filename['.a:filename.']')
return
endif
if bufname('%') == '' && winnr('$') == 1 && &modified != 1
let remove_bufnr = bufnr('%')
if g:outlook_debug == 1
- call Outlook_WarningMsg( 'Outlook_EditFile will remove buffer['.remove_bufnr.'] b['.bufname('%').'] w['.winnr('$').'] m['.&modified.']' )
+ call s:Outlook_WarningMsg( 'Outlook_EditFile will remove buffer['.remove_bufnr.'] b['.bufname('%').'] w['.winnr('$').'] m['.&modified.']' )
endif
let cmd = ':'.
\ 'new'.
@@ -138,13 +133,17 @@ function! Outlook_EditFile(filename, encoding)
let g:outlook_last_cmd = cmd
exec cmd
+ let b:outlook_body_format = a:bodyFormat
+ let b:outlook_action = 'update'
+
if g:outlook_debug == 1
- call Outlook_WarningMsg( 'Outlook_EditFile executing['.cmd.']' )
+ call s:Outlook_WarningMsg( 'Outlook_EditFile file['.a:filename.'] bufnr['.bufnr('%').'] bodyFormat['.b:outlook_body_format.']' )
endif
+
if remove_bufnr != -1
exec remove_bufnr.'bw'
if g:outlook_debug == 1
- call Outlook_WarningMsg( 'Outlook_EditFile removing buffer['.remove_bufnr.']' )
+ call s:Outlook_WarningMsg( 'Outlook_EditFile removing buffer['.remove_bufnr.']' )
endif
endif
else
@@ -152,64 +151,76 @@ function! Outlook_EditFile(filename, encoding)
call remote_send( g:outlook_servername, ":call Outlook_EditFile( '".a:filename."', '".a:encoding."' )\<CR>" )
" call remote_send( g:outlook_servername, cmd )
else
- call Outlook_ErrorMsg( 'Please start a new Vim instance using "gvim --servername '.g:outlook_servername.'"')
+ call s:Outlook_ErrorMsg( 'Please start a new Vim instance using "gvim --servername '.g:outlook_servername.'"')
endif
endif
endfunction
-function! Outlook_BufWritePost()
+function! s:Outlook_BufWritePost()
" autoread, prevents this message:
" "File has changed, do you want to Load"
if !exists('g:outlook_noautoread')
- setlocal autoread
+ setlocal autoread
endif
- let filename = expand("<afile>:p")
- if filename == ''
- let filename = expand("%:p")
- call Outlook_WarningMsg( 'Filename was blank, using:'.filename )
+ let l:filename = expand("<afile>:p")
+ if l:filename == ''
+ let l:filename = expand("%:p")
+ call s:Outlook_WarningMsg( 'Filename was blank, using:'.l:filename )
+ endif
+
+ let l:bufnr = expand("<abuf>")
+ let l:bodyFormat = (exists('b:outlook_body_format')?(b:outlook_body_format):'plain')
+
+ if g:outlook_debug == 1
+ call s:Outlook_WarningMsg( 'Outlook_BufWritePost file['.l:filename.'] bufnr['.l:bufnr.'] bodyFormat['.b:outlook_body_format.']' )
endif
let cmd = 'cscript "'. expand(g:outlook_javascript).
\ '" "'.
- \ filename.
+ \ l:filename.
\ '" '.
- \ g:outlook_nobdelete
+ \ g:outlook_nobdelete.
+ \ ' "'.
+ \ l:bodyFormat.
+ \ '" '
if g:outlook_debug == 1
- call Outlook_WarningMsg( 'Outlook_BufWritePost executing['.cmd.']' )
+ call s:Outlook_WarningMsg( 'Outlook_BufWritePost executing['.cmd.'] bufnr['.l:bufnr.']' )
endif
try
let g:outlook_cscript_output = system(cmd)
+ if g:outlook_debug == 1
+ call s:Outlook_WarningMsg( 'Outlook_NewEmail results['.g:outlook_cscript_output.']' )
+ endif
catch /.*/
- call Outlook_WarningMsg( 'Outlook_BufWritePost: Error calling cscript to update Outlook:'.v:exception )
- if g:outlook_save_cscript_output == 1 && g:outlook_view_cscript_error
- call Outlook_WarningMsg( v:exception )
+ call s:Outlook_WarningMsg( 'Outlook_BufWritePost: Error calling cscript to update Outlook bufnr['.l:bufnr.'] E['.v:exception.']' )
+ if (g:outlook_save_cscript_output == 1 && g:outlook_view_cscript_error) || g:outlook_debug
+ call s:Outlook_WarningMsg( v:exception )
endif
finally
endtry
- if g:outlook_save_cscript_output == 1 && g:outlook_view_cscript_error
+ if (g:outlook_save_cscript_output == 1 && g:outlook_view_cscript_error) || g:outlook_debug
if g:outlook_cscript_output =~ '\c\(OutlookVim\[\d\+\]:\s*\(Successfully\)\@<=\|runtime error\)'
- call Outlook_WarningMsg( substitute(g:outlook_cscript_output, '\c^.*\(OutlookVim\[.*\)', '\1', '') )
+ call s:Outlook_WarningMsg( substitute(g:outlook_cscript_output, '\c^.*\(OutlookVim\[.*\)', '\1', '') )
elseif g:outlook_nobdelete == 0
if g:outlook_debug == 1
- call Outlook_WarningMsg( 'Outlook_BufWritePost deleting buffer when viewing cscript error' )
+ call s:Outlook_WarningMsg( 'Outlook_BufWritePost deleting buffer['.l:bufnr.'] when viewing cscript error' )
endif
bdelete
endif
else
if g:outlook_nobdelete == 0
if g:outlook_debug == 1
- call Outlook_WarningMsg( 'Outlook_BufWritePost deleting buffer' )
+ call s:Outlook_WarningMsg( 'Outlook_BufWritePost deleting buffer['.l:bufnr.']' )
endif
bdelete
endif
endif
-
endfunction
-function! Outlook_BufUnload()
+function! s:Outlook_BufUnload()
" This is necessary in case the buffer is not saved (:w), since
" the temporary files are (by default) deleted by outlookvim.js.
" But the javascript is only called if you save the buffer, if
@@ -218,7 +229,7 @@ function! Outlook_BufUnload()
if !exists('g:outlook_nodelete_unload') || g:outlook_nodelete_unload != 1
if expand('<afile>:e') == 'outlook'
if g:outlook_debug == 1
- call Outlook_WarningMsg( 'Outlook_BufUnload deleting['.expand('<afile>:p').']' )
+ call s:Outlook_WarningMsg( 'Outlook_BufUnload deleting['.expand('<afile>:p').'] bufnr['.expand("<abuf>").']' )
endif
call delete(expand('<afile>:p').'.ctl')
call delete(expand('<afile>:p'))
@@ -226,6 +237,54 @@ function! Outlook_BufUnload()
endif
endfunction
+function! s:Outlook_NewEmail()
+ if bufname('%') == ''
+ call s:Outlook_WarningMsg( 'OutlookVim: You must save the file first' )
+ return
+ endif
+
+ if !exists('b:outlook_body_format')
+ let b:outlook_body_format = 'plain'
+ if exists('g:outlook_supported_body_format')
+ if g:outlook_supported_body_format =~? 'html'
+ if &filetype == 'html'
+ let b:outlook_body_format = 'html'
+ endif
+ endif
+ endif
+ endif
+ let b:outlook_action = 'new'
+ " Do not delete this buffer after updating Outlook
+ let b:outlook_nobdelete = 1
+
+ let cmd = 'cscript "'. expand(g:outlook_javascript).
+ \ '" "'.
+ \ expand('%:p').
+ \ '" '.
+ \ b:outlook_nobdelete.
+ \ ' "'.
+ \ b:outlook_body_format.
+ \ '" '
+ if g:outlook_debug == 1
+ call s:Outlook_WarningMsg( 'Outlook_NewEmail executing['.cmd.'] bufnr['.bufnr('%').']' )
+ endif
+
+ try
+ let g:outlook_cscript_output = system(cmd)
+ if g:outlook_debug == 1
+ call s:Outlook_WarningMsg( 'Outlook_NewEmail results['.g:outlook_cscript_output.']' )
+ endif
+ catch /.*/
+ call s:Outlook_WarningMsg( 'Outlook_NewEmail: Error calling cscript to update Outlook bufnr['.bufnr('%').'] E['.v:exception.']' )
+ if (g:outlook_save_cscript_output == 1 && g:outlook_view_cscript_error) || g:outlook_debug
+ call s:Outlook_WarningMsg( v:exception )
+ endif
+ finally
+ endtry
+endfunction
+
+command! OutlookNewEmail call s:Outlook_NewEmail()
+
" Check is cscript.exe is already in the PATH
" Some path entries may end in a \ (c:\util\;), this must also be replaced
" or globpath fails to parse the directories
@@ -234,20 +293,21 @@ if v:version > 703 || v:version == 702 && has('patch051')
else
let cscript_location = globpath(substitute($PATH, '\\\?;', ',', 'g'), 'cscript.exe')
endif
+
if strlen(cscript_location) == 0
- call Outlook_ErrorMsg("Cannot find cscript.exe in system path")
+ call s:Outlook_ErrorMsg("Cannot find cscript.exe in system path")
finish
endif
if exists('g:outlook_javascript')
if !filereadable(expand(g:outlook_javascript))
- call Outlook_ErrorMsg("Cannot find javascript file[" .
+ call s:Outlook_ErrorMsg("Cannot find javascript file[" .
\ expand(g:outlook_javascript) .
\ ']' )
finish
endif
else
- call Outlook_ErrorMsg("Cannot find the variable: g:outlook_javascript ")
+ call s:Outlook_ErrorMsg("Cannot find the variable: g:outlook_javascript ")
finish
endif
@@ -264,20 +324,20 @@ if has('autocmd') && !exists("g:loaded_outlook")
" Each time we enter this buffer, set the filetype to mail
" which allows us to rely on each personal users mail preferences
- autocmd BufEnter *.outlook setlocal filetype=mail
+ exec 'autocmd BufEnter *.outlook setlocal filetype='.g:outlook_file_type
" nested is required since we are issuing a bdelete, inside an autocmd
" so we also need the required autocmd to fire for that command.
" setlocal autoread, prevents this message:
" "File has changed, do you want to Load"
- autocmd BufWritePost *.outlook nested call Outlook_BufWritePost()
+ autocmd BufWritePost *.outlook nested call s:Outlook_BufWritePost()
- autocmd BufUnload *.outlook call Outlook_BufUnload()
+ autocmd BufUnload *.outlook call s:Outlook_BufUnload()
augroup END
" Don't re-run the script if already sourced
- let g:loaded_outlook = 9
+ let g:loaded_outlook = 10
let @"=saveB
endif
@@ -287,7 +347,7 @@ endif
if g:outlook_always_use_unicode == 1
if match(&fileencodings, '\<ucs-bom\|utf\>') == -1
let g:outlook_always_use_unicode = 0
- call Outlook_WarningMsg( 'OutlookVim: Cannot force Outlook to use unicode as Vim is not setup for unicode. '.
+ call s:Outlook_WarningMsg( 'OutlookVim: Cannot force Outlook to use unicode as Vim is not setup for unicode. '.
\ 'See :h outlook-unicode' )
endif
endif
View
170 plugin/outlookvim.js
@@ -1,8 +1,8 @@
// outlookvim.js
//
// Author: David Fishburn
-// Version: 9.0
-// Last Modified: 2013 Apr 08
+// Version: 10.0
+// Last Modified: 2013 May 28
// Homepage: http://www.vim.org/scripts/script.php?script_id=3087
//
// Purpose:
@@ -24,10 +24,16 @@
// JScript Language Reference
// http://msdn2.microsoft.com/en-us/library/yek4tbz0.aspx
//
+// JavaScript API for Office
+// http://msdn.microsoft.com/en-us/library/fp160953.aspx
+//
+// Example
+// http://stackoverflow.com/questions/12247696/open-outlook-with-javascript-for-sending-mail-with-attachment-in-c-sharp
+
var objArgs = WScript.Arguments;
-var version = 9;
+var version = 10;
-function updateOutlook( emailfile, persistfiles )
+function updateOutlook( emailfile, persistfiles, bodyformat )
{
var ctlfile = emailfile + ".ctl";
var outlook = null;
@@ -37,11 +43,12 @@ function updateOutlook( emailfile, persistfiles )
var objNS = null;
var objInbox = null;
var entryID = null;
- var newmsg = null;
+ var msg = null;
var inspector = null;
var readOnly = 1;
var createNo = false;
var mixedMode = -2;
+ var updateMsg = true;
WScript.Echo("OutlookVim[" + version + "]: updateOutlook persist files:" + persistfiles);
try
@@ -55,6 +62,15 @@ function updateOutlook( emailfile, persistfiles )
}
try
{
+ objNS = outlook.GetNamespace("MAPI");
+ }
+ catch(err)
+ {
+ WScript.Echo("OutlookVim[" + version + "]: Unable to get outlook namespace["+err.message+"]");
+ return;
+ }
+ try
+ {
fs = new ActiveXObject("Scripting.FileSystemObject");
}
catch(err)
@@ -77,29 +93,11 @@ function updateOutlook( emailfile, persistfiles )
// -1 = TristateTrue: Open the file as Unicode
// -2 = TristateMixed: Mixed mode
// -2 = TristateUseDefault: Open the file as System Default type.
- f = fs.OpenTextFile(emailfile, readOnly, createNo, mixedMode);
+ f = fs.OpenTextFile(emailfile, readOnly, createNo, mixedMode);
}
catch(err)
{
- WScript.Echo("OutlookVim[" + version + "]: Unable to open file:"+emailfile+" err:"+err.message);
- return;
- }
- try
- {
- fid = fs.OpenTextFile(ctlfile);
- }
- catch(err)
- {
- WScript.Echo("OutlookVim[" + version + "]: Unable to open control file:"+ctlfile+" err:"+err.message);
- return;
- }
- try
- {
- objNS = outlook.GetNamespace("MAPI");
- }
- catch(err)
- {
- WScript.Echo("OutlookVim[" + version + "]: Unable to get outlook namespace:"+err.message);
+ WScript.Echo("OutlookVim[" + version + "]: Unable to open file["+emailfile+"] Err["+err.message+"]");
return;
}
try
@@ -108,80 +106,118 @@ function updateOutlook( emailfile, persistfiles )
}
catch(err)
{
- WScript.Echo("OutlookVim[" + version + "]: Unable to get Inbox:"+err.message);
+ WScript.Echo("OutlookVim[" + version + "]: Unable to get Inbox["+err.message+"]");
return;
}
try
{
- entryID = fid.ReadLine();
+ fid = fs.OpenTextFile(ctlfile);
}
catch(err)
{
- WScript.Echo("OutlookVim[" + version + "]: Failed to read control file["+ctlfile+"]:"+err.message);
- return;
+ updateMsg = false;
+ WScript.Echo("OutlookVim[" + version + "]: Unable to open control file["+ctlfile+"] assuming new email Err["+err.message+"]");
+ //return;
}
- try
+ if( updateMsg )
{
- newmsg = objNS.GetItemFromID(entryID);
+ try
+ {
+ entryID = fid.ReadLine();
+ }
+ catch(err)
+ {
+ WScript.Echo("OutlookVim[" + version + "]: Failed to read control file["+ctlfile+"] Err["+err.message+"]");
+ return;
+ }
+ try
+ {
+ msg = objNS.GetItemFromID(entryID);
+ }
+ catch(err)
+ {
+ WScript.Echo("OutlookVim[" + version + "]: GetItemFromID failed["+err.message+"]");
+ return;
+ }
}
- catch(err)
+ else
{
- WScript.Echo("OutlookVim[" + version + "]: GetItemFromID failed:"+err.message);
- return;
+ // value 0 = MailItem
+ msg = outlook.CreateItem(0);
}
+
try
{
- newmsg.Body = f.ReadAll();
+ switch( bodyformat )
+ {
+ case "html":
+ case "HTML":
+ msg.HTMLBody = f.ReadAll();
+ break;
+ //case "rtf":
+ //case "RTF":
+ // msg.RTFBody = f.ReadAll();
+ // break;
+ default:
+ msg.Body = f.ReadAll();
+ break;
+ }
}
catch(err)
{
- WScript.Echo("OutlookVim[" + version + "]: Failed to read email file["+emailfile+"]:"+err.message);
- return;
+ WScript.Echo("OutlookVim[" + version + "]: Failed to read email file["+emailfile+"] Err["+err.message+"]");
+ return;
}
- fid.Close();
- f.Close();
+ if( updateMsg )
+ {
+ fid.Close();
+ f.Close();
+ }
try
{
- inspector = newmsg.GetInspector;
+ inspector = msg.GetInspector;
inspector.Activate();
}
catch(err)
{
- WScript.Echo("OutlookVim[" + version + "]: Failed to get Inspector:"+err.message);
+ WScript.Echo("OutlookVim[" + version + "]: Failed to get Inspector["+err.message+"]");
return;
}
- if( 1 == persistfiles )
- {
- WScript.Echo("OutlookVim[" + version + "]: Keeping files");
- }
- else
+ if( updateMsg )
{
- WScript.Echo("OutlookVim[" + version + "]: Deleting files:" + persistfiles);
- try
+ if( 1 == persistfiles )
{
- f = fs.GetFile(emailfile);
- f.Delete();
+ WScript.Echo("OutlookVim[" + version + "]: Keeping files");
}
- catch(err)
+ else
{
- WScript.Echo("OutlookVim[" + version + "]: Failed to get and delete email file["+emailfile+"]:"+err.message);
- }
+ WScript.Echo("OutlookVim[" + version + "]: Deleting files[" + persistfiles + "]");
+ try
+ {
+ f = fs.GetFile(emailfile);
+ f.Delete();
+ }
+ catch(err)
+ {
+ WScript.Echo("OutlookVim[" + version + "]: Failed to get and delete email file["+emailfile+"] Err["+err.message+"]");
+ }
- try
- {
- fid = fs.GetFile(ctlfile);
- fid.Delete();
- }
- catch(err)
- {
- WScript.Echo("OutlookVim[" + version + "]: Failed to get and delete control file["+ctlfile+"]:"+err.message);
+ try
+ {
+ fid = fs.GetFile(ctlfile);
+ fid.Delete();
+ }
+ catch(err)
+ {
+ WScript.Echo("OutlookVim[" + version + "]: Failed to get and delete control file["+ctlfile+"] Err["+err.message+"]");
+ }
}
}
- WScript.Echo("OutlookVim[" + version + "]: Successfully updated Outlook, message ID:"+entryID);
+ WScript.Echo("OutlookVim[" + version + "]: Successfully updated Outlook, message ID["+entryID+"]");
}
if( 0 == objArgs.length )
@@ -190,11 +226,17 @@ if( 0 == objArgs.length )
} else {
var emailfile = objArgs(0);
var persistfiles = 0;
+ var bodyformat = "plain";
if( objArgs.length > 1 )
{
var persistfiles = objArgs(1);;
- WScript.Echo("OutlookVim[" + version + "]: Persist files, overriding to:" + persistfiles);
+ WScript.Echo("OutlookVim[" + version + "]: Persist files, overriding to[" + persistfiles + "]");
+ }
+ if( objArgs.length > 2 )
+ {
+ var bodyformat = objArgs(2);;
+ WScript.Echo("OutlookVim[" + version + "]: Body format overriding to[" + bodyformat + "]");
}
- updateOutlook( emailfile, persistfiles );
+ updateOutlook( emailfile, persistfiles, bodyformat );
}
Please sign in to comment.
Something went wrong with that request. Please try again.