1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-01-23 13:00:04 +08:00

feat(mail): add function to view mail context

This commit is contained in:
Shidong Wang 2021-10-24 16:11:33 +08:00
parent 17aac81445
commit cefb375609
No known key found for this signature in database
GPG Key ID: 41BB7053E835C848
2 changed files with 53 additions and 18 deletions

View File

@ -85,11 +85,27 @@ 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 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))
@ -107,6 +123,7 @@ function! s:on_stdout(id, data, event) abort
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

View File

@ -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 <silent><buffer> <F5> :call <SID>refresh()<Cr>
nnoremap <silent><buffer> <Cr> :call <SID>view_mail()<Cr>
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