mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-03-14 10:45:42 +08:00
fix(mail): fix mail logger
This commit is contained in:
parent
5ec1b3beb5
commit
1cc4282c99
@ -4,31 +4,31 @@ let s:job_noop_timer = ''
|
|||||||
let s:JOB = SpaceVim#api#import('job')
|
let s:JOB = SpaceVim#api#import('job')
|
||||||
|
|
||||||
function! mail#client#connect(ip, port)
|
function! mail#client#connect(ip, port)
|
||||||
let argv = ['telnet', a:ip, a:port]
|
let argv = ['telnet', a:ip, a:port]
|
||||||
let s:job_id = s:JOB.start(argv,
|
let s:job_id = s:JOB.start(argv,
|
||||||
\ {
|
\ {
|
||||||
\ 'on_stdout' : function('s:on_stdout'),
|
\ 'on_stdout' : function('s:on_stdout'),
|
||||||
\ 'on_stderr' : function('s:on_stderr'),
|
\ 'on_stderr' : function('s:on_stderr'),
|
||||||
\ 'on_exit' : function('s:on_exit'),
|
\ 'on_exit' : function('s:on_exit'),
|
||||||
\ }
|
\ }
|
||||||
\ )
|
\ )
|
||||||
|
call mail#client#logger#info('mail client job id:' . s:job_id)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Wed, 06 Sep 2017 02:55:41 +0000 ===> 2017-09-06
|
" Wed, 06 Sep 2017 02:55:41 +0000 ===> 2017-09-06
|
||||||
let s:__months = {
|
let s:__months = {
|
||||||
\ 'Sep' : 9,
|
\ 'Sep' : 9,
|
||||||
\ }
|
\ }
|
||||||
function! s:convert(date) abort
|
function! s:convert(date) abort
|
||||||
let info = split(a:date, ' ')
|
let info = split(a:date, ' ')
|
||||||
let year = info[3]
|
let year = info[3]
|
||||||
let m = get(s:__months, info[2], 00)
|
let m = get(s:__months, info[2], 00)
|
||||||
let day = len(info[1]) == 1 ? '0' . info[1] : info[1]
|
let day = len(info[1]) == 1 ? '0' . info[1] : info[1]
|
||||||
return join([year, m, day], '-')
|
return join([year, m, day], '-')
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:noop(id) abort
|
function! s:noop(id) abort
|
||||||
call mail#client#send(mail#command#noop())
|
call mail#client#send(mail#command#noop())
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
let s:_mail_id = -1
|
let s:_mail_id = -1
|
||||||
@ -38,72 +38,77 @@ let s:_mail_subject = ''
|
|||||||
let s:mail_unseen = 0
|
let s:mail_unseen = 0
|
||||||
|
|
||||||
function! s:parser(data) abort
|
function! s:parser(data) abort
|
||||||
if type(a:data) == 3
|
if type(a:data) == 3
|
||||||
for data in a:data
|
for data in a:data
|
||||||
call mail#client#logger#info('STDOUT: ' . data)
|
call mail#client#logger#info('STDOUT: ' . data)
|
||||||
if data =~ '^\* \d\+ FETCH '
|
if data =~ '^\* \d\+ FETCH '
|
||||||
let s:_mail_id = matchstr(data, '\d\+')
|
let s:_mail_id = matchstr(data, '\d\+')
|
||||||
elseif data =~ '^From: '
|
elseif data =~ '^From: '
|
||||||
let s:_mail_from = substitute(data, '^From: ', '', 'g')
|
let s:_mail_from = substitute(data, '^From: ', '', 'g')
|
||||||
let s:_mail_from .= repeat(' ', 50 - len(s:_mail_from))
|
let s:_mail_from .= repeat(' ', 50 - len(s:_mail_from))
|
||||||
elseif data =~ '^Date: '
|
elseif data =~ '^Date: '
|
||||||
let s:_mail_date = s:convert(substitute(data, '^Date: ', '', 'g'))
|
let s:_mail_date = s:convert(substitute(data, '^Date: ', '', 'g'))
|
||||||
elseif data =~ '^Subject: '
|
elseif data =~ '^Subject: '
|
||||||
let s:_mail_subject = substitute(data, '^Subject: ', '', 'g')
|
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())
|
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'
|
elseif data =~ '* STATUS INBOX'
|
||||||
let s:mail_unseen = matchstr(data, '\d\+')
|
let s:mail_unseen = matchstr(data, '\d\+')
|
||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
else
|
else
|
||||||
echom a:data
|
echom a:data
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:on_stdout(id, data, event) abort
|
function! s:on_stdout(id, data, event) abort
|
||||||
call s:parser(a:data)
|
call mail#client#logger#info('STDOUT: ' . string(a:data))
|
||||||
|
call s:parser(a:data)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function! s:on_stderr(id, data, event) abort
|
function! s:on_stderr(id, data, event) abort
|
||||||
for data in a:data
|
for data in a:data
|
||||||
call mail#client#logger#error('STDERR: ' . data)
|
call mail#client#logger#error('STDERR: ' . data)
|
||||||
endfor
|
endfor
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:on_exit(id, data, event) abort
|
function! s:on_exit(id, data, event) abort
|
||||||
call s:parser(a:data)
|
call s:parser(a:data)
|
||||||
let s:job_id = 0
|
let s:job_id = 0
|
||||||
if !empty(s:job_noop_timer)
|
if !empty(s:job_noop_timer)
|
||||||
call timer_stop(s:job_noop_timer)
|
call timer_stop(s:job_noop_timer)
|
||||||
let s:job_noop_timer = ''
|
let s:job_noop_timer = ''
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
function! mail#client#send(command)
|
function! mail#client#send(command)
|
||||||
call mail#client#logger#info('Send command: ' . a:command)
|
call mail#client#logger#info('Send command: ' . a:command)
|
||||||
|
if s:job_id >= 0
|
||||||
call s:JOB.send(s:job_id, a:command)
|
call s:JOB.send(s:job_id, a:command)
|
||||||
|
else
|
||||||
|
call mail#client#logger#info('skipped!, job id is:' . s:job_id)
|
||||||
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! mail#client#open()
|
function! mail#client#open()
|
||||||
if s:job_id == 0
|
if s:job_id == 0
|
||||||
if !empty(g:mail_imap_login) && !empty(g:mail_imap_password)
|
if !empty(g:mail_imap_login) && !empty(g:mail_imap_password)
|
||||||
call mail#client#connect(g:mail_imap_host, g:mail_imap_port)
|
call mail#client#connect(g:mail_imap_host, g:mail_imap_port)
|
||||||
call mail#client#send(mail#command#login(g:mail_imap_login, g:mail_imap_password))
|
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#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#fetch('1:15', 'BODY[HEADER.FIELDS ("DATE" "FROM" "SUBJECT")]'))
|
||||||
call mail#client#send(mail#command#status('INBOX', '["RECENT"]'))
|
call mail#client#send(mail#command#status('INBOX', '["RECENT"]'))
|
||||||
let s:job_noop_timer = timer_start(20000, function('s:noop'), {'repeat' : -1})
|
let s:job_noop_timer = timer_start(20000, function('s:noop'), {'repeat' : -1})
|
||||||
endif
|
|
||||||
endif
|
endif
|
||||||
call mail#client#win#open()
|
endif
|
||||||
|
call mail#client#win#open()
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
function! mail#client#unseen()
|
function! mail#client#unseen()
|
||||||
|
|
||||||
return s:mail_unseen
|
return s:mail_unseen
|
||||||
|
|
||||||
endfunction
|
endfunction
|
||||||
|
@ -1,11 +1,4 @@
|
|||||||
let s:LOGGER = SpaceVim#api#import('logger')
|
let s:LOGGER =SpaceVim#logger#derive('mail')
|
||||||
|
|
||||||
let g:wsd = keys(s:LOGGER)
|
|
||||||
|
|
||||||
call s:LOGGER.set_name('vim-mail')
|
|
||||||
call s:LOGGER.set_level(1)
|
|
||||||
let s:LOGGER.silent = 0
|
|
||||||
|
|
||||||
|
|
||||||
function! mail#client#logger#info(msg)
|
function! mail#client#logger#info(msg)
|
||||||
call s:LOGGER.info(a:msg)
|
call s:LOGGER.info(a:msg)
|
||||||
@ -20,9 +13,3 @@ function! mail#client#logger#warn(msg)
|
|||||||
call s:LOGGER.warn(a:msg)
|
call s:LOGGER.warn(a:msg)
|
||||||
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! mail#client#logger#view()
|
|
||||||
|
|
||||||
call s:LOGGER.view()
|
|
||||||
|
|
||||||
endfunction
|
|
||||||
|
@ -4,13 +4,13 @@
|
|||||||
let s:BUFFER = SpaceVim#api#import('vim#buffer')
|
let s:BUFFER = SpaceVim#api#import('vim#buffer')
|
||||||
|
|
||||||
|
|
||||||
let s:bufnr = 0
|
let s: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 = {}
|
||||||
|
|
||||||
function! mail#client#win#open()
|
function! mail#client#win#open()
|
||||||
if s:bufnr == 0
|
if s:bufnr ==# -1
|
||||||
split __VIM_MAIL__
|
split __VIM_MAIL__
|
||||||
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
|
||||||
|
16
bundle/vim-mail/autoload/mail/logger.vim
Normal file
16
bundle/vim-mail/autoload/mail/logger.vim
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
let s:LOGGER =SpaceVim#logger#derive('vim-mail')
|
||||||
|
|
||||||
|
function! mail#logger#info(msg)
|
||||||
|
call s:LOGGER.info(a:msg)
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! mail#logger#error(msg)
|
||||||
|
call s:LOGGER.error(a:msg)
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! mail#logger#warn(msg)
|
||||||
|
|
||||||
|
call s:LOGGER.warn(a:msg)
|
||||||
|
|
||||||
|
endfunction
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user