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:
parent
17aac81445
commit
cefb375609
@ -85,27 +85,44 @@ function! s:data_handle(...) abort
|
|||||||
call s:on_stdout(1,1, [a:1])
|
call s:on_stdout(1,1, [a:1])
|
||||||
endfunction
|
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
|
function! s:on_stdout(id, data, event) abort
|
||||||
for data in a:data
|
for data in a:data
|
||||||
call mail#logger#info('STDOUT: ' . data)
|
call mail#logger#info('STDOUT: ' . data)
|
||||||
if data =~ '^\* \d\+ FETCH '
|
if s:stdout_is_context
|
||||||
let s:_mail_id = matchstr(data, '\d\+')
|
if data =~ 'OK Fetch completed'
|
||||||
elseif data =~ '^From: '
|
let s:stdout_is_context = 0
|
||||||
let s:_mail_from = substitute(data, '^From: ', '', 'g')
|
else
|
||||||
let s:_mail_from .= repeat(' ', 50 - len(s:_mail_from))
|
endif
|
||||||
elseif data =~ '^Date: '
|
else
|
||||||
let s:_mail_date = s:convert(substitute(data, '^Date: ', '', 'g'))
|
if data =~ '^\* \d\+ FETCH '
|
||||||
elseif data =~ '^Subject: '
|
let s:_mail_id = matchstr(data, '\d\+')
|
||||||
let s:_mail_subject = substitute(data, '^Subject: ', '', 'g')
|
elseif data =~ '^\*\s\+\d\+\s\+FETCH\s(BODY[TEXT\]'
|
||||||
call mail#client#mailbox#updatedir(s:_mail_id, s:_mail_from, s:_mail_date, s:_mail_subject, mail#client#win#currentDir())
|
let s:stdout_is_context = 1
|
||||||
elseif data =~ '* STATUS INBOX'
|
elseif data =~ '^From: '
|
||||||
let s:mail_unseen = matchstr(data, '\d\+')
|
let s:_mail_from = substitute(data, '^From: ', '', 'g')
|
||||||
elseif data =~# '* OK Coremail System IMap Server Ready'
|
let s:_mail_from .= repeat(' ', 50 - len(s:_mail_from))
|
||||||
call mail#client#send(mail#command#login(g:mail_imap_login, g:mail_imap_password))
|
elseif data =~ '^Date: '
|
||||||
call mail#client#send(mail#command#select(mail#client#win#currentDir()))
|
let s:_mail_date = s:convert(substitute(data, '^Date: ', '', 'g'))
|
||||||
call mail#client#send(mail#command#fetch('1:15', 'BODY[HEADER.FIELDS ("DATE" "FROM" "SUBJECT")]'))
|
elseif data =~ '^Subject: '
|
||||||
call mail#client#send(mail#command#status('INBOX', '["RECENT"]'))
|
let s:_mail_subject = substitute(data, '^Subject: ', '', 'g')
|
||||||
let s:job_noop_timer = timer_start(20000, function('s:noop'), {'repeat' : -1})
|
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
|
endif
|
||||||
endfor
|
endfor
|
||||||
endfunction
|
endfunction
|
||||||
|
@ -8,6 +8,7 @@ let s:ICONV = SpaceVim#api#import('iconv')
|
|||||||
|
|
||||||
|
|
||||||
let s:bufnr = -1
|
let s:bufnr = -1
|
||||||
|
let s:mail_context_bufnr = -1
|
||||||
let s:win_name = 'home'
|
let s:win_name = 'home'
|
||||||
let s:win_dir = 'INBOX'
|
let s:win_dir = 'INBOX'
|
||||||
let s:win_unseen = {}
|
let s:win_unseen = {}
|
||||||
@ -18,6 +19,7 @@ function! mail#client#win#open()
|
|||||||
let s:bufnr = bufnr('%')
|
let s:bufnr = bufnr('%')
|
||||||
setlocal buftype=nofile nobuflisted nolist noswapfile nowrap cursorline nospell nomodifiable nowrap norelativenumber number
|
setlocal buftype=nofile nobuflisted nolist noswapfile nowrap cursorline nospell nomodifiable nowrap norelativenumber number
|
||||||
nnoremap <silent><buffer> <F5> :call <SID>refresh()<Cr>
|
nnoremap <silent><buffer> <F5> :call <SID>refresh()<Cr>
|
||||||
|
nnoremap <silent><buffer> <Cr> :call <SID>view_mail()<Cr>
|
||||||
setfiletype VimMailClient
|
setfiletype VimMailClient
|
||||||
else
|
else
|
||||||
split
|
split
|
||||||
@ -26,6 +28,22 @@ function! mail#client#win#open()
|
|||||||
call s:refresh()
|
call s:refresh()
|
||||||
endfunction
|
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()
|
function! mail#client#win#currentDir()
|
||||||
return s:win_dir
|
return s:win_dir
|
||||||
endfunction
|
endfunction
|
||||||
|
Loading…
Reference in New Issue
Block a user