danchoi / vmail

a vim interface for gmail
http://danielchoi.com/software/vmail.html
MIT License
785 stars 59 forks source link

Feature: Optionally composing html emails #164

Open dhruvasagar opened 10 years ago

dhruvasagar commented 10 years ago

I would like the ability to compose HTML emails, which will allow me to use simple tags like

 (for code snippets), ,, etc for bold, italic & underlined text and such. What are the possibilities ?

As an alternative, at least for basic formatting options, I might even be happy with using connotations such as word, word, -word- etc for different effects. And converted before sending.

It might even be a nice idea to be able to compose mails in different formats such as perhaps markdown and such, and have them converted to html before sending.

gamag commented 10 years ago

Maybe adding a metadata field to the emails indicating a preprocessing option could do the trick, something like filter: markdown, which would pass the email without metadata through any program given instead of markdown and send the output of it instead of the original text. This would be enough for formatting needs, and would even make using pgp easier.

When metadata is needed, like the to: field for pgp, the filter could be restricted to scripts in a certain directory, which then have to parse the whole email including metadata.

dhruvasagar commented 10 years ago

This sounds like a good idea.

gamag commented 10 years ago

I forgot that to send html, a conten-type: text/html would be needed. So the user should have to possibility to change/specify the content type. For html mails it's sometimes desirable to have a plain text and a html version in one mail, for encrypted data, it's not, so things get a little complicated.

MaciekChudek commented 9 years ago

This is a good idea, so I whipped together a hack so I could send markdown emails until the feature gets implemented.

You need to patch two files (see patch below) to get vmail to preprocess your email through any arbitrary shell script you specify (piped through STDIN). It's important that your script:

  1. add a Content-type: text/html; header, and
  2. separate the headers (including attach: lines) from the body and only html-ify the body, leaving the headers at the top in plain text.

Here's my perl script that just runs the body part through markdown:

#!/bin/perl

use strict;
use warnings;

my $slurp = join('',<>);
my $x = ($slurp =~ m|f:m|); #search for shortened keyword "f:m"
if (!$x) {$x = ($slurp =~ m|filter: markdown|);} #search for full keyword
if ($x) {
    print "Content-type: text/html; charset=iso-8859-1\n".$`; #original headers ($` = string before match);
    print q{
<html><head><title></title></head>
<body>
};  # replace the keyword with html headers
    open(FH, "| markdown") || die "Couldn't run markdown";
    print FH $'; #pipe body through markdown, prints to std out
    close(FH);
    print "\n</body>\n</html>";
}else{
    print $slurp;
}

And here's the patch (remember to change "parse_mail.pl " to the name your own script):

--- a/vmail.vim 2015-08-29 02:10:41.790703085 -0700
+++ b/vmail.vim 2015-08-29 00:01:42.763514214 -0700
@@ -683,7 +686,8 @@
 function! s:send_message()
   let mail = join(getline(1,'$'), "\n")
   echo "Sending message"
-  let res = system(s:deliver_command, mail)
+  let parsed = system("parse_mail.pl ", mail)
+  let res = system(s:deliver_command, parsed)
   if match(res, '^Failed') == -1
     write!
     call s:close_and_focus_list_window()
--- a/vmail/imap_client.rb  2015-08-29 02:10:08.570197764 -0700
+++ b/vmail/imap_client.rb  2015-08-29 02:07:28.784422766 -0700
@@ -425,15 +423,20 @@
             mail.add_file(file) if File.size?(file)
           end
         end
-        mail.text_part do
-          body raw_body.split(/\n\s*\n/, 2)[1]
+        raw_body = raw_body.split(/\n\s*\n/, 2)[1]
+      end
+      if headers['Content-type'] =~ /html/
+        mail.html_part do
+          body raw_body
+          content_type headers['content-type']
         end
+        mail.html_part.charset = 'UTF-8'
       else
         mail.text_part do
           body raw_body
         end
+        mail.text_part.charset = 'UTF-8'
       end
-      mail.text_part.charset = 'UTF-8'
       mail
     rescue
       $logger.debug $!
dhruvasagar commented 9 years ago

Where's the like button when you need one! This would be really nice :)