Subject: vim6+python abuse

From: Omer Mussaev <[email-masked]>
Date: Tue, 28 Nov 2000 10:51:38 +0200

there are short and slightly ugly mail-lookup scripts for vim6+python.
If you do not have vim6+python, there is a screenshot.
Enjoy.

P.S. This is my first python program, so falmes are not accepted:)

" vim

command! -nargs=+ Mail call Mail_lookup (<q-args>)

function! Mail_lookup (expression)
       exec 'set nonumber'
       exec 'python msg_to_get='.a:expression
       exec 'pyfile ~/mail_reader.vim.py' 
endfunction
import imaplib, getpass, string, vim, re
#
mailserver="mail.foo.org"
mailpasswd="password"

# msg_to_get should be set by vim, otherwise default is 10 
if msg_to_get == None: msg_to_get = 10

mailbox = imaplib.IMAP4( mailserver )
mailbox.login( getpass.getuser(), mailpasswd )
mailbox.select( )
typ, data = mailbox.search( None, 'All' )

for num in string.split( data[ 0 ] ): 
   last = int( num )
mime_pattern = re.compile( r'This message is in MIME format|Content-type: image/jpeg' )
vbuff = vim.current.buffer 
vim.command( "normal ggvGd" )
for msg in range( last - msg_to_get, last ):
   dummy, data = mailbox.fetch( int (msg), '(BODY[HEADER.FIELDS (DATE)] BODY[HEADER.FIELDS (FROM)] BODY[HEADER.FIELDS (SUBJECT)] BODY[TEXT])')
   for str in (data[0][1], data[1][1], data[2][1] ):
      vbuff.append( string.split ( str, "\n" )[0] )
   bstart = len( vbuff )
   if mime_pattern.search( data[3][1] ) == None: 
      vbuff.append( string.split( data[3][1], "\n"))
   else: 
      vbuff.append( "Message contains MIME parts, skipped" )
   bend=len( vbuff )
   if bstart+1<bend: 
      vcommand= "%d,%dfold" % ( bstart + 1, bend )
      vim.command( vcommand )
mailbox.logout()

vim.command( "%s/
//g" ) ;  vim.command( "set nonumber" )
vim.command( "so $VIM/syntax/mail.vim" )
vim.command( "normal G?^From:\n" )

---

From: Chen Shapira <[email-masked]>
Date: Tue, 28 Nov 2000 11:09:48 +0200

> >
> 
> Try jacal (http://www-swiss.ai.mit.edu/~jaffer/JACAL.html) or yacas 
> (http://www.xs4all.nl/~apinkus/yacas.html). The yacas 
> homepage contains
> links to many other computer algebra programs, and I have a URL of a
> directory of math program at home which I can send you (when 
> I get home).

Jacal seems perfect! Thanks!