1.nr DR 1
2.nr si 4n
3.he 'SENDMAIL''%'
4.if \n(DR .fo 'For Your Eyes Only'\*-DRAFT\*-'\*(td'
5.ls 2
6.+c
7.(l C
8.sz 12
9SENDMAIL \*- An Internet Mail Router
10.sz
11.sp
12Eric Allman
13.i
14Project INGRES
15Electronics Research Lab
16University of California
17Berkeley, California  94720
18.)l
19.(f
20This is
21.if \n(DR draft
22version 3.2,
23last modified on 08/27/81.
24.if \n(DR Please do not distribute this version without permission
25.if \n(DR of the author.
26.)f
27.sp 2
28.pp
29.i Sendmail
30implements a general internetwork mail routing facility.
31Features include aliasing and forwarding,
32automatic routing to network gateways,
33and flexible configuration.
34.pp
35Section 1 discusses the design goals for
36.i sendmail .
37Section 2 gives an overview of the basic functions of the system.
38In section 3,
39details of usage are discussed.
40A detailed description of the configuration file
41is given in section 4,
42including a walkthrough of a specific configuration file.
43Section 5 compares
44.i sendmail
45to other internet mail routers,
46and an evaluation of
47.i sendmail
48is given in section 6,
49including future plans.
50.sh 1 "DESIGN GOALS"
51.pp
52.i Sendmail
53was an outgrowth of
54.i delivermail,
55a previous incarnation of a UNIX internetwork mail router.
56.i Delivermail
57was written relatively quickly.
58The first version only knew about taking apart addresses
59for explicit forwarding
60and limited aliasing;
61automatic forwarding and other features
62came later.
63.pp
64Design goals for
65.i delivermail
66included:
67.np
68Compatibility with the existing mail system,
69including Bell version 6 mail,
70Bell version 7 mail,
71Berkeley mail,
72BerkNet mail
73[BerkNet],
74.(d
75[BerkNet]
76.)d
77and hopefully UUCP mail
78[UUCP].
79.(d
80[UUCP]
81.)d
82ARPANET mail
83[ARPANET]
84.(d
85[ARPANET]
86.)d
87was also required,
88and the difference in format
89influenced the decision to put all such formatting
90into the low-level mailer.
91.np
92Because of time constraints,
93utilize as much existing software as possible.
94The changes to the existing software were minimal:
95Berkeley mail,
96BerkNet,
97UUCP, and the ARPANET FTP server
98had to be modified to call
99.i delivermail
100as their server instead of
101/bin/mail
102(or in the case of the ARPANET,
103instead of
104writing the mail into a file
105which has no meaning to standard UNIX mailers).
106The only major modifications
107were to /bin/mail,
108which was maintained both as a user interface sender
109and as a
110.i delivermail
111mailer.
112As a sender,
113it calls
114.i delivermail .
115.i Delivermail
116calls it in turn to do local delivery,
117so a
118.b \-d
119flag was added to avoid loops.
120.np
121Reliability was considered essential
122because of the emphasis on mail in our environment.
123This turned out to be one of the hardest goals to satisfy,
124especially in the face of the many anomalous message formats
125produced by various ARPANET sites.
126For example,
127MIT and CMU allow mail from people who are not logged in
128(and which have meaningless from addresses),
129which caused error message loops.
130CMU also puts blanks in names,
131which created amazing problems,
132since many UNIX mail programs assume that an address
133is one word.
134And at least one person lists his address as
135.q "From: the TTY of ..." ,
136giving a
137.q Sender:
138field with his real address.
139In summary,
140the obscure aspects of the ARPANET mail protocol
141really are used and
142are difficult to support,
143but must be supported.
144But even obeying the standard is insufficient.
145For example,
146WHARTON changes our host name from
147.q BERKELEY
148to
149.q BERKEL- ,
150which confused error processing.
151Degenerate cases such as this
152must be handled gracefully.
153.pp
154There were certain non-goals in
155.i delivermail
156also.
157Many of these resulted from the expectation that
158it would only be used at Berkeley,
159and probably only at a few sites at Berkeley.
160.np
161It was fair game to compile configuration information
162into the code,
163even to assume that they were running BerkNet.
164.np
165The problem of multiple connections to a single network
166was not foreseen.
167For example,
168on a host with no UUCP connection,
169all UUCP mail was sent to a single host.
170In fact,
171Berkeley is running UUCP on at least three hosts.
172.np
173No attempt was made to reduce the volume of mail across a network link.
174Besides the difficulty of doing this,
175we failed to appreciate how much volume there would be.
176.pp
177.i Sendmail
178maintained the goals of
179.i delivermail.
180Time was less of a constraint,
181but not reimplementing basic mailers
182has proven to be a wise move in many ways.
183For example,
184many internet mailers deliver local mail directly.
185This is more efficient,
186but builds in the design decisions
187of the local mailer,
188and makes it difficult to concentrate
189on the
190.q "real problems"
191(such as locking).
192Other design goals were:
193.np
194.i Sendmail
195should operate in more complex environments,
196including multiple
197connections to a single network type
198(such as with multiple UUCP or Ether nets),
199requiring that the contents of a host field
200be considered,
201as well as just the syntax of an address,
202in order to determine the gateway to use.
203This results both from a desire to simplify use by other sites,
204and to anticipate the environment Berkeley is moving towards.
205.np
206Configuration should not be compiled into the code.
207A single binary should be able to run as is at any site
208(modulo such basic changes as the CPU type or the operating system).
209We have found this seemingly unimportant goal
210to be critical in real life.
211Besides the simple problems that occur when any program gets recompiled
212in a different environment,
213many sites like to
214.q fiddle
215with anything that they will be recompiling anyway.
216.np
217.i Delivermail
218only knows about one alias file.
219Berkeley is a sufficiently open environment
220that this can be writable by everyone,
221but other environments are not so lax.
222Thus,
223.i sendmail
224must be able to let various groups maintain their own mailing lists,
225and individuals their own forwarding,
226without writing the system alias file.
227.np
228Customized incoming mailers should be supported.
229This allows users who are using specialized mailers
230that want to use a different format to build their environment
231without changing the system,
232and allows specialized functions
233(such as returning an
234.q "I am on vacation"
235message).
236.np
237Network traffic should be minimized
238by batching addresses to a single host where possible,
239without assistance by the user.
240.sh 1 "OVERVIEW"
241.sh 2 "System Organization"
242.pp
243.i Sendmail
244neither interfaces with the user
245nor does actual mail delivery.
246Rather,
247it collects a message
248generated by a user interface program (UIP)
249[MPM],
250.(d
251[MPM]
252.)d
253does editing as required by the destination network,
254and calls appropriate mailers
255to do mail delivery or queueing for network transmission
256(the exception is when mailing to a file).
257This discipline allows the insertion of new mailers
258at minimum cost.
259In this sense it is like the Message Processing Module (MPM)
260of [1].
261.(d
262[1] Postel -- internet message structure
263.)d
264See Figure 1.
265.(z
266.hl
267.(c
268	       +-------+
269	       | user  |
270	       +-------+
271		   |
272	        +-----+
273	        | UIP |
274	        +-----+
275		   |
276             +-----------+
277             | sendmail  |
278             +-----------+
279		|  |  |
280     +----------+  +  +----------+
281     |  	   |             |
282+---------+   +---------+   +---------+
283| mailer1 |   | mailer2 |   | mailer3 |
284+---------+   +---------+   +---------+
285.)c
286
287.ce
288Figure 1 \*- System Structure.
289.hl
290.)z
291.sh 2 "Operational Description"
292.sh 3 "Argument processing and address parsing"
293.pp
294The arguments are first scanned,
295and flag arguments are processed.
296The remaining arguments are addresses.
297They are parsed in turn,
298and a list of recipients is created.
299Aliasing is done at this step.
300As much validity checking of the addresses as possible
301is done at this step.
302Syntax is checked, and local addresses can be verified,
303but detailed checking of host names and addresses
304is not checked until later.
305Forwarding is also done
306as the local addresses are verified.
307.pp
308As each address is parsed,
309it is appended to the recipient list.
310When a name is aliased or forwarded,
311the old name is not removed from the list,
312but a flag is set in the address header
313that tells the delivery phase
314to not actually deliver the message to this recipient.
315This list is kept without duplicates,
316preventing alias loops
317and eliminating people receiving two copies of a message,
318as might happen if a person were in two groups.
319.sh 3 "Message collection"
320.pp
321The message is then collected from the standard input.
322Parsing of the message header is done at this point.
323The header is stored in memory,
324and the body of the message is saved
325in a temporary file.
326.pp
327Collection occurs even if no addresses were valid
328to simplify program interface.
329The message will be returned with an error.
330.sh 3 "Message delivery"
331.pp
332For each unique mailer and host,
333a call is made to the mailer.
334Each call contains the users on that host.
335Mailers that only accept one recipient at a time
336are handled properly.
337.pp
338.i Sendmail
339forks a process for each mailer
340with a non-empty send list.
341The message is then sent to the mailer
342(which must read its standard input)
343prepended by a customized header.
344The exit code is caught and checked,
345and a suitable error message given as appropriate.
346The exit code must conform to a system standard
347or a meaningless message
348(\c
349.q "Service unavailable" )
350is given.
351.pp
352Delivery to files is handled directly.
353.sh 3 "Return to sender"
354.pp
355If errors occurred during processing,
356the message is returned to the sender for retransmission.
357The letter can be mailed back
358or written in the file
359.q dead.letter
360in the sender's home directory\**.
361.(f
362\**Obviously, if the site giving the error is not the originating
363site, the only reasonable option is to mail back to the sender.
364Also, there are many more error disposition options,
365but they only effect the error message \*- the
366.q "return to sender"
367function is always handled in one of these two ways.
368.)f
369.sh 2 "Configuration File"
370.pp
371Almost all configuration information is read at runtime
372from an ASCII file.
373Information encoded in this file includes
374macro definitions,
375header declarations,
376mailer definitions,
377and address rewriting rules.
378.sh 3 Macros
379.pp
380Macros can be used in three ways.
381Certain macros transmit
382unstructured textual information
383into the mail system,
384such as the name
385.i sendmail
386will use to identify itself in error messages.
387Other macros transmit information from
388.i sendmail
389to the configuration file
390for use in creating other fields
391(such as argument vectors to mailers);
392examples of these are the name of the sender and the host and user
393of the recipient.
394Other macros are unused internally,
395and can be used as shorthand in the configuration file.
396.sh 3 "Header declarations"
397.pp
398Header declarations declare to
399.i sendmail
400the set of known header lines.
401Knowledge of a few header lines
402is built into
403.i sendmail ,
404such as the
405.q From:
406and
407.q Date:
408lines.
409.pp
410Most headers declared in the configuration file
411will be automatically inserted
412in the outgoing message
413if they don't exist in the incoming message.
414Certain headers are suppressed by some mailers.
415.sh 3 "Mailer declarations"
416.pp
417Mailer declarations tell
418.i sendmail
419of the various mailers available to it.
420The definition includes the internal name of the mailer,
421the pathname of the program to call,
422some flags associated with the mailer,
423and an argument vector to be used on the call;
424this vector is macro expanded before use.
425.sh 3 "Address rewriting rules"
426.pp
427The heart of address parsing in
428.i sendmail
429is the rewriting rules.
430These are an ordered list of pattern-replacement rules,
431somewhat like a production system,
432except that order is critical.
433Each address is applied successively to these rules
434being rewritten into a different (textual) form
435until it resolves into a canonical address
436(i.e.,
437a [mailer, host, user]
4383-tuple),
439or it falls off the end.
440When a pattern matches,
441the rule is reapplied until it fails.
442.sh 2 "Message Header Editing"
443.pp
444Certain editing of the message header
445occurs automatically.
446Header lines can be inserted
447under control of the configuration file.
448Some lines can be merged;
449for example,
450a
451.q From:
452line and a
453.q Full-name:
454line can be merged under certain circumstances.
455.sh 1 "USAGE AND IMPLEMENTATION"
456.sh 2 "Arguments"
457.pp
458Arguments must be presented with flags before addresses.
459The flags are:
460.nr ii 1i
461.ip "\-f addr"
462The mail is from
463.i addr .
464This flag is ignored unless the real user
465is root,
466network,
467or uucp,
468or if
469.i addr
470contains an exclamation point
471(because of certain restrictions in UUCP).
472.ip "\-r addr"
473An obsolete form of
474.b \-f .
475.ip "\-h cnt"
476Sets the
477.q "hop count"
478to
479.i cnt .
480This represents the number of times this message has been processed
481by
482.i sendmail
483(to the extent that it is supported by the underlying networks).
484.i Cnt
485is incremented during processing,
486and if it reaches
487MAXHOP
488(currently 30)
489.i sendmail
490throws away the message with an error.
491.ip "\-F\&name"
492Sets the full name of this user to
493.i name .
494.ip \-e\&p
495Print error messages (default).
496.ip \-e\&q
497Throw away error messages.
498The only response is the exit status.
499.ip \-e\&m
500Mail back errors.
501.ip \-e\&w
502.q Write
503back errors \*- or mail them if the user is not logged in.
504.ip \-e\&e
505Do special error processing for BerkNet.
506This involves mailing back the errors
507but always returning a zero exit status.
508.ip \-n
509Don't do aliasing or forwarding.
510.ip \-m
511Include me in alias expansions.
512Normally
513.i sendmail
514suppresses the sender
515if in a group being sent to.
516.ip \-i
517Don't take a dot to end a message.
518.ip \-t
519Read the header for
520.q To: ,
521.q Cc: ,
522and
523.q Bcc:
524lines, and send to everyone listed in those lists.
525The
526.q Bcc:
527line will be deleted before sending.
528Any addresses in the argument vector will be deleted
529from the send list.
530.ip \-a\&m
531Do special processing for the
532ARPANET.
533This includes taking the
534.q "From:"
535person from the header,
536printing
537ARPANET
538style messages
539(preceded by three digit reply codes for compatibility with
540the FTP protocol
541[FTP1, FTP2]),
542.(d
543[FTP1] -- ftp protocol
544.)d
545.(d
546[FTP2] -- revised FTP reply codes
547.)d
548and ending lines with <CRLF>.
549.ip \-a\&f
550Same as
551.b \-a\&m ,
552except print out message numbers appropriate for the MLFL command
553[MLFL].
554.(d
555[MLFL] -- RFC733
556.)d
557.ip \-s
558Save UNIX-style
559.q From
560lines at the beginning of headers.
561Normally they are assumed redundant
562and discarded.
563.ip \-v
564Give a blow-by-blow description of function.
565This gives information of interest to the user
566rather than for the
567.i sendmail
568maintainer;
569for example,
570aliases are printed as expanded
571and mailer functions are printed as they run.
572.ip \-C\&file
573Use a different configuration file.
574.ip \-A\&file
575Use a different alias file.
576.ip \-I
577Initialize the DBM version
578of the alias file.
579If
580.b \-I
581is given,
582no delivery is attempted.
583.ip \-V
584Verify the addresses only.
585Only partial verification is done:
586syntax is checked, and local names are verified,
587but no checking normally done by the mailer is attempted.
588.ip \-d\&level
589Set debugging level.
590.ip \-D\&x\&val
591Define macro
592.i x
593to have value
594.i val .
595.nr ii 5n
596.pp
597Following flag arguments,
598address arguments may be given.
599These follow the syntax in RFC733
600[7]
601.(d
602[7] RFC733
603.)d
604for ARPANET
605address formats.
606In brief, the format is:
607.np
608Anything in parentheses is thrown away
609(as a comment).
610.np
611Anything in angle brackets (\ <>\ ) is preferred
612over anything else.
613.np
614Double quotes
615(\ "\ )
616quote phrases;
617backslashes quote characters.
618Backslashes are more powerful \*- for example,
619.i user
620and
621.i
622"user"
623.r
624are equivalent,
625but
626.i \euser
627is different from either of them.
628.pp
629All other processing is controlled by the rewriting rules
630(disclaimer: some special processing is done
631after rewriting local names).
632Parentheses, angle brackets, and double quotes
633must be properly balanced and nested.
634.sh 2 "Aliasing, Forwarding, Inclusion"
635.pp
636.i Sendmail
637supports three methods for implicitly rerouting mail.
638Aliasing applies system wide.
639Forwarding allows each user to reroute incoming mail
640destined for that account.
641Inclusion directs
642.i sendmail
643to read a file for a list of addresses,
644and would normal be used
645in conjunction with aliasing.
646.sh 3 "Aliasing"
647.pp
648Aliasing uses a system-wide file
649mapping names to address lists.
650This file is inverted to speed access.
651Only names that appear to be local
652are allowed as aliases;
653this guarantees a unique key.
654.pp
655The inverted form of the file
656must be recreated when the text copy is changed.
657The
658.b \-I
659option to
660.i sendmail
661rebuilds the database\**.
662.(f
663\**This could be done automatically if
664.i sendmail
665could be guaranteed to be running as the owner of the
666alias file.
667In some environments this is not the case.
668.)f
669.sh 3 "Forwarding"
670.pp
671After aliasing,
672users that are found to be local and valid
673are checked for the existence of a
674.q .forward
675file in their home directory.
676If it exists,
677the message is
678.i not
679sent to that user,
680but rather to the list of users in that file.
681The expectation is that this will normally
682be one user only,
683and the use will be for network mail forwarding.
684.pp
685Forwarding also permits a user to specify a private incoming mailer.
686For example,
687forwarding to:
688.(b
689"\^|\|/usr/local/newmail myname"
690.)b
691will use a different incoming mailer.
692.sh 3 "Inclusion"
693.pp
694Inclusion is specified in ARPANET syntax:
695.(b
696:Include: pathname
697.)b
698An address of this form reads the file specified by
699.i pathname
700and sends to all users listed in that file.
701.pp
702The intent is
703.i not
704to support direct use of this feature,
705but rather to use this as a subset of aliasing.
706For example,
707an alias of the form:
708.(b
709project: :include:/usr/project/userlist
710.)b
711is a method of letting a project maintain a mailing list
712without interaction with the system administration,
713even if the alias file is protected.
714.pp
715It is not necessary to rebuild the alias database
716when a :include: list is changed.
717.sh 2 "Exit Status"
718.pp
719An exit status is returned that corresponds to the system standard
720used by the other mailers.
721.sh 2 "Interaction With Other Mailers"
722.pp
723Two examples of how network-specific work is passed to other programs
724are the incoming UUCP mailer
725(\c
726.i rmail )
727and the outgoing ARPANET mailer.
728.sh 3 "Incoming UUCP mail"
729.pp
730Mail coming in from the UUCP network
731is not guaranteed to have a normal header line,
732nor will at argument be passed telling who it is from\**.
733.(f
734\**As a result of this,
735it is impossible to verify UUCP sender addresses.
736.)f
737Fortuitously,
738UUCP mail calls the program
739.i rmail
740rather than
741.i mail
742or
743.i sendmail .
744The
745.i rmail
746program has been modified here to do the special-purpose parsing
747necessary to decode UUCP headers
748and turn them into a normal UUCP address;
749this address is then passed to
750.i sendmail
751via a
752.b \-f
753flag.
754.sh 3 "Outgoing ARPANET mail"
755.pp
756The ARPANET imposes many standards that
757.i sendmail
758does not care to enforce.
759For example,
760an arpanet sitename must be on
761.i every
762address,
763not just the
764.q "From:"
765address.
766Certain UNIX sites like to use
767.q %
768as an alternative to
769.q @ ,
770which must be translated.
771The outgoing ARPANET mailer makes these tranformations
772before passing the message to the network.
773.sh 1 CONFIGURATION
774.pp
775Configuration is controlled primarily by the file
776/usr/lib/sendmail.cf.
777.i Sendmail
778should not need to be recomplied except
779.np
780To change operating systems
781(V6, V7/32V, 4BSD).
782.np
783To remove or insert the DBM library.
784.np
785To change ARPANET reply codes.
786.np
787To add headers requiring special processing.
788.lp
789Adding mailers or changing parsing or routing information
790does not require recompilation.
791.pp
792If the mail is being sent by a local user,
793and the file
794.q .mailcf
795exists in the sender's home directory,
796that file is read as a configuration file
797after the system configuration file.
798The primary use of this is to add header lines.
799.sh 2 "Configuration File Description"
800.pp
801The configuration file is formatted
802as a series of text lines,
803each beginning with a character describing its semantics.
804Blank lines and lines beginning with a sharp sign
805(#)
806are ignored.
807Other lines are:
808.(b
809D	define macro
810H	define header
811M	define mailer
812S	use rewriting set
813C	define word class
814R	specify rewriting rule
815.)b
816.pp
817See figure 2 for an example configuration file.
818.(z
819.hl
820.sp
821.sz -2
822##########################################
823# sendmail configuration file
824#	@(#)sendmail.cf	3.6	8/17/81
825##########################################
826
827### local hosts on various nets
828DABerkeley
829DBIngVAX
830DUucbvax
831
832### special macros
833# my name
834D\&n\&MAILER-DAEMON
835# UNIX header format
836D\&l\&From $g  $d
837# delimiter (operator) characters
838D\&o\&.:@!^
839
840### format of headers:
841H\&Date: $a
842H\&From: $g$?x ($x)$.
843H\&Full-Name: $x
844H\&Message-Id: <$t.$p.$B@$A>
845H\&Posted-Date: $a
846
847### name classifications
848# arpanet hostnames
849C\&A\&ucb berkeley
850# list of local host names
851C\&B\&j IngVax
852# berknet hosts on the arpanet
853C\&C\&i ingres ing70
854# uucp hostnames
855C\&U\&ucbvax ernie
856
857###  mailers
858# local mail -- must be zero
859M\&local	/bin/mail		rlsAmn	$f	...local\&mail -d $u
860# program mail -- must be one
861M\&prog	/bin/csh		lA	$f	...prog\&mail -fc $u
862# berkeley net mail
863M\&berk	/usr/net/bin/sendberkmail fxs	$B:$f	...berk\&mail -m $h -h $c -t $u
864# arpanet mail
865M\&arpa	/usr/lib/mailers/arpa	sAu	$f@$A	...arpa\&mail $f $h $u
866# uucp mail
867M\&uucp	/usr/bin/uux		rsDxm	$U!$f	...uucp\&mail - $h!rmail ($u)
868
869### rewriting rules
870R\&$-h.$+u	$+h:$+u			change "." to ":"
871R\&$=C:$+u@$-h	$+u@$+h			delete ing70: on arpanet addresses
872R\&$+u@$=A	ing70:$+u		delete local arpa hosts
873R\&$+u@$-h	$#berk$@ing70$:$+u@$+h	send arpa mail to ing70
874R\&$+h^$+u	$+h!$+u			change "^" to "!"
875R\&$-x!$=U!$+y	csvax:$+y		delete uucp loops through csvax
876R\&$-h!$+u	csvax:$+h!$+u		send uucp mail to csvax
877R\&$-x:$-h:$+u	$+h:$+u			delete multiple berk hosts
878R\&$=B:$+u	$+u			delete local berk hosts
879R\&$-h:$+u	$#berk$@$+h$:$+u	resolve berk mail
880R\&$+u		$#local$:$+u		resolve local mail
881
882### rewriting rules for from host
883S\&1
884R\&ing70:$+u@$-h	$+u@$+h			arpanet mail is automatic
885R\&CSVAX:$-h!$+u	$+h!$+u			uucp mail is automatic
886
887
888.ce
889Figure 2.  Sample configuration file.
890.sp
891.hl
892.)z
893.sh 3 "D \*- define macro"
894.pp
895This line defines a macro.
896Macros have single character names.
897They can be interpolated using the escape
898.b $\c
899.i x ,
900where
901.i x
902is the macro name.
903By convention,
904all upper-case letters are unused by
905.i sendmail
906and may be used freely by the user;
907all other names are reserved for use by sendmail.
908Certain macros
909.i must
910be defined,
911and are used internally.
912These are:
913.(b
914$l	UNIX-style \*(lqFrom\*(rq line.
915$n	My address in error messages.
916$o	\*(lqOperators\*(rq in addresses.
917.)b
918The
919.b $l
920macro is expanded when
921.i sendmail
922wants to insert a UNIX-style
923.q From
924line on messages.
925This typically expands to something like:
926.(b
927From joe  Wed Aug 12 09:15:13 1981
928.)b
929The
930.b $n
931macro is used as the name of this process
932when error messages are being mailed back.
933Typically,
934it is wise to include an alias
935so that mail to this address will be sent to root.
936The
937.b $o
938macro defines the characters
939that will separate words when addresses are being broken up.
940Each of these becomes a word by itself when scanned.
941Blanks and tabs are built-in separators
942but are ignored,
943i.e., are not turned into words.
944For example, the input:
945.(b
946Ing70:ZRM @ MIT-MC SRI-KL
947.)b
948Is broken up into the six words:
949.(b
950Ing70, :, ZRM, @, MIT-MC, SRI-KL
951.)b
952assuming that colon and at-sign are operators
953(but hyphen is not).
954.pp
955A number of macros are defined by
956.i sendmail
957for use as primitives.
958These are:
959.(l
960$a	The date in ARPANET format.
961$c	The hop count.
962$d	The date in UNIX (ctime) format.
963$f	The sender's (from) address.
964$g	The sender's address translated by the mailer.
965$h	The host of the recipient.
966$p	The process id of sendmail in decimal.
967$t	The time in seconds in decimal.
968$u	The user part of the recipient.
969$v	The version number of sendmail.
970$x	The full name of the sender.
971$y	The id of the sender's terminal.
972$z	The home directory of the recipient.
973.)l
974.pp
975The
976.b $p
977and
978.b $t
979macros are used to create unique strings.
980The
981.b $f
982macro is the id of the sender
983as originally determined;
984when mailing to a specific person,
985the
986.b $g
987macro is the address of the sender
988with respect to the receiver.
989For example,
990if I send to
991.q csvax:samwise
992the
993.b $f
994and
995.b $g
996macros are:
997.(b
998$f	eric
999$g	IngVAX:eric
1000.)b
1001This only applies to the first step in the link.
1002For example,
1003sending to Ing70:drb@bbn-unix,
1004we have
1005.b $f
1006and
1007.b $g
1008as above for the transfer to Ing70, but:
1009.(b
1010$f	IngVAX:eric
1011$g	IngVAX:eric@Berkeley
1012.)b
1013for transfer to the ARPANET.
1014When sending, the
1015.b $u ,
1016.b $h ,
1017and
1018.b $z
1019macros get set to the user, host, and home directory
1020(respectively)
1021of the receiver.
1022The host is only set if the user is not local,
1023and the home directory is only set if the user is local.
1024.pp
1025A primitive conditional is available during macro expansion.
1026The construct:
1027.(b
1028$?x text1 $: text2 $.
1029.)b
1030tests if macro
1031.b $\c
1032.i x
1033is defined.
1034If it is,
1035text1 is interpolated;
1036otherwise,
1037text2 is interpolated.
1038.sh 3 "H \*- define header"
1039.pp
1040The remainder of the
1041.b H
1042line looks like a regular header line,
1043except that the field value is macro expanded
1044before use.
1045All headers mentioned in this way
1046are automatically inserted
1047into every message
1048except for headers mentioned in the compile-time
1049configuration file
1050.i conf.c .
1051These headers are
1052Date,
1053From,
1054Full-Name,
1055Message-Id,
1056and
1057Received-Date.
1058To get these fields the appropriate flag
1059must be specified
1060for the receiving mailer.
1061.pp
1062Since the file
1063.q ".mailcf"
1064in the sender's home directory is read and processed,
1065it is possible to add customized header lines.
1066For example,
1067the .mailcf consisting of:
1068.(b
1069H\&Phone: (415) 888-9990
1070.)b
1071will add that line to every outgoing message.
1072.sh 3 "M \*- define mailer"
1073.pp
1074This line is structured into fields
1075separated by white space (spaces or tabs).
1076The fields are:
1077.np
1078The internal name of the mailer,
1079referred to in the rewriting rules.
1080.np
1081The pathname of the program to execute for this mailer.
1082.np
1083The flags for this mailer,
1084described below.
1085.np
1086The macro string to become the
1087.b $g
1088macro (translated sender)
1089for this mailer.
1090.np
1091The argument vector passed to the mailer
1092(macro expanded).
1093.pp
1094The flags are a series of characters:
1095.ls 1
1096.ip f
1097The mailer wants a
1098.b \-f
1099.i from
1100flag,
1101but only if this is a network forward operation
1102(i.e.,
1103the mailer will give an error
1104if the executing user does not have special permissions).
1105.ip r
1106Same as
1107.b f ,
1108but sends a
1109.b \-r
1110flag.
1111.ip q
1112Don't print errors \*- the mailer will do it for us.
1113.ip S
1114Don't reset your userid before calling the mailer.
1115This would be used in a secure environment where
1116.i sendmail
1117ran as a special user.
1118This could be used to prevent
1119(or at least complicate)
1120forged addresses.
1121This option is supressed in
1122.q unsafe
1123configuration files
1124(i.e., user-supplied, either on a
1125.b \-C
1126option, or in the
1127.i \&.mailcf
1128file in the home directory).
1129.ip n
1130This mailer does not want a UNIX-style
1131.q From
1132line on the message.
1133.ip l
1134This mailer is local,
1135so no host will be specified.
1136.ip s
1137Strip quote characters off of addresses
1138before calling the mailer.
1139.ip m
1140This mailer can send to multiple users
1141(on the same host)
1142in one call.
1143.ip F
1144This mailer wants a
1145.q From:
1146header line.
1147.ip D
1148This mailer wants a
1149.q Date:
1150header line.
1151.ip M
1152This mailer wants a
1153.q Message-Id:
1154header line.
1155.ip x
1156This mailer wants a
1157.q Full-Name:
1158header line.
1159.ip u
1160Upper case should be preserved in user names.
1161.ip h
1162Upper case should be preserved in host names.
1163.ip A
1164This mailer wants an ARPANET standard header
1165(equivalent to the
1166.b F
1167and
1168.b D
1169flags).
1170.ls
1171.sh 3 "S \*- use rewriting set"
1172.pp
1173There are two sets of rewriting rules.
1174Set zero is used to rewrite recipient addresses.
1175Set one is used to rewrite sender addresses.
1176Set one can be used to eliminate implicit links.
1177For example,
1178if there exists a site on on the BerkNet called
1179.q Ing70
1180which is an ARPANET gateway,
1181and we are on a site called
1182.q IngVAX ,
1183ARPANET mail coming into
1184.q Ing70
1185for someone on
1186.q IngVAX
1187will read:
1188.(b
1189From: Ing70:auser@ahost
1190.)b
1191Rewriting set one can rewrite this as:
1192.(b
1193From: auser@ahost
1194.)b
1195since
1196.q Ing70
1197will be implied.
1198.pp
1199When you change to a new set,
1200the previous content of that set is cleared.
1201.sh 3 "R \*- rewriting rule"
1202.pp
1203The heart of parsing is the rewriting rules.
1204The process is essentially textual.
1205First,
1206the address to be rewritten is broken up into words.
1207Words are defined as strings of non-special characters
1208separated by white space or single special characters
1209as defined by the
1210.b $o
1211macro.
1212Then,
1213the words are rewritten using simple pattern matching.
1214Words in the pattern match themselves
1215unless they begin with dollar sign.
1216The dollar escapes have the following meanings\**:
1217.(f
1218\**These dollar escapes have nothing to do with macro expansion.
1219.)f
1220.(b
1221$-x	Match a single word (and call it x).
1222$+x	Match one or more words (and call them x).
1223$=c	Match any word in class c (see below).
1224.)b
1225The case of letters is ignored in pattern matching
1226(including class comparisons).
1227.pp
1228When a pattern (also called a left hand side or LHS)
1229matches,
1230the input is rewritten as defined by the right hand side (RHS).
1231Acceptable escapes in the RHS are:
1232.(b
1233$+x	Replace from corresponding match in LHS.
1234$#mailer	Canonical mailer name.
1235$@host	Canonical host name.
1236$:user	Canonical user name.
1237.)b
1238The replacement from the LHS to the RHS does not use macros,
1239and there are no name conflicts.
1240Patterns are reexecuted until it either resolves to
1241a canonical name
1242(i.e.,
1243.q "$#mailer$@host$:user" )
1244or fails.
1245As soon as the input resolves to a canonical name,
1246matching ends;
1247otherwise,
1248the next pattern is tried.
1249The
1250.q "$@host"
1251part is not needed
1252if the mailer does not require a host.
1253The special mailer
1254.q error
1255causes the user part to be printed as an error.
1256.sh 3 "C \*- define word class"
1257.pp
1258There are twenty six word classes,
1259represented as
1260.q A
1261through
1262.q Z .
1263For example:
1264.(b
1265CVcsvax ingvax esvax
1266.)b
1267defines the words
1268.q csvax ,
1269.q ingvax ,
1270and
1271.q esvax
1272to all be in class
1273.q V ,
1274so that
1275.q $=V
1276on the LHS of a rewriting rule
1277will match any of these words.
1278.sh 2 "A Detailed Example"
1279.pp
1280We will now follow the configuration file
1281in figure 2
1282through in detail.
1283.sh 3 "Macro definitions"
1284.(b
1285DABerkeley
1286DBIngVAX
1287DUucbvax
1288DnMAILER-DAEMON
1289DlFrom $g  $d
1290Do.:@!^
1291.)b
1292The first three macros are for convenience only,
1293and are used to define the local host names
1294on the ARPANET, BerkNet, and the UUCP net
1295respectively.
1296.pp
1297Macro
1298.b n
1299defines the name of this entity
1300when error messages are sent.
1301Macro
1302.b l
1303defines what the first line
1304of a message in UNIX format looks like,
1305in this case the version 7 standard of:
1306.(b
1307From sender-name  time-of-submission
1308.)b
1309The
1310.b o
1311macro
1312tells what characters will be distinct from names
1313when scanning addresses.
1314In this case,
1315dot and colon will be used
1316to distinguish BerkNet addresses,
1317at sign for ARPANET addresses,
1318and exclamation point and caret for UUCP addresses.
1319.sh 3 "Header definitions"
1320.(b
1321H\&Date: $a
1322H\&From: $g$?x ($x)$.
1323H\&Full-Name: $x
1324H\&Message-Id: <$t.$p.$B@$A>
1325H\&Posted-Date: $a
1326.)b
1327These define the headers
1328that may be added to a message.
1329The
1330.q Date:
1331is just the ARPANET idea of the date.
1332The
1333.q From:
1334line is the translated version of the sender,
1335followed by the sender's full name if known.
1336The
1337.q Message-Id:
1338field has the time and process id's concatenated
1339with the BerkNet and ARPANET addresses
1340to make a unique string.
1341Finally, the
1342.q Posted-Date:
1343is the date in ARPANET format;
1344it differs from
1345.q Date:
1346in that it is always output as soon as the message enters
1347.i sendmail 's
1348domain,
1349and hence indicates the time that the message first enters
1350the mail delivery system
1351[NBS].
1352.(d
1353[NBS] NBS standard
1354.)d
1355.sh 3 "Name classifications"
1356.(b
1357C\&A\&ucb berkeley
1358C\&B\&j IngVax
1359C\&C\&i ingres ing70
1360C\&U\&ucbvax ernie
1361.)b
1362These commands put the words
1363.q ucb
1364and
1365.q berkeley
1366into class
1367.q A ,
1368the valid names of this site on the ARPANET.
1369Words
1370.q j
1371and
1372.q ingvax
1373are in class
1374.q B ,
1375the local names on BerkNet.
1376Class
1377.q C ,
1378the names of the site which has the ARPANET link,
1379has the words
1380.q i ,
1381.q ingres ,
1382and
1383.q ing70 .
1384Finally,
1385.q ucbvax
1386and
1387.q ernie
1388are the UUCP names of our UUCP gateway,
1389and are in class
1390.q U .
1391.pp
1392The classes will be used in the patterns of the rewriting rules
1393as described below.
1394.sh 3 "Mailer definitions"
1395.(b
1396M\&local	/bin/mail		rlsAmn	$f	...localmail -d $u
1397M\&prog	/bin/csh		lA	$f	...progmail -fc $u
1398M\&berk	/usr/net/bin/sendberkmail fxs	$B:$f	...berkmail -m $h -h $c -t $u
1399M\&arpa	/usr/lib/mailers/arpa	sAu	$f@$A	...arpamail $f $h $u
1400M\&uucp	/usr/bin/uux		rsDxm	$U!$f	...uucpmail - $h!rmail ($u)
1401.)b
1402Five mailers are known in the configuration file.
1403The first two
1404.i must
1405be for local and program mail,
1406and must come as the first and second mailers respectively.
1407.pp
1408Local mail is sent using
1409/bin/mail.
1410It takes a
1411.b \-r
1412flag,
1413is local,
1414quote characters are stripped before sending,
1415takes ARPANET standard headers,
1416can deliver to multiple recipients at once,
1417and does not want a UNIX-style
1418.q From
1419line since it will add one itself.
1420The translated from address is the same as the raw from address,
1421since no network hops are made.
1422The argument vector has a program name,
1423a
1424.b \-d
1425flag (\c
1426.q "really deliver" ,
1427which must be added to /bin/mail),
1428and the list of recipients \*- one recipient per argument.
1429.pp
1430Mail piped through programs
1431is interpreted by /bin/csh.
1432It does not take a
1433.b \-r
1434flag,
1435quotes should be left,
1436it can only deal with one user,
1437and it does want a UNIX-style
1438.q From
1439line,
1440but is still local and still wants an ARPANET style header.
1441.pp
1442BerkNet mail is processed by
1443/usr/net/bin/sendberkmail.
1444It takes a
1445.b \-f
1446flag,
1447wants a
1448.q Full-Name:
1449header line,
1450and wants quotes stripped.
1451The
1452.q Full-Name:
1453is used here because if it were given as a comment
1454in a
1455.q From:
1456line it might be discarded by later instantiations of
1457.i sendmail .
1458The from address as seen by the receiver is
1459.q IngVAX:sender ,
1460and it takes a flag-oriented
1461rather than a positional
1462command list.
1463.pp
1464The ARPANET wants quotes stripped,
1465ARPANET standard headers,
1466and wants the user name left with case intact.
1467It takes a positional command list.
1468.pp
1469UUCP mail calls
1470.i uux
1471with a
1472.b \-r
1473flag,
1474quotes stripped,
1475a
1476.q Date:
1477line,
1478a
1479.q Full-Name:
1480line,
1481and with multiple users listed.
1482.sh 3 "Rewriting rules for recipient addresses"
1483.(b
1484[1]	R\&$-h.$+u	$+h:$+u			change "." to ":"
1485[2]	R\&$=C:$+u@$-h	$+u@$+h			delete ing70: on arpanet addresses
1486[3]	R\&$+u@$=A	ing70:$+u		delete local arpa hosts
1487[4]	R\&$+u@$-h	$#berk$@ing70$:$+u@$+h	send arpa mail to ing70
1488[5]	R\&$+h^$+u	$+h!$+u			change "^" to "!"
1489[6]	R\&$-x!$=U!$+y	csvax:$+y		delete uucp loops through csvax
1490[7]	R\&$-h!$+u	csvax:$+h!$+u		send uucp mail to csvax
1491[8]	R\&$-x:$-h:$+u	$+h:$+u			delete multiple berk hosts
1492[9]	R\&$=B:$+u	$+u			delete local berk hosts
1493[10]	R\&$-h:$+u	$#berk$@$+h$:$+u	resolve berk mail
1494[11]	R\&$+u		$#local$:$+u		resolve local mail
1495.)b
1496Dots in addresses are translated to colons
1497in the first rule.
1498Redundant explicit routing to the ARPANET is deleted
1499in the second rule.
1500Hops out over the ARPANET
1501back to us are deleted in the third rule \*-
1502note that the host that we would have come in on
1503is inserted.
1504Real ARPANET mail is resolved immediately with no further ado \*-
1505it is sent out over the BerkNet to the ing70,
1506and further rewriting stops immediately.
1507.pp
1508Carets are changed to exclamation points
1509for UUCP addresses in the fifth rule.
1510The sixth rule deletes loops out into UUCP land
1511and back to us \*- noting that we will be left on CSVAX.
1512Multiple BerkNet hosts are deleted in rule seven \*-
1513this can occur internally quite easily
1514as a side effect of a rewriting rule.
1515Rule eight deletes local BerkNet hosts.
1516The last two rules resolve BerkNet and local mail.
1517.pp
1518Consider the following examples:
1519.(b
1520	esvax.asa
1521[1]	esvax:asa
1522[10]	$#berk$@esvax$:asa
1523.)b
1524.(b
1525	research^vax135^dmr
1526[5]	research!vax135^dmr
1527[5]	research!vax135!dmr
1528[7]	$#berk$@csvax$:research!vax135!dmr
1529.)b
1530.(b
1531	research!ucbvax!j:eric
1532[6]	csvax:j:eric
1533[8]	j:eric
1534[9]	eric
1535[11]	$#local$:eric
1536.)b
1537.(b
1538	ing70:wnj@Berkeley
1539[2]	wnj@Berkeley
1540[3]	ing70:wnj
1541[10]	$#berk$@ing70$:wnj
1542.)b
1543.sh 3 "Rewriting rules for sender addresses"
1544.(b
1545S\&1
1546R\&ing70:$+u@$-h	$+u@$+h			arpanet mail is automatic
1547R\&CSVAX:$-h!$+u	$+h!$+u			uucp mail is automatic
1548.)b
1549The
1550.b S
1551line starts putting the rules into set one.
1552These rules strip off the
1553.q ing70:
1554from incoming ARPANET mail
1555and the
1556.q CSVAX:
1557off of incoming UUCP mail.
1558.pp
1559The name classes could be used here,
1560but using literal strings is safe
1561because they will always be program-generated.
1562.sh 1 "COMPARISON WITH OTHER MAILERS"
1563.sh 2 "Delivermail"
1564.pp
1565.i Sendmail
1566is an outgrowth of
1567.i delivermail .
1568The primary differences are:
1569.np
1570Configuration information is not compiled in.
1571This simplifies many of the problems
1572of moving to other machines.
1573It also allows easy debugging of new mailers.
1574.np
1575Address parsing is more flexible.
1576For example,
1577.i delivermail
1578only supported one gateway to any network,
1579whereas
1580.i sendmail
1581can be sensitive to host names
1582and reroute to different gateways.
1583.np
1584Forwarding and
1585:include:
1586support eliminate the requirement that the system alias file
1587be writable by any user
1588(or that an update program be written,
1589or that the system administration make all changes).
1590.np
1591.i Sendmail
1592supports message batching across networks
1593when a message is being sent to multiple recipients.
1594.sh 2 "MMDF"
1595.pp
1596MMDF [ref]
1597spans a much wider problem set than
1598.i sendmail .
1599For example,
1600MMDF includes a
1601.q "phone network"
1602mailer, whereas
1603.i sendmail
1604calls on preexisting mailers in most cases.
1605.i Sendmail
1606is approximately equivalent to the
1607SUBMIT and DELIVER phases of MMDF.
1608Because of this difference in design goals,
1609some of the important features of MMDF
1610(queueing, retransmission, and two-phase timeout)
1611are unimplemented by
1612.i sendmail .
1613.pp
1614MMDF and
1615.i sendmail
1616both support aliasing,
1617customized mailers,
1618message batching,
1619and automatic forwarding to gateways.
1620.sh 2 "Message Processing Module"
1621.pp
1622The Message Processing Module (MPM)
1623discussed by Postel [ref]
1624matches
1625.i sendmail
1626closely in terms of its basic architecture.
1627However,
1628like MMDF,
1629the MPM includes the network interface software
1630as part of its domain.
1631.pp
1632MPM also postulates a duplex channel to the receiver,
1633as does MMDF.
1634This allows simpler handling of errors
1635by the mailer
1636than possible in
1637.i sendmail ;
1638when a message queued by
1639.i sendmail
1640is sent,
1641any errors must be returned to the sender
1642by the mailer itself.
1643Both MPM and MMDF mailers
1644can return an immediate error response,
1645and a single error processor can create an appropriate response.
1646.pp
1647MPM prefers passing the message as a structured message,
1648with type-length-value tuples.
1649This implies a much higher degree of cooperation
1650between mailers than required by
1651.i sendmail .
1652MPM also assumes a universally agreed upon internet name space
1653(with each address a net-host-user tuple),
1654which
1655.i sendmail
1656does not.
1657.sh 1 "EVALUATIONS AND FUTURE PLANS"
1658.pp
1659.i Sendmail
1660is designed to work in a nonhomogeneous environment.
1661Every attempt is made to avoid imposing any constraints
1662on the underlying mailers.
1663This goal has driven much of the design.
1664One of the major problems
1665has been the lack of a uniform address space,
1666as postulated in [IP]
1667.(d
1668[IP] -- internet protocol
1669.)d
1670and [PostelIMS].
1671.(d
1672[PostelIMS] -- Internet Message Structure
1673.)d
1674.pp
1675A nonuniform address space implies that path will be specified
1676in all addresses,
1677either explicitly (as part of the address)
1678or implicitly
1679(as with implied forwarding to gateways).
1680This has the unpleasant effect of making replying to messages
1681exceedingly difficult,
1682since there is no one
1683.q address
1684for any person,
1685but only a way to get there from wherever you are.
1686.pp
1687Interfacing to mail programs
1688that were not initially intended to be applied
1689in an internet environment
1690has been amazingly successful,
1691and has reduced the job to a manageable task.
1692.pp
1693However,
1694many of these mailers implement their own queueing and retransmission.
1695In networks that support store-and-forward file transfer,
1696such as BerkNet and UUCP,
1697this feature must be supplied already.
1698However,
1699networks that transfer in real time,
1700such as the ARPANET or an Ether-based network
1701[ref],
1702generally do not provide these features.
1703Also,
1704networks which provide these generally do not understand
1705timeouts or returning the text of the message on error,
1706both highly desirable features\**.
1707.(f
1708\**We have implemented an ARPANET mailer which
1709returns the message on error and does one-stage timeout
1710(returning the message after three days).
1711.)f
1712Such queueing, retransmission, and two-phase timeout
1713may be integrated into
1714.i sendmail
1715if it seems desirable.
1716.pp
1717.i Sendmail
1718has knowledge of a few difficult environments
1719built in.
1720It generates ARPANET FTP compatible error messages
1721(prepended with three-digit numbers
1722[FTP1, FTP2])
1723.(d
1724[FTP1] -- FTP description
1725.)d
1726.(d
1727[FTP2] -- revised FTP codes
1728.)d
1729as necessary,
1730optionally generates UNIX-style
1731.q From
1732lines on the front of messages for some mailers,
1733and knows how to parse the same lines on input.
1734This can be inconvenient to sites which have abandoned UNIX mail,
1735although
1736.i sendmail
1737still adds and understands ARPANET-style
1738.q From:
1739lines.
1740Also,
1741error handling has an option customized for BerkNet.
1742.pp
1743One surprisingly major annoyance in most internet mailers
1744(such as MMDF)
1745is that the location and format of local mail is built in\**.
1746.(f
1747\**For example,
1748MMDF puts local mail in the file
1749.q .mail
1750\*- useful if you are running version 6.
1751.)f
1752.i Sendmail
1753eliminates all knowledge of location
1754and can function successfully with different formats.
1755.pp
1756The ability to automatically generate a response to incoming mail
1757(by forwarding mail to a program)
1758seems useful
1759(\c
1760.q "I am on vacation until late August...." )
1761but can create problems
1762such as forwarding loops
1763(two people on vacation whose programs send notes back and forth,
1764for instance)
1765if these programs are not well written.
1766A program should be written to do standard tasks correctly,
1767but this does not solve the general case.
1768It might be desirable to implement some form of load limiting.
1769I am unaware of any mail system that addresses this problem,
1770nor am I aware of any reasonable solution at this time.
1771.pp
1772.i Sendmail
1773should be modified to run as a daemon,
1774reading an MPX file
1775(or other IPC scheme)
1776to receive mail and process it.
1777This would reduce the cost of sending mail to writing the message
1778into a known file.
1779.i Sendmail
1780would be modified to have a very different argument structure.
1781It already has an option to read the recipients
1782from the message header.
1783A more palatable technique for giving error messages
1784would also have to be devised.
1785.pp
1786The configuration file is currently practically inscrutable;
1787considerable convenience could be realized
1788with a higher-level format.
1789For example, a description might read:
1790.(b
1791(MACRO name value)
1792(HEADER name value
1793	(OPTION option) ...
1794	(NEEDS option) ... )
1795(MAILER name path xlatstring
1796	(OPTION option) ...
1797	(ARGV arg ... ))
1798(CLASS name word ...)
1799(REWRITE setname
1800	(RULE lhs rhs) ... )
1801.)b
1802.pp
1803Many other nice features could be implemented.
1804For example,
1805if we were sure that the alias file were writable by the effective user
1806(i.e., if
1807.i sendmail
1808were to run setuid)
1809then the inverted form could be rebuilt automatically when the
1810text copy was changed.
1811However, this appears to be little more than frosting.
1812.sp 2i
1813.pd
1814