xref: /vim-8.2.3635/runtime/syntax/mail.vim (revision 01a6c216)
1" Vim syntax file
2" Language:		Mail file
3" Previous Maintainer:	Felix von Leitner <[email protected]>
4" Maintainer:		GI <[email protected]>, where a='gi1242+vim', b='gmail', c='com'
5" Last Change:		Wed 14 Aug 2013 08:24:52 AM PDT
6
7" Quit when a syntax file was already loaded
8if exists("b:current_syntax")
9  finish
10endif
11
12let s:cpo_save = &cpo
13set cpo&vim
14
15" The mail header is recognized starting with a "keyword:" line and ending
16" with an empty line or other line that can't be in the header. All lines of
17" the header are highlighted. Headers of quoted messages (quoted with >) are
18" also highlighted.
19
20" Syntax clusters
21syn cluster mailHeaderFields	contains=mailHeaderKey,mailSubject,mailHeaderEmail,@mailLinks
22syn cluster mailLinks		contains=mailURL,mailEmail
23syn cluster mailQuoteExps	contains=mailQuoteExp1,mailQuoteExp2,mailQuoteExp3,mailQuoteExp4,mailQuoteExp5,mailQuoteExp6
24
25syn case match
26" For "From " matching case is required. The "From " is not matched in quoted
27" emails
28" According to RFC 2822 any printable ASCII character can appear in a field
29" name, except ':'.
30syn region	mailHeader	contains=@mailHeaderFields,@NoSpell start="^From .*\d\d\d\d$" skip="^\s" end="\v^[!-9;-~]*([^!-~]|$)"me=s-1 fold
31syn match	mailHeaderKey	contained contains=mailEmail,@NoSpell "^From\s.*\d\d\d\d$"
32
33" Nothing else depends on case.
34syn case ignore
35
36" Headers in properly quoted (with "> " or ">") emails are matched
37syn region	mailHeader	keepend contains=@mailHeaderFields,@mailQuoteExps,@NoSpell start="^\z(\(> \?\)*\)\v(newsgroups|x-([a-z\-])*|path|xref|message-id|from|((in-)?reply-)?to|b?cc|subject|return-path|received|date|replied):" skip="^\z1\s" end="\v^\z1[!-9;-~]*([^!-~]|$)"me=s-1 end="\v^\z1@!"me=s-1 end="\v^\z1(\> ?)+"me=s-1 fold
38
39" Usenet headers
40syn match	mailHeaderKey	contained contains=mailHeaderEmail,mailEmail,@NoSpell "\v(^(\> ?)*)@<=(Newsgroups|Followup-To|Message-ID|Supersedes|Control):.*$"
41
42
43syn region	mailHeaderKey	contained contains=mailHeaderEmail,mailEmail,@mailQuoteExps,@NoSpell start="\v(^(\> ?)*)@<=(to|b?cc):" skip=",$" end="$"
44syn match	mailHeaderKey	contained contains=mailHeaderEmail,mailEmail,@NoSpell "\v(^(\> ?)*)@<=(from|reply-to):.*$" fold
45syn match	mailHeaderKey	contained contains=@NoSpell "\v(^(\> ?)*)@<=date:"
46syn match	mailSubject	contained "\v^subject:.*$" fold
47syn match	mailSubject	contained contains=@NoSpell "\v(^(\> ?)+)@<=subject:.*$"
48
49" Anything in the header between < and > is an email address
50syn match	mailHeaderEmail	contained contains=@NoSpell "<.\{-}>"
51
52" Mail Signatures. (Begin with "-- ", end with change in quote level)
53syn region	mailSignature	keepend contains=@mailLinks,@mailQuoteExps start="^--\s$" end="^$" end="^\(> \?\)\+"me=s-1 fold
54syn region	mailSignature	keepend contains=@mailLinks,@mailQuoteExps,@NoSpell start="^\z(\(> \?\)\+\)--\s$" end="^\z1$" end="^\z1\@!"me=s-1 end="^\z1\(> \?\)\+"me=s-1 fold
55
56" Treat verbatim Text special.
57syn region	mailVerbatim	contains=@NoSpell keepend start="^#v+$" end="^#v-$" fold
58syn region	mailVerbatim	contains=@mailQuoteExps,@NoSpell keepend start="^\z(\(> \?\)\+\)#v+$" end="\z1#v-$" fold
59
60" URLs start with a known protocol or www,web,w3.
61syn match mailURL contains=@NoSpell `\v<(((https?|ftp|gopher)://|(mailto|file|news):)[^' 	<>"]+|(www|web|w3)[a-z0-9_-]*\.[a-z0-9._-]+\.[^' 	<>"]+)[a-z0-9/]`
62syn match mailEmail contains=@NoSpell "\v[_=a-z\./+0-9-]+\@[a-z0-9._-]+\a{2}"
63
64" Make sure quote markers in regions (header / signature) have correct color
65syn match mailQuoteExp1	contained "\v^(\> ?)"
66syn match mailQuoteExp2	contained "\v^(\> ?){2}"
67syn match mailQuoteExp3	contained "\v^(\> ?){3}"
68syn match mailQuoteExp4	contained "\v^(\> ?){4}"
69syn match mailQuoteExp5	contained "\v^(\> ?){5}"
70syn match mailQuoteExp6	contained "\v^(\> ?){6}"
71
72" Even and odd quoted lines. Order is important here!
73syn region	mailQuoted6	keepend contains=mailVerbatim,mailHeader,@mailLinks,mailSignature,@NoSpell start="^\z(\(\([a-z]\+>\|[]|}>]\)[ \t]*\)\{5}\([a-z]\+>\|[]|}>]\)\)" end="^\z1\@!" fold
74syn region	mailQuoted5	keepend contains=mailQuoted6,mailVerbatim,mailHeader,@mailLinks,mailSignature,@NoSpell start="^\z(\(\([a-z]\+>\|[]|}>]\)[ \t]*\)\{4}\([a-z]\+>\|[]|}>]\)\)" end="^\z1\@!" fold
75syn region	mailQuoted4	keepend contains=mailQuoted5,mailQuoted6,mailVerbatim,mailHeader,@mailLinks,mailSignature,@NoSpell start="^\z(\(\([a-z]\+>\|[]|}>]\)[ \t]*\)\{3}\([a-z]\+>\|[]|}>]\)\)" end="^\z1\@!" fold
76syn region	mailQuoted3	keepend contains=mailQuoted4,mailQuoted5,mailQuoted6,mailVerbatim,mailHeader,@mailLinks,mailSignature,@NoSpell start="^\z(\(\([a-z]\+>\|[]|}>]\)[ \t]*\)\{2}\([a-z]\+>\|[]|}>]\)\)" end="^\z1\@!" fold
77syn region	mailQuoted2	keepend contains=mailQuoted3,mailQuoted4,mailQuoted5,mailQuoted6,mailVerbatim,mailHeader,@mailLinks,mailSignature,@NoSpell start="^\z(\(\([a-z]\+>\|[]|}>]\)[ \t]*\)\{1}\([a-z]\+>\|[]|}>]\)\)" end="^\z1\@!" fold
78syn region	mailQuoted1	keepend contains=mailQuoted2,mailQuoted3,mailQuoted4,mailQuoted5,mailQuoted6,mailVerbatim,mailHeader,@mailLinks,mailSignature,@NoSpell start="^\z([a-z]\+>\|[]|}>]\)" end="^\z1\@!" fold
79
80" Need to sync on the header. Assume we can do that within 100 lines
81if exists("mail_minlines")
82    exec "syn sync minlines=" . mail_minlines
83else
84    syn sync minlines=100
85endif
86
87" Define the default highlighting.
88hi def link mailVerbatim	Special
89hi def link mailHeader		Statement
90hi def link mailHeaderKey	Type
91hi def link mailSignature	PreProc
92hi def link mailHeaderEmail	mailEmail
93hi def link mailEmail		Special
94hi def link mailURL		String
95hi def link mailSubject		Title
96hi def link mailQuoted1		Comment
97hi def link mailQuoted3		mailQuoted1
98hi def link mailQuoted5		mailQuoted1
99hi def link mailQuoted2		Identifier
100hi def link mailQuoted4		mailQuoted2
101hi def link mailQuoted6		mailQuoted2
102hi def link mailQuoteExp1	mailQuoted1
103hi def link mailQuoteExp2	mailQuoted2
104hi def link mailQuoteExp3	mailQuoted3
105hi def link mailQuoteExp4	mailQuoted4
106hi def link mailQuoteExp5	mailQuoted5
107hi def link mailQuoteExp6	mailQuoted6
108
109let b:current_syntax = "mail"
110
111let &cpo = s:cpo_save
112unlet s:cpo_save
113