Missing headers when forwarding html message as RFC822
[notmuch-archives.git] / ca / 56d429c4eeccb484896f5512f3abd40b69670a
1 Return-Path: <too@guru-group.fi>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 34818431FAF\r
6         for <notmuch@notmuchmail.org>; Thu, 10 Jul 2014 14:13:24 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
12         autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id V+tidhWHrZwI for <notmuch@notmuchmail.org>;\r
16         Thu, 10 Jul 2014 14:13:17 -0700 (PDT)\r
17 Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])\r
18         by olra.theworths.org (Postfix) with ESMTP id 8F573431FAE\r
19         for <notmuch@notmuchmail.org>; Thu, 10 Jul 2014 14:13:17 -0700 (PDT)\r
20 Received: by guru.guru-group.fi (Postfix, from userid 501)\r
21         id 833171000C9; Fri, 11 Jul 2014 00:13:08 +0300 (EEST)\r
22 From: Tomi Ollila <tomi.ollila@iki.fi>\r
23 To: notmuch@notmuchmail.org, jani@nikula.org, david@tethera.net,\r
24         jrollins@finestructure.net\r
25 Subject: [DRAFT PATCH] modified notmuch-emacs-mua\r
26 Date: Fri, 11 Jul 2014 00:12:59 +0300\r
27 Message-Id: <1405026779-29966-1-git-send-email-tomi.ollila@iki.fi>\r
28 X-Mailer: git-send-email 2.0.0\r
29 MIME-Version: 1.0\r
30 Content-Type: text/plain; charset=UTF-8\r
31 Content-Transfer-Encoding: 8bit\r
32 Cc: tomi.ollila@iki.fi\r
33 X-BeenThere: notmuch@notmuchmail.org\r
34 X-Mailman-Version: 2.1.13\r
35 Precedence: list\r
36 List-Id: "Use and development of the notmuch mail system."\r
37         <notmuch.notmuchmail.org>\r
38 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
39         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
40 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
41 List-Post: <mailto:notmuch@notmuchmail.org>\r
42 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
43 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
44         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
45 X-List-Received-Date: Thu, 10 Jul 2014 21:13:24 -0000\r
46 \r
47 Highlights:\r
48 \r
49 * notmuch-emacs-mua without arguments runs (notmuch-hello)\r
50 \r
51 * runs emacs(1) in case emacsclient(1) fails to connect to running emacs\r
52 \r
53 * takes -nw option\r
54 \r
55 * handles mailto:\r
56 \r
57 * --from option when sending non-mailto: way\r
58 \r
59 * -i includes file --body[= ]string inserts string\r
60 ---\r
61  notmuch-emacs-mua | 200 ++++++++++++++++++++++++++++++++++++++++++++++++++++++\r
62  1 file changed, 200 insertions(+)\r
63  create mode 100755 notmuch-emacs-mua\r
64 \r
65 diff --git a/notmuch-emacs-mua b/notmuch-emacs-mua\r
66 new file mode 100755\r
67 index 0000000..b1696f7\r
68 --- /dev/null\r
69 +++ b/notmuch-emacs-mua\r
70 @@ -0,0 +1,200 @@\r
71 +#!/usr/bin/env bash\r
72 +# -*- mode: shell-script; sh-basic-offset: 4; tab-width: 8 -*-\r
73 +#\r
74 +# notmuch-emacs-mua - start composing a mail on the command line\r
75 +#\r
76 +# Copyright © 2014 Jani Nikula\r
77 +#\r
78 +# This program is free software: you can redistribute it and/or modify\r
79 +# it under the terms of the GNU General Public License as published by\r
80 +# the Free Software Foundation, either version 3 of the License, or\r
81 +# (at your option) any later version.\r
82 +#\r
83 +# This program is distributed in the hope that it will be useful,\r
84 +# but WITHOUT ANY WARRANTY; without even the implied warranty of\r
85 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
86 +# GNU General Public License for more details.\r
87 +#\r
88 +# You should have received a copy of the GNU General Public License\r
89 +# along with this program.  If not, see http://www.gnu.org/licenses/ .\r
90 +#\r
91 +# Authors: Jani Nikula <jani@nikula.org>\r
92 +#          Tomi Ollila <tomi.ollila@iki.fi>\r
93 +#\r
94 +\r
95 +set -eu\r
96 +\r
97 +# "expand" '\' to '\\' & '"' to '\"'\r
98 +escape_optarg ()\r
99 +{\r
100 +    OPTARG=${OPTARG//\\/\\\\}; OPTARG=${OPTARG//\"/\\\"}\r
101 +}\r
102 +\r
103 +# ditto, in case there is '\n' sequence in the source, otherwise\r
104 +# "expand" only trailing '\'s to '\\'s\r
105 +escape_body_optarg ()\r
106 +{\r
107 +    case ${OPTARG} in\r
108 +       *'\"'*) OPTARG=${OPTARG//\\/\\\\} ;;\r
109 +       *'\') OPTARG=$( printf %s "${OPTARG}" | sed 's/\(\\*\)$/\1\1/' )\r
110 +    esac\r
111 +    OPTARG=${OPTARG//\"/\\\"}\r
112 +}\r
113 +\r
114 +unset ALTERNATE_EDITOR\r
115 +exec_mua ()\r
116 +{\r
117 +    if "${EMACSCLIENT:=emacsclient}" --eval t >/dev/null 2>&1\r
118 +    then\r
119 +       emacs=$EMACSCLIENT\r
120 +       # close stdout in case no -nw (and no --print)\r
121 +       test -n "$W$X" || exec >/dev/null\r
122 +    else\r
123 +       emacs=${EMACS:-emacs}\r
124 +    fi\r
125 +    ${X:-exec} "$emacs" $W --eval "$*"\r
126 +    exit\r
127 +    ${X:-exec "$emacs" $W --eval} "$*"\r
128 +}\r
129 +\r
130 +X=\r
131 +W=\r
132 +\r
133 +SUBJECT= TO= CC= BCC= BODY= FROM= IB=\r
134 +\r
135 +while\r
136 +    # first, handle "long" options which cannot be handled by getopts\r
137 +    case ${1-} in\r
138 +       -nw)\r
139 +           W=-nw\r
140 +           shift\r
141 +           continue\r
142 +           ;;\r
143 +       mailto:*)\r
144 +           oIFS=$IFS; IFS=; OPTARG="$*" IFS=$oIFS\r
145 +           escape_optarg\r
146 +           exec_mua "(progn (require 'notmuch) (browse-url-mail \"$OPTARG\"))"\r
147 +           exit\r
148 +    esac\r
149 +\r
150 +    getopts :s:c:b:i:h opt\r
151 +do\r
152 +    # Handle errors and long options.\r
153 +    case ${opt} in\r
154 +       :)\r
155 +           echo "$0: short option '-${OPTARG}' requires an argument." >&2\r
156 +           exit 1\r
157 +           ;;\r
158 +       \?)\r
159 +           opt=$1\r
160 +           if [[ ${OPTARG} != '-' ]]; then\r
161 +               echo "$0: unknown short option '-${OPTARG}'." >&2\r
162 +               exit 1\r
163 +           fi\r
164 +\r
165 +           case ${opt} in\r
166 +               # Long options with arguments.\r
167 +               --subject=*|--to=*|--cc=*|--bcc=*|--body=*|--from=*)\r
168 +                   OPTARG=${opt#--*=}\r
169 +                   opt=${opt%%=*}\r
170 +                   ;;\r
171 +               # Long options with argument in next arg.\r
172 +               --subject  |--to  |--cc  |--bcc  |--body  |--from  )\r
173 +                   if [[ $# < 2 ]]; then\r
174 +                       echo "$0: option '${opt}' requires an argument." >&2\r
175 +                       exit 1\r
176 +                   fi\r
177 +                   OPTARG=$2\r
178 +                   OPTIND=$((OPTIND + 1))\r
179 +                   ;;\r
180 +               # Long options without arguments.\r
181 +               --help|--nw|--print)\r
182 +                   ;;\r
183 +               *)\r
184 +                   echo "$0: unknown long option '${opt}', or argument mismatch." >&2\r
185 +                   exit 1\r
186 +                   ;;\r
187 +           esac\r
188 +           # getopts does not do this for what it considers errors.\r
189 +           OPTIND=$((OPTIND + 1))\r
190 +           ;;\r
191 +    esac\r
192 +\r
193 +    case ${opt} in\r
194 +       --help|h)\r
195 +           exec man notmuch-emacs-mua\r
196 +           ;;\r
197 +       --from)\r
198 +           escape_optarg\r
199 +           FROM=${OPTARG}\r
200 +           ;;\r
201 +       --subject|s)\r
202 +           escape_optarg\r
203 +           SUBJECT=${SUBJECT:+$SUBJECT }${OPTARG}\r
204 +           ;;\r
205 +       --to)\r
206 +           escape_optarg\r
207 +           TO=${TO:+$TO, }${OPTARG}\r
208 +           ;;\r
209 +       --cc|c)\r
210 +           escape_optarg\r
211 +           CC=${CC:+$CC, }${OPTARG}\r
212 +           ;;\r
213 +       --bcc|b)\r
214 +           escape_optarg\r
215 +           BCC=${BCC:+$BCC, }${OPTARG}\r
216 +           ;;\r
217 +       i)\r
218 +           escape_optarg\r
219 +           if [[ ! -f ${OPTARG} ]]; then\r
220 +               echo "$0: '${OPTARG}': no such file" >&2\r
221 +               exit 1\r
222 +           fi\r
223 +           IB=${IB}$'\n'"  (insert-file \"${OPTARG}\")"\r
224 +           IB=${IB}$'\n'"  (if /= (point) (line-beginning-position) (insert \"\\n\"))"\r
225 +           ;;\r
226 +       --body)\r
227 +           escape_body_optarg\r
228 +           IB=${IB}$'\n'"  (insert \"${OPTARG}\\n\")"\r
229 +           ;;\r
230 +       --nw)\r
231 +           W=-nw\r
232 +           ;;\r
233 +       --print)\r
234 +           X=echo\r
235 +           ;;\r
236 +       *)\r
237 +           # We should never end up here.\r
238 +           echo "$0: internal error (option '${opt}')." >&2\r
239 +           exit 1\r
240 +           ;;\r
241 +    esac\r
242 +\r
243 +    shift $((OPTIND - 1))\r
244 +    OPTIND=1\r
245 +done\r
246 +\r
247 +# Positional parameters.\r
248 +for arg; do\r
249 +    arg=${arg//\\/\\\\}; arg=${arg//\"/\\\"}\r
250 +    TO=${TO:+$TO, }${arg}\r
251 +done\r
252 +\r
253 +NL=$'\n'\r
254 +ELISP="\\r
255 +${CC:+$NL  (message-goto-cc) (insert \"$CC\")}\\r
256 +${BCC:+$NL  (message-goto-bcc) (insert \"$BCC\")}\\r
257 +${IB:+$NL  (message-goto-body)$IB}"\r
258 +\r
259 +if [[ $TO == '' && $SUBJECT == '' && $ELISP == '' ]]\r
260 +then\r
261 +    exec_mua "(progn (require 'notmuch) (notmuch-hello))"\r
262 +else\r
263 +    [[ $FROM != '' ]] && OH="(list (cons 'From \"$FROM\"))" || OH=nil\r
264 +    [[ $TO != '' ]] && TO=\"$TO\" || TO=nil\r
265 +    [[ $SUBJECT != '' ]] && SUBJECT=\"$SUBJECT\" || SUBJECT=nil\r
266 +    exec_mua "$NL(progn (require 'notmuch)\r
267 +  (notmuch-mua-mail $TO $SUBJECT\r
268 +       $OH nil (notmuch-mua-get-switch-function))\\r
269 +$ELISP$NL  (set-buffer-modified-p nil) (message-goto-to))"\r
270 +fi\r
271 -- \r
272 1.9.0\r
273 \r