Again, there were some "bugs" in the function. Here's the final version.
No more "set edit_headers" assumption, no quotation problems.
function M_settitle()
let i = 1
let line = getline(i)
while (match(line, "To:") == -1 && line != "")
let i = i + 1
let line = getline(i)
endwhile
if (line != "")
let i = match(line, " ") + 1
let j = match(line, "<") - 1
if j == -2
let j = match(line, ",")
endif
if j == -1
let j = strlen(line)
endif
let len = j - i
let address = strpart(line, i, len)
let title = "Mail to " . address
let title = substitute(title, " ", "\\\\ ", "g")
let title = substitute(title, "\"", "", "g")
execute 'set titlestring=' . title
execute 'set iconstring=' . title
else
execute 'set titlestring=Mutt'
execute 'set iconstring=Mutt'
endif
execute 'set titleold=Mutt'
endfunc
Is it useful for someone besides me? :-)
Regards,
Peter.