aboutsummaryrefslogtreecommitdiff
path: root/vim/autoload/mail/header/field.vim
blob: e27d13c0cef401a23cb92a8f8eef778380a79386 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
" Add a field to a header, regardless of whether a field by the same name is
" already present
function! mail#header#field#Add(header, name, body) abort
  let new = {
        \ 'name': a:name,
        \ 'body': a:body,
        \}
  call add(a:header['fields'], new)
endfunction

" Set a field in a header, replacing the first one with the same name (if
" any), and and removing any others
"
function! mail#header#field#Set(header, name, body) abort
  let fields = []
  let new = {
        \ 'name': a:name,
        \ 'body': a:body,
        \}
  for field in a:header['fields']
    if field['name'] ==? a:name
      if exists('new')
        let field = new | unlet new
      else
        continue
      endif
    endif
    call add(fields, field)
  endfor
  if exists('new')
    call add(fields, new) | unlet new
  endif
  let a:header['fields'] = fields
endfunction

" Remove a header field
function! mail#header#field#Clear(header, name) abort
  let fields = []
  for field in a:header['fields']
    if field['name'] !=? a:name
      call add(fields, field)
    endif
  endfor
  let a:header['fields'] = fields
endfunction