blob: 7717cd970ae7125a6aad5b8c25e099c654755ae6 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim syntax file
2" Language: Mail file
3" Previous Maintainer: Felix von Leitner <leitner@math.fu-berlin.de>
4" Maintainer: Gautam Iyer <gautam@math.uchicago.edu>
Bram Moolenaar75c50c42005-06-04 22:06:24 +00005" Last Change: Wed 01 Jun 2005 02:11:07 PM CDT
Bram Moolenaar071d4272004-06-13 20:20:40 +00006
7" Quit when a syntax file was already loaded
8if exists("b:current_syntax")
9 finish
10endif
11
12" The mail header is recognized starting with a "keyword:" line and ending
13" with an empty line or other line that can't be in the header. All lines of
14" the header are highlighted. Headers of quoted messages (quoted with >) are
15" also highlighted.
16
17" Syntax clusters
18syn cluster mailHeaderFields contains=mailHeaderKey,mailSubject,mailHeaderEmail,@mailLinks
19syn cluster mailLinks contains=mailURL,mailEmail
20syn cluster mailQuoteExps contains=mailQuoteExp1,mailQuoteExp2,mailQuoteExp3,mailQuoteExp4,mailQuoteExp5,mailQuoteExp6
21
22syn case match
23" For "From " matching case is required. The "From " is not matched in quoted
24" emails
Bram Moolenaarc81e5e72007-05-05 18:24:42 +000025" According to RFC 2822 any printable ASCII character can appear in a field
26" name, except ':'.
27syn region mailHeader contains=@mailHeaderFields,@NoSpell start="^From " skip="^\s" end="\v^[!-9;-~]*([^!-~]|$)"me=s-1
Bram Moolenaar6bb68362005-03-22 23:03:44 +000028syn match mailHeaderKey contained contains=mailEmail,@NoSpell "^From\s.*$"
Bram Moolenaar071d4272004-06-13 20:20:40 +000029
30syn case ignore
31" Nothing else depends on case. Headers in properly quoted (with "> " or ">")
32" emails are matched
Bram Moolenaarc81e5e72007-05-05 18:24:42 +000033syn region mailHeader keepend contains=@mailHeaderFields,@mailQuoteExps,@NoSpell start="^\z(\(> \?\)*\)\v(newsgroups|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
Bram Moolenaar071d4272004-06-13 20:20:40 +000034
Bram Moolenaar6bb68362005-03-22 23:03:44 +000035syn region mailHeaderKey contained contains=mailHeaderEmail,mailEmail,@mailQuoteExps,@NoSpell start="\v(^(\> ?)*)@<=(to|b?cc):" skip=",$" end="$"
36syn match mailHeaderKey contained contains=mailHeaderEmail,mailEmail,@NoSpell "\v(^(\> ?)*)@<=(from|reply-to):.*$"
Bram Moolenaar75c50c42005-06-04 22:06:24 +000037syn match mailHeaderKey contained contains=@NoSpell "\v(^(\> ?)*)@<=date:"
38syn match mailSubject contained "\v^subject:.*$"
39syn match mailSubject contained contains=@NoSpell "\v(^(\> ?)+)@<=subject:.*$"
Bram Moolenaar071d4272004-06-13 20:20:40 +000040
41" Anything in the header between < and > is an email address
Bram Moolenaar75c50c42005-06-04 22:06:24 +000042syn match mailHeaderEmail contained contains=@NoSpell "<.\{-}>"
Bram Moolenaar071d4272004-06-13 20:20:40 +000043
Bram Moolenaar4399ef42005-02-12 14:29:27 +000044" Mail Signatures. (Begin with "-- ", end with change in quote level)
Bram Moolenaar75c50c42005-06-04 22:06:24 +000045syn region mailSignature keepend contains=@mailLinks,@mailQuoteExps start="^--\s$" end="^$" end="^\(> \?\)\+"me=s-1
46syn region mailSignature keepend contains=@mailLinks,@mailQuoteExps,@NoSpell start="^\z(\(> \?\)\+\)--\s$" end="^\z1$" end="^\z1\@!"me=s-1 end="^\z1\(> \?\)\+"me=s-1
Bram Moolenaar071d4272004-06-13 20:20:40 +000047
48" URLs start with a known protocol or www,web,w3.
Bram Moolenaar75c50c42005-06-04 22:06:24 +000049syn match mailURL contains=@NoSpell `\v<(((https?|ftp|gopher)://|(mailto|file|news):)[^' <>"]+|(www|web|w3)[a-z0-9_-]*\.[a-z0-9._-]+\.[^' <>"]+)[a-z0-9/]`
50syn match mailEmail contains=@NoSpell "\v[_=a-z\./+0-9-]+\@[a-z0-9._-]+\a{2}"
Bram Moolenaar071d4272004-06-13 20:20:40 +000051
52" Make sure quote markers in regions (header / signature) have correct color
53syn match mailQuoteExp1 contained "\v^(\> ?)"
54syn match mailQuoteExp2 contained "\v^(\> ?){2}"
55syn match mailQuoteExp3 contained "\v^(\> ?){3}"
56syn match mailQuoteExp4 contained "\v^(\> ?){4}"
57syn match mailQuoteExp5 contained "\v^(\> ?){5}"
58syn match mailQuoteExp6 contained "\v^(\> ?){6}"
59
60" Even and odd quoted lines. order is imporant here!
Bram Moolenaar75c50c42005-06-04 22:06:24 +000061syn match mailQuoted1 contains=mailHeader,@mailLinks,mailSignature,@NoSpell "^\([a-z]\+>\|[]|}>]\).*$"
62syn match mailQuoted2 contains=mailHeader,@mailLinks,mailSignature,@NoSpell "^\(\([a-z]\+>\|[]|}>]\)[ \t]*\)\{2}.*$"
63syn match mailQuoted3 contains=mailHeader,@mailLinks,mailSignature,@NoSpell "^\(\([a-z]\+>\|[]|}>]\)[ \t]*\)\{3}.*$"
64syn match mailQuoted4 contains=mailHeader,@mailLinks,mailSignature,@NoSpell "^\(\([a-z]\+>\|[]|}>]\)[ \t]*\)\{4}.*$"
65syn match mailQuoted5 contains=mailHeader,@mailLinks,mailSignature,@NoSpell "^\(\([a-z]\+>\|[]|}>]\)[ \t]*\)\{5}.*$"
66syn match mailQuoted6 contains=mailHeader,@mailLinks,mailSignature,@NoSpell "^\(\([a-z]\+>\|[]|}>]\)[ \t]*\)\{6}.*$"
Bram Moolenaar071d4272004-06-13 20:20:40 +000067
68" Need to sync on the header. Assume we can do that within 100 lines
69if exists("mail_minlines")
70 exec "syn sync minlines=" . mail_minlines
71else
72 syn sync minlines=100
73endif
74
75" Define the default highlighting.
76hi def link mailHeader Statement
77hi def link mailHeaderKey Type
78hi def link mailSignature PreProc
79hi def link mailHeaderEmail mailEmail
80hi def link mailEmail Special
81hi def link mailURL String
82hi def link mailSubject LineNR
83hi def link mailQuoted1 Comment
84hi def link mailQuoted3 mailQuoted1
85hi def link mailQuoted5 mailQuoted1
86hi def link mailQuoted2 Identifier
87hi def link mailQuoted4 mailQuoted2
88hi def link mailQuoted6 mailQuoted2
89hi def link mailQuoteExp1 mailQuoted1
90hi def link mailQuoteExp2 mailQuoted2
91hi def link mailQuoteExp3 mailQuoted3
92hi def link mailQuoteExp4 mailQuoted4
93hi def link mailQuoteExp5 mailQuoted5
94hi def link mailQuoteExp6 mailQuoted6
95
96let b:current_syntax = "mail"