From 31ab74f8bec3db93e89fa978d59371a76330788c Mon Sep 17 00:00:00 2001 From: Shidong Wang Date: Sat, 23 Oct 2021 15:51:36 +0800 Subject: [PATCH] feat(mail): add mail layer option --- autoload/SpaceVim/layers/mail.vim | 21 +++++++++++++++++++-- bundle/vim-mail/autoload/mail/client.vim | 2 +- bundle/vim-mail/plugin/mail.vim | 3 +++ doc/SpaceVim.txt | 8 +++++--- 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/autoload/SpaceVim/layers/mail.vim b/autoload/SpaceVim/layers/mail.vim index 49f278c68..2fcd893ae 100644 --- a/autoload/SpaceVim/layers/mail.vim +++ b/autoload/SpaceVim/layers/mail.vim @@ -10,10 +10,12 @@ " @section mail, layers-mail " @parentsection layers " The `mail` layer provides basic function to connected to mail server. -" +" NOTE: this layer is still wip now. " @subsection layer options " -" 1. `ssh_port`: set the port of mail server +" 1. `imap_host`: set the imap server host +" 2. `imap_port`: set the imap server port +" 3. `imap_login`: set the login of imap server " " @subsection key bindings " > @@ -21,15 +23,30 @@ " SPC a m open mail client " < +if exists('s:imap_host') + finish +endif + +let s:imap_host = 'imap.163.com' +let s:imap_port = 143 +let s:imap_login = '' + function! SpaceVim#layers#mail#plugins() abort return [ \ [g:_spacevim_root_dir . 'bundle/vim-mail', {'merged' : 0, 'loadconf' : 1}], \ ] endfunction +function! SpaceVim#layers#mail#set_variable(opt) abort + let s:imap_host = get(a:opt, 'imap_host', s:imap_host) + let s:imap_port = get(a:opt, 'imap_port', s:imap_port) +endfunction function! SpaceVim#layers#mail#config() abort call SpaceVim#mapping#space#def('nnoremap', ['a', 'm'], 'call mail#client#open()', 'Start mail client', 1) + let g:mail_imap_host = s:imap_port + let g:mail_imap_port = s:imap_port + let g:mail_imap_login = s:imap_login endfunction function! SpaceVim#layers#mail#health() abort diff --git a/bundle/vim-mail/autoload/mail/client.vim b/bundle/vim-mail/autoload/mail/client.vim index 37a438876..9939978a4 100644 --- a/bundle/vim-mail/autoload/mail/client.vim +++ b/bundle/vim-mail/autoload/mail/client.vim @@ -92,7 +92,7 @@ function! mail#client#open() let username = input('USERNAME: ') let password = input('PASSWORD: ') if !empty(username) && !empty(password) - call mail#client#connect('imap.163.com', 143) + call mail#client#connect(g:mail_imap_host, g:mail_imap_port) call mail#client#send(mail#command#login(username, 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")]')) diff --git a/bundle/vim-mail/plugin/mail.vim b/bundle/vim-mail/plugin/mail.vim index 3d7531c34..65b643545 100644 --- a/bundle/vim-mail/plugin/mail.vim +++ b/bundle/vim-mail/plugin/mail.vim @@ -12,6 +12,9 @@ let g:mail_method = 'imap' let g:mail_sending_name = 'Shidong Wang' let g:mail_sending_address = 'wsdjeg@163.com' let g:mail_logger_silent = 0 + +let g:mail_imap_host = get(g:, 'mail_imap_host', 'imap.163.com') + if !exists('g:mail_directory') let g:mail_directory = expand('~/.vim-mail/') endif diff --git a/doc/SpaceVim.txt b/doc/SpaceVim.txt index 9d7e088cc..add18473b 100644 --- a/doc/SpaceVim.txt +++ b/doc/SpaceVim.txt @@ -4624,11 +4624,13 @@ The following key bindings will be enabled when this layer is loaded: ============================================================================== MAIL *SpaceVim-layers-mail* -The `mail` layer provides basic function to connected to mail server. - +The `mail` layer provides basic function to connected to mail server. NOTE: +this layer is still wip now. LAYER OPTIONS - 1. `ssh_port`: set the port of mail server + 1. `imap_host`: set the imap server host + 2. `imap_port`: set the imap server port + 3. `imap_login`: set the login of imap server KEY BINDINGS