]> diplodocus.org Git - nmh/blob - docs/README-ATTACHMENTS
Added context_find_prefix().
[nmh] / docs / README-ATTACHMENTS
1 This document describes the previous attach interface. The attach
2 interface has changes for nmh 1.6 and later. The interface is
3 documented in send(1), whatnow(1), and mhbuild(1). No configuration
4 is required, and the same commands exist in whatnow; the two main
5 differences are that the header is now named "Attach", and mhbuild takes
6 care of the actual header processing.
7
8 Jon Steinhart's (jon@fourwinds.com) Attachment Handling Mods
9 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10
11 A bunch of changes have been made to improve the nmh user interface for
12 handling MIME attachments. This document provides the background and
13 implementation details of this so-called attach feature.
14
15 The user documentation for the attach feature is in the nmh send(1)
16 and whatnow(1) man pages.
17
18 Why Did I Do This?
19 ~~~~~~~~~~~~~~~~~~
20
21 Although nmh contains the necessary functionality for MIME message handing,
22 the interface to this functionality is pretty obtuse. There's no way that
23 I'm ever going to convince my partner to write mhbuild composition files!
24 And even though I know how to write them, I often screw up when sending a
25 message that contains a shell script because I forget that I have to double
26 any # at the start of a line, which shell scripts have galore.
27
28 These changes simplify the task of managing attachments on draft files.
29 They allow attachments to be added, listed, and deleted. MIME messages are
30 automatically created when drafts with attachments are sent.
31
32 The Simple Setup
33 ~~~~~~~~~~~~~~~~
34
35 Starting with nmh version 1.5, no setup is necessary.
36
37 ======================================================================
38 Through nmh 1.4, and optionally with nmh 1.5 and beyond, here's how to
39 set things up.
40
41 This only works if you're using the "standard" interface, i.e.,
42 whatnow. Life is more complicated if you run mh-e.
43
44 Add the following to your .mh_profile:
45
46 send: -attach Nmh-Attachment
47 whatnow: -attach Nmh-Attachment
48
49 You may already have send and whatnow lines in your .mh_profile; if
50 you do, just add the new stuff to the end of the line. For example,
51 mine looks like:
52
53 send: -alias aliases -attach Nmh-Attachment
54 whatnow: -attach Nmh-Attachment
55
56 That's it. Next time you want to send an attachment, say "attach
57 filename" at the whatnow prompt and you're done. You can check your
58 attachments by saying "alist".
59 ======================================================================
60
61 Did I Do This Correctly?
62 ~~~~~~~~~~~~~~~~~~~~~~~~
63
64 Hard to say. Despite lots of time looking at the nmh code, I can't say that
65 I get the philosophy behind its structure.
66
67 I am aware of two deviations from what I saw in the nmh code.
68
69 1. I commented my changes.
70
71 2. It's been years since I've used a VT-100, so I don't try to make code
72 fit into 80 columns anymore. Seems silly to me. (Some of us might
73 disagree. :-)
74
75 What Did I Do?
76 ~~~~~~~~~~~~~~
77
78 I made changes to the following files:
79
80 h/
81 prototypes.h
82 man/
83 anno.man
84 send.man
85 whatnow.man
86 uip/
87 Makefile.in
88 anno.c
89 annosbr.c
90 send.c
91 sendsbr.c
92 viamail.c (needed change for new sendsbr argument)
93 whatnowsbr.c
94
95 Attachments are associated with messages using header fields. For example, a
96 draft that looks like this
97
98 To: jon
99 Subject: test of attachments
100 Nmh-Attachment: /export/home/jon/foo
101 Nmh-Attachment: /export/home/jon/bar
102 Nmh-Attachment: /export/home/jon/test/foo
103 --------
104
105 has the files "foo", "bar", and foo as attachments.
106
107 Although I use the header field name "Nmh-Attachment" to indicate
108 attachments, the implementation allows any header field name.
109 (Originally, Jon used X-MH-Attachment. We have globally changed that
110 to Nmh-Attachment to prevent contributing to the X- header field
111 namespace.)
112
113 The advantage of using header fields is that the list of attachments
114 travels with the draft so it remains valid across editing sessions.
115
116 Note that the header fields for attachments are removed from the message
117 before it is sent.
118
119 Since I was adding header fields to messages, it seemed sensible to use the
120 existing anno program to do this for me. This required several changes to
121 generalize anno:
122
123 o I added a -draft option that permits annotations (header fields) to
124 be added to the draft instead of a message sequence.
125
126 o I added a -delete option that allows annotations to be deleted.
127
128 o I added a -list option that allows annotations to be listed.
129
130 o I added a -number option that modifies the behavior of -delete and -list.
131
132 o I added a -append option so that annotations are appended to the headers
133 instead of the default prepend. Without this, attachments come out in
134 reverse order.
135
136 Using the modified anno, the example above could be created (assuming that the
137 draft exists) by
138
139 prompt% anno -draft -comp Nmh-Attachment -text /export/home/jon/foo -nodate -append
140 prompt% anno -draft -comp Nmh-Attachment -text /export/home/jon/bar -nodate -append
141 prompt% anno -draft -comp Nmh-Attachment -text /export/home/jon/test/foo -nodate -append
142
143 One can quite easily make an "attach" command using shell scripts,
144 aliases or functions. For example, here's a bash function that does
145 the job:
146
147 function attach() { for i in $*; do anno -append -nodate -draft -comp Nmh-Attachment -text "$i"; done; }
148
149 The following examples show the different ways in which attachments can be
150 listed.
151
152 prompt% anno -list -draft -comp Nmh-Attachment
153 foo
154 bar
155 foo
156
157 prompt% anno -list -draft -comp Nmh-Attachment -text /
158 /export/home/jon/foo
159 v /export/home/jon/bar
160 /export/home/jon/test/foo
161
162 prompt% anno -list -draft -comp Nmh-Attachment -number
163 1 foo
164 2 bar
165 3 foo
166
167 prompt% anno -list -draft -comp Nmh-Attachment -text / -number
168 1 /export/home/jon/foo
169 2 /export/home/jon/bar
170 3 /export/home/jon/test/foo
171
172 prompt%
173
174 Why all these listing options?
175
176 I feel that the listing as produced by the first example is what most people
177 would want most of the time.
178
179 The listing as produced by the second example seemed necessary for situations
180 where there were several attachments with the same file name in different
181 directories.
182
183 I included the numbering option so that attachments could be deleted by number
184 which might be easier in situations where there were several attachments with
185 the same file name in different directories, as in the above example.
186
187 Attachments are deleted using the -delete option.
188
189 prompt% anno -delete -draft -comp Nmh-Attachment -text foo
190
191 deletes the first attachment since the foo matches the basename of the
192 attachment name.
193
194 prompt% anno -delete -draft -comp Nmh-Attachment -text /export/home/jon/test/foo
195
196 deletes the third attachment since the text is a full path name and matches.
197
198 prompt% anno -delete -draft -comp Nmh-Attachment -number 2
199
200 deletes the second attachment.
201
202 The attachment annotations are converted to a MIME message by send. I'm not
203 completely sure that this is the right place to do it, as opposed to doing
204 it in post, but both would work. It seemed to me to make more sense to do
205 it in send so that all of the various post options would apply to the MIME
206 message instead of the original draft file.
207
208 I added an -attach option to send that specifies the header field name used
209 for attachments. Send performs the following additional steps if this option
210 is set:
211
212 o It scans the header of the draft for attachments. Normal behavior applies
213 if none exist.
214
215 o A temporary mhbuild composition file is created if there are attachments.
216
217 o All non-attachment headers are copied from the draft file to the
218 composition file.
219
220 o The body of the draft is copied to a temporary body file if it contains at
221 least one non-whitespace character. A mhbuild directive for this file is
222 appended to the composition file. Note that this eliminates the problem
223 of lines beginning with the # character in the message body.
224
225 o A mhbuild directive is appended to the composition file for each attachment
226 header.
227
228 o mhbuild is run on the composition file, converting it to a MIME message.
229
230 o The converted composition file is substituted for the original draft file
231 and run through the rest of send.
232
233 o The original draft file is renamed instead of the converted composition
234 file. This preserves the original message instead of the composition file
235 which is really what a user would want.
236
237 o The ,file.orig file created by mhbuild is removed as it's a nuisance.
238
239 The mhbuild directives appended to the composition file are constructed as
240 follows:
241
242 o The content-type a file with a dot-suffix is obtained from the list of
243 mhshow-suffix- entries in the profile.
244
245 o A file with no dot-suffix or no entry in the profile is assigned a
246 content-type of application/octet-stream if it contains any non-ASCII
247 characters.
248
249 o A file with no dot-suffix or no entry in the profile is assigned a
250 content-type of text/plain if it contains only ASCII characters.
251
252 o The directive is of the form:
253
254 #content-type; name="basename"; x-unix-mode=mode [ description ] filename
255
256 The content type is derived as discussed above. The basename is the
257 last component of the pathname given in the body of the attachment header
258 field. The mode is file permissions. The description is obtained by
259 running the file command on the attachment file. The filename is the
260 field body from the attachment header field.
261
262 I added an -attach option to whatnow that specifies the header field
263 name for attachments.
264
265 I added to the commands available at the whatnow prompt to provide an
266 interface to the attachment mechanism.
267
268 I'm not completely happy with some of these additions because they
269 duplicate shell functionality. I'm not sure that there's a good way
270 around it other than to not use whatnow.
271
272 The first three additions (the ones I'm not happy with) are cd, ls,
273 and pwd. These do the same thing as their system counterparts. As a
274 matter of fact, these are implemented by running the commands in a
275 subshell. I did this because I wanted proper interpretation of
276 shell-specific things like ~ and wildcard expansion.
277
278 The next command is attach. This takes a list of files and adds them
279 to the draft as attachments using the same code as the modified anno.
280 The list of files is run through ls using the user's shell, so
281 wildcard expansion and all that works.
282
283 The alist command lists the attachments on the current draft using
284 listing function that I added to anno. It takes two optional options,
285 -l for a long listing meaning full path names, and -n for a numbered
286 listing.
287
288 The detach command removes attachments from the current draft, again
289 using the modified anno. The arguments are interpreted as numbers if
290 the -n option is used, otherwise they're interpreted as file names.
291 File names are shoveled through ls using the user's shell in the
292 directory containing the file for wildcard expansion and such. File
293 names are matched against the last pathname component unless they
294 begin with a / in which case they're matched against the entire name.
295
296 What's Left To Do?
297 ~~~~~~~~~~~~~~~~~~
298
299 Nothing on this stuff. When I get time I'd like to improve the interface
300 for reading messages with attachments. It's my opinion that, because of the
301 command line nature of nmh, it makes the most sense to treat attachments as
302 separate messages. In other words one should be able to read the next
303 attachment using next, and the previous one using prev. One should be able
304 to show and scan attachments. This would probably involve a major change
305 in the message numbering scheme to allow something like 123.4 to indicate
306 attachment 4 on message 123.
307
308 Jon Steinhart