File: README-ATTACHMENTS

package info (click to toggle)
nmh 1.8-4
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 7,860 kB
  • sloc: ansic: 50,445; sh: 22,697; makefile: 1,138; lex: 740; perl: 509; yacc: 265
file content (308 lines) | stat: -rw-r--r-- 11,604 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
This document describes the previous attach interface.  The attach
interface has changes for nmh 1.6 and later.  The interface is
documented in send(1), whatnow(1), and mhbuild(1).  No configuration
is required, and the same commands exist in whatnow; the two main
differences are that the header is now named "Attach", and mhbuild takes
care of the actual header processing.

Jon Steinhart's (jon@fourwinds.com) Attachment Handling Mods
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

A bunch of changes have been made to improve the nmh user interface for
handling MIME attachments.  This document provides the background and
implementation details of this so-called attach feature.

The user documentation for the attach feature is in the nmh send(1)
and whatnow(1) man pages.  

Why Did I Do This?
~~~~~~~~~~~~~~~~~~

Although nmh contains the necessary functionality for MIME message handing,
the interface to this functionality is pretty obtuse.  There's no way that
I'm ever going to convince my partner to write mhbuild composition files!
And even though I know how to write them, I often screw up when sending a
message that contains a shell script because I forget that I have to double
any # at the start of a line, which shell scripts have galore.

These changes simplify the task of managing attachments on draft files.
They allow attachments to be added, listed, and deleted.  MIME messages are
automatically created when drafts with attachments are sent.

The Simple Setup
~~~~~~~~~~~~~~~~

Starting with nmh version 1.5, no setup is necessary.

======================================================================
Through nmh 1.4, and optionally with nmh 1.5 and beyond, here's how to
set things up.

This only works if you're using the "standard" interface, i.e.,
whatnow.  Life is more complicated if you run mh-e.

Add the following to your .mh_profile:

	send: -attach Nmh-Attachment
	whatnow: -attach Nmh-Attachment

You may already have send and whatnow lines in your .mh_profile; if
you do, just add the new stuff to the end of the line.  For example,
mine looks like:

	send: -alias aliases -attach Nmh-Attachment
	whatnow: -attach Nmh-Attachment

That's it.  Next time you want to send an attachment, say "attach
filename" at the whatnow prompt and you're done.  You can check your
attachments by saying "alist".
======================================================================

Did I Do This Correctly?
~~~~~~~~~~~~~~~~~~~~~~~~

Hard to say.  Despite lots of time looking at the nmh code, I can't say that
I get the philosophy behind its structure.

I am aware of two deviations from what I saw in the nmh code.

 1.  I commented my changes.

 2.  It's been years since I've used a VT-100, so I don't try to make code
     fit into 80 columns anymore.  Seems silly to me.  (Some of us might
     disagree. :-)

What Did I Do?
~~~~~~~~~~~~~~

I made changes to the following files:

	h/
		prototypes.h
	man/
		anno.man
		send.man
		whatnow.man
	uip/
		Makefile.in
		anno.c
		annosbr.c
		send.c
		sendsbr.c
		viamail.c	(needed change for new sendsbr argument)
		whatnowsbr.c

Attachments are associated with messages using header fields.  For example, a
draft that looks like this

	To: jon
	Subject: test of attachments
	Nmh-Attachment: /export/home/jon/foo
	Nmh-Attachment: /export/home/jon/bar
	Nmh-Attachment: /export/home/jon/test/foo
	--------

has the files "foo", "bar", and foo as attachments.

Although I use the header field name "Nmh-Attachment" to indicate
attachments, the implementation allows any header field name.
(Originally, Jon used X-MH-Attachment.  We have globally changed that
to Nmh-Attachment to prevent contributing to the X- header field
namespace.)

The advantage of using header fields is that the list of attachments
travels with the draft so it remains valid across editing sessions.

Note that the header fields for attachments are removed from the message
before it is sent.

Since I was adding header fields to messages, it seemed sensible to use the
existing anno program to do this for me.  This required several changes to
generalize anno:

 o  I added a -draft option that permits annotations (header fields) to
    be added to the draft instead of a message sequence.

 o  I added a -delete option that allows annotations to be deleted.

 o  I added a -list option that allows annotations to be listed.

 o  I added a -number option that modifies the behavior of -delete and -list.

 o  I added a -append option so that annotations are appended to the headers
    instead of the default prepend.  Without this, attachments come out in
    reverse order.

Using the modified anno, the example above could be created (assuming that the
draft exists) by

	prompt% anno -draft -comp Nmh-Attachment -text /export/home/jon/foo -nodate -append
	prompt% anno -draft -comp Nmh-Attachment -text /export/home/jon/bar -nodate -append
	prompt% anno -draft -comp Nmh-Attachment -text /export/home/jon/test/foo -nodate -append

One can quite easily make an "attach" command using shell scripts,
aliases or functions.  For example, here's a bash function that does
the job:

	function attach() { for i in $*; do anno -append -nodate -draft -comp Nmh-Attachment -text "$i"; done; }

The following examples show the different ways in which attachments can be
listed.

	prompt% anno -list -draft -comp Nmh-Attachment
	foo
	bar
	foo

	prompt% anno -list -draft -comp Nmh-Attachment -text /
	/export/home/jon/foo
	/export/home/jon/bar
	/export/home/jon/test/foo

	prompt% anno -list -draft -comp Nmh-Attachment -number
	1	foo
	2	bar
	3	foo

	prompt% anno -list -draft -comp Nmh-Attachment -text / -number
	1	/export/home/jon/foo
	2	/export/home/jon/bar
	3	/export/home/jon/test/foo

	prompt%

Why all these listing options?

I feel that the listing as produced by the first example is what most people
would want most of the time.

The listing as produced by the second example seemed necessary for situations
where there were several attachments with the same file name in different
directories.

I included the numbering option so that attachments could be deleted by number
which might be easier in situations where there were several attachments with
the same file name in different directories, as in the above example.

Attachments are deleted using the -delete option.

	prompt% anno -delete -draft -comp Nmh-Attachment -text foo

deletes the first attachment since the foo matches the basename of the
attachment name.

	prompt% anno -delete -draft -comp Nmh-Attachment -text /export/home/jon/test/foo

deletes the third attachment since the text is a full path name and matches.

	prompt% anno -delete -draft -comp Nmh-Attachment -number 2

deletes the second attachment.

The attachment annotations are converted to a MIME message by send.  I'm not
completely sure that this is the right place to do it, as opposed to doing
it in post, but both would work.  It seemed to me to make more sense to do
it in send so that all of the various post options would apply to the MIME
message instead of the original draft file.

I added an -attach option to send that specifies the header field name used
for attachments.  Send performs the following additional steps if this option
is set:

 o  It scans the header of the draft for attachments.  Normal behavior applies
    if none exist.

 o  A temporary mhbuild composition file is created if there are attachments.

 o  All non-attachment headers are copied from the draft file to the
    composition file.

 o  The body of the draft is copied to a temporary body file if it contains at
    least one non-whitespace character.  A mhbuild directive for this file is
    appended to the composition file.  Note that this eliminates the problem
    of lines beginning with the # character in the message body.

 o  A mhbuild directive is appended to the composition file for each attachment
    header.

 o  mhbuild is run on the composition file, converting it to a MIME message.

 o  The converted composition file is substituted for the original draft file
    and run through the rest of send.

 o  The original draft file is renamed instead of the converted composition
    file.  This preserves the original message instead of the composition file
    which is really what a user would want.

 o  The ,file.orig file created by mhbuild is removed as it's a nuisance.

The mhbuild directives appended to the composition file are constructed as
follows:

 o  The content-type a file with a dot-suffix is obtained from the list of
    mhshow-suffix- entries in the profile.

 o  A file with no dot-suffix or no entry in the profile is assigned a
    content-type of application/octet-stream if it contains any non-ASCII
    characters.

 o  A file with no dot-suffix or no entry in the profile is assigned a
    content-type of text/plain if it contains only ASCII characters.

 o  The directive is of the form:

	#content-type; name="basename"; x-unix-mode=mode [ description ] filename

    The content type is derived as discussed above.  The basename is the
    last component of the pathname given in the body of the attachment header
    field.  The mode is file permissions.  The description is obtained by
    running the file command on the attachment file.  The filename is the
    field body from the attachment header field.

I added an -attach option to whatnow that specifies the header field
name for attachments.

I added to the commands available at the whatnow prompt to provide an
interface to the attachment mechanism.

I'm not completely happy with some of these additions because they
duplicate shell functionality.  I'm not sure that there's a good way
around it other than to not use whatnow.

The first three additions (the ones I'm not happy with) are cd, ls,
and pwd.  These do the same thing as their system counterparts.  As a
matter of fact, these are implemented by running the commands in a
subshell.  I did this because I wanted proper interpretation of
shell-specific things like ~ and wildcard expansion.

The next command is attach.  This takes a list of files and adds them
to the draft as attachments using the same code as the modified anno.
The list of files is run through ls using the user's shell, so
wildcard expansion and all that works.

The alist command lists the attachments on the current draft using
listing function that I added to anno.  It takes two optional options,
-l for a long listing meaning full path names, and -n for a numbered
listing.

The detach command removes attachments from the current draft, again
using the modified anno.  The arguments are interpreted as numbers if
the -n option is used, otherwise they're interpreted as file names.
File names are shoveled through ls using the user's shell in the
directory containing the file for wildcard expansion and such.  File
names are matched against the last pathname component unless they
begin with a / in which case they're matched against the entire name.

What's Left To Do?
~~~~~~~~~~~~~~~~~~

Nothing on this stuff.  When I get time I'd like to improve the interface
for reading messages with attachments.  It's my opinion that, because of the
command line nature of nmh, it makes the most sense to treat attachments as
separate messages.  In other words one should be able to read the next
attachment using next, and the previous one using prev.  One should be able
to show and scan attachments.  This would probably involve a major change
in the message numbering scheme to allow something like 123.4 to indicate
attachment 4 on message 123.

	Jon Steinhart