diff --git a/bundle/vim-mail/autoload/mail/client.vim b/bundle/vim-mail/autoload/mail/client.vim index 0739f6c6f..e2db7a91f 100644 --- a/bundle/vim-mail/autoload/mail/client.vim +++ b/bundle/vim-mail/autoload/mail/client.vim @@ -85,27 +85,44 @@ function! s:data_handle(...) abort call s:on_stdout(1,1, [a:1]) endfunction +" [ vim-mail ] [15:52:30] [ Info ] Send command: WKHCh FETCH 6:6 BODY[TEXT] +" [ vim-mail ] [15:52:30] [ Info ] STDOUT: * 6 FETCH (BODY[TEXT] {14} +" [ vim-mail ] [15:52:30] [ Info ] STDOUT: Ym9keSAxMjM0 +" [ vim-mail ] [15:52:30] [ Info ] STDOUT: ) +" [ vim-mail ] [15:52:30] [ Info ] STDOUT: WKHCh OK Fetch completed +" [ vim-mail ] [15:52:30] [ Info ] STDOUT: + +let s:stdout_is_context = 0 function! s:on_stdout(id, data, event) abort for data in a:data call mail#logger#info('STDOUT: ' . data) - if data =~ '^\* \d\+ FETCH ' - let s:_mail_id = matchstr(data, '\d\+') - elseif data =~ '^From: ' - let s:_mail_from = substitute(data, '^From: ', '', 'g') - let s:_mail_from .= repeat(' ', 50 - len(s:_mail_from)) - elseif data =~ '^Date: ' - let s:_mail_date = s:convert(substitute(data, '^Date: ', '', 'g')) - elseif data =~ '^Subject: ' - let s:_mail_subject = substitute(data, '^Subject: ', '', 'g') - call mail#client#mailbox#updatedir(s:_mail_id, s:_mail_from, s:_mail_date, s:_mail_subject, mail#client#win#currentDir()) - elseif data =~ '* STATUS INBOX' - let s:mail_unseen = matchstr(data, '\d\+') - elseif data =~# '* OK Coremail System IMap Server Ready' - call mail#client#send(mail#command#login(g:mail_imap_login, g:mail_imap_password)) - call mail#client#send(mail#command#select(mail#client#win#currentDir())) - call mail#client#send(mail#command#fetch('1:15', 'BODY[HEADER.FIELDS ("DATE" "FROM" "SUBJECT")]')) - call mail#client#send(mail#command#status('INBOX', '["RECENT"]')) - let s:job_noop_timer = timer_start(20000, function('s:noop'), {'repeat' : -1}) + if s:stdout_is_context + if data =~ 'OK Fetch completed' + let s:stdout_is_context = 0 + else + endif + else + if data =~ '^\* \d\+ FETCH ' + let s:_mail_id = matchstr(data, '\d\+') + elseif data =~ '^\*\s\+\d\+\s\+FETCH\s(BODY[TEXT\]' + let s:stdout_is_context = 1 + elseif data =~ '^From: ' + let s:_mail_from = substitute(data, '^From: ', '', 'g') + let s:_mail_from .= repeat(' ', 50 - len(s:_mail_from)) + elseif data =~ '^Date: ' + let s:_mail_date = s:convert(substitute(data, '^Date: ', '', 'g')) + elseif data =~ '^Subject: ' + let s:_mail_subject = substitute(data, '^Subject: ', '', 'g') + call mail#client#mailbox#updatedir(s:_mail_id, s:_mail_from, s:_mail_date, s:_mail_subject, mail#client#win#currentDir()) + elseif data =~ '* STATUS INBOX' + let s:mail_unseen = matchstr(data, '\d\+') + elseif data =~# '* OK Coremail System IMap Server Ready' + call mail#client#send(mail#command#login(g:mail_imap_login, g:mail_imap_password)) + call mail#client#send(mail#command#select(mail#client#win#currentDir())) + call mail#client#send(mail#command#fetch('1:15', 'BODY[HEADER.FIELDS ("DATE" "FROM" "SUBJECT")]')) + call mail#client#send(mail#command#status('INBOX', '["RECENT"]')) + let s:job_noop_timer = timer_start(20000, function('s:noop'), {'repeat' : -1}) + endif endif endfor endfunction diff --git a/bundle/vim-mail/autoload/mail/client/win.vim b/bundle/vim-mail/autoload/mail/client/win.vim index 539907286..3c1a68e68 100644 --- a/bundle/vim-mail/autoload/mail/client/win.vim +++ b/bundle/vim-mail/autoload/mail/client/win.vim @@ -8,6 +8,7 @@ let s:ICONV = SpaceVim#api#import('iconv') let s:bufnr = -1 +let s:mail_context_bufnr = -1 let s:win_name = 'home' let s:win_dir = 'INBOX' let s:win_unseen = {} @@ -18,6 +19,7 @@ function! mail#client#win#open() let s:bufnr = bufnr('%') setlocal buftype=nofile nobuflisted nolist noswapfile nowrap cursorline nospell nomodifiable nowrap norelativenumber number nnoremap :call refresh() + nnoremap :call view_mail() setfiletype VimMailClient else split @@ -26,6 +28,22 @@ function! mail#client#win#open() call s:refresh() endfunction +function! s:view_mail() abort + let uid = line('.') - 1 + let dir = s:win_dir + tabedit __VIM_MAIL__context + setlocal buftype=nofile nobuflisted nolist noswapfile nowrap cursorline nospell nomodifiable nowrap norelativenumber number + let s:mail_context_bufnr = bufnr('%') + call mail#client#send(mail#command#fetch(uid . ':' . uid, 'BODY[TEXT]')) +endfunction + +function! mail#client#win#update_context(stdout) abort + let text = s:BASE64.decode(a:stdout) + call setbufvar(s:mail_context_bufnr, '&modifiable', 1) + call s:BUFFER.buf_set_lines(s:mail_context_bufnr, -1, -1, 0, [text]) + call setbufvar(s:mail_context_bufnr, '&modifiable', 0) +endfunction + function! mail#client#win#currentDir() return s:win_dir endfunction