" bug-reply-to.vim - include nnn@bugs.d.o in Reply-To when sending mail " to a Debian bug " " Copyright (c) 2005, 2006 Adeodato Simó (dato@net.com.org.es) " Licensed under the terms of the MIT license, included below. " SITUATION: when Debian maintainers reply to a bug, it's usual to " receive private replies afterwards, since not all submitters are aware " that they should CC the bug address, or they may forget to do so. " SOLUTION: when mailing to a bug, set the Reply-To to the bug address, " and include one's own address there if a private copy is also desired. " This file provides a Vim function to do this; obviously, the mail " headers will have to be available in the edited file for this to work " (e.g., `set edit_headers` in Mutt). " USAGE: use an autocommand like the following one in order for a " Reply-To: nnn@bugs.debian.org header to be added automatically. The " function accepts any number of arguments, which will be interpreted as " addresses and added to the Reply-To header. If an argument starts with " 'h:' (case-insensitive), the rest will be interpreted as a header from " which to get the address from. " au FileType mail call Add_bug_to_reply_to() au FileType mail call Add_bug_to_reply_to('h:From') " TODO: make test suite function! Add_bug_to_reply_to (...) "{{{ let i = 1 let headers = "" let cont_header = 0 let line = getline(i) " Get To, Cc, and Bcc headers (each of which may be broken in several lines) while line != "" if line =~? '\v^(to|b?cc)' || (cont_header && line =~ '^\s') let headers = headers . line let cont_header = 1 else let cont_header = 0 endi let i = i + 1 let line = getline(i) endw let end_of_headers = i " Get a list of all the bug addresses let start = 0 let reply = "" let bug_regex = '\v\d+(-(quiet|done|close|forwarded))?\@bugs\.debian\.org' let index = match(headers, bug_regex, start) while index != -1 let addr = matchstr(headers, bug_regex, start) let reply = reply . addr . ", " let start = index + strlen(addr) let index = match(headers, bug_regex, start) endw if start != 0 " There was at least one bug address " Replies to -done mails go to the bug address let reply = substitute(reply, '\v-(done|close|forwarded)', '', 'g') " Extra addresses? let i = 1 while i <= a:0 let a = a:{i} if a =~? '\v^h:' " get value from header let j = 1 let h = substitute(a, '\v\ch:', '', '') let line = getline(j) while line != "" if line =~? '\v^' . h . ':' let a = substitute(line, '\v^[^:]+: *', '', '') break endi let j = j+1 let line = getline(j) endw endi let reply = reply . a . ', ' let i = i+1 endw " Appending a new header is fine, since mutt will merge and uniq them let reply = substitute(reply, '\v, *$', '', '') call append(end_of_headers - 1, "Reply-To: " . reply) endif endfu "}}} """ " MIT LICENSE (http://www.opensource.org/licenses/mit-license.php) " Permission is hereby granted, free of charge, to any person obtaining " a copy of this software and associated documentation files (the " "Software"), to deal in the Software without restriction, including " without limitation the rights to use, copy, modify, merge, publish, " distribute, sublicense, and/or sell copies of the Software, and to " permit persons to whom the Software is furnished to do so, subject to " the following conditions: " The above copyright notice and this permission notice shall be included " in all copies or substantial portions of the Software. " THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, " EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF " MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. " IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY " CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, " TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE " SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. " vim: sw=2 ft=vim