filter 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. .TH FILTER 1
  2. .SH NAME
  3. filter, list, deliver, token, vf \- filtering mail
  4. .SH SYNOPSIS
  5. .PP
  6. .B upas/filter
  7. [
  8. .B -bh
  9. ]
  10. .I rcvr
  11. .I mailbox
  12. [
  13. .I "regexp file
  14. ] ...
  15. .PP
  16. .B upas/list
  17. [
  18. .B -d
  19. ]
  20. .B add|check
  21. .I patternfile
  22. .I addressfile ...
  23. .PP
  24. .B upas/deliver
  25. .I recipient
  26. .I fromfile
  27. .I mbox
  28. .PP
  29. .B upas/token
  30. .I key
  31. [
  32. .I tokenfile
  33. ]
  34. .PP
  35. .B upas/vf
  36. [
  37. .B -r
  38. ]
  39. [
  40. .B -s
  41. .I savefile
  42. ]
  43. .SH DESCRIPTION
  44. .PP
  45. A user may filter all incoming mail by creating
  46. a world readable/executable file
  47. .BI /mail/box/ username /pipeto.
  48. If the file is a shell script, it can use the
  49. commands described here to implement a filter.
  50. .PP
  51. .I Filter
  52. provides simple mail filtering.
  53. The first two arguments are the recipient's address and mailbox, that is,
  54. the same arguments provided to
  55. .BR pipeto .
  56. The remaining arguments are all pairs of a regular expression and a file name.
  57. With no flags, the sender's address is matched against each
  58. regular expression starting with the first. If the expression
  59. matches, then the message is delivered to the file whose name
  60. follows the expression. The file must be world writable and should
  61. be append only.
  62. A message that matches none of the expressions is delivered into
  63. the user's standard mail box.
  64. .PP
  65. By default,
  66. .I filter
  67. matches each regular expression against the message's sender.
  68. The
  69. .B -h
  70. flag causes
  71. .I filter
  72. to match against the entire header,
  73. and the
  74. .B -b
  75. flag causes
  76. .I filter
  77. to match against the entire message (header and body).
  78. .PP
  79. For example, to delete any messages of precedence bulk, place in
  80. your
  81. .B pipeto
  82. file:
  83. .EX
  84. /bin/upas/filter -h $1 $2 'Precedence: bulk' /dev/null
  85. .EE
  86. .PP
  87. Three other commands exist which, combined by an
  88. .IR rc (1)
  89. script, allow you to build your own filter.
  90. .PP
  91. .I List
  92. takes two verbs;
  93. .B check
  94. and
  95. .BR add .
  96. .B Check
  97. directs
  98. .I list
  99. to check each address contained in the
  100. .IR addressfile s
  101. against a list of patterns in
  102. .IR patternfile .
  103. Patterns come in four forms:
  104. .TP
  105. .B ~\fIregular-expression\fP
  106. If any address matches the regular expression,
  107. .I list
  108. returns successfully.
  109. .TP
  110. .BR =\fIstring\fP .
  111. If any address exactly matches
  112. .IR string ,
  113. .I list
  114. returns successfully.
  115. .TP
  116. .B !~\fIregular-expression\fP
  117. If any address matches the regular expression
  118. and no other address matches a non `!' rule,
  119. .I list
  120. returns error status "!match".
  121. .TP
  122. .B !=\fIstring\fP
  123. If any address exactly matches
  124. .I string
  125. and no other address matches a non `!' rule,
  126. .I list
  127. returns error status "!match".
  128. .PP
  129. If no addresses match a pattern,
  130. .I list
  131. returns "no match".
  132. .PP
  133. The pattern file may also contain lines of the form
  134. .EX
  135. #include filename
  136. .EE
  137. This allows pattern files to include other pattern
  138. files.
  139. All pattern matches are case insensitive.
  140. .I List
  141. searches the pattern file (and its includes) in order.
  142. The first matching pattern determines the action.
  143. .PP
  144. .I List
  145. .B add
  146. directs
  147. .I list
  148. to add a pattern to
  149. .I patternfile
  150. for each address in the
  151. .I addressfiles
  152. that doesh't already match a pattern.
  153. .PP
  154. .IR Token ,
  155. with only one argument, prints to standard output a unique token
  156. created from the current date and
  157. .IR key .
  158. With two arguments, it checks
  159. .I token
  160. against tokens created over the last 10 days with
  161. .IR key .
  162. If a match is found, it returns successfully.
  163. .PP
  164. .I Deliver
  165. delivers into mail box
  166. .I mbox
  167. the message read from standard input.
  168. It obeys standard mail file locking and logging
  169. conventions.
  170. .PP
  171. A sample
  172. .B pipeto
  173. using the filter kit can be found in
  174. .BR /sys/src/cmd/upas/filterkit/pipeto.sample .
  175. .PP
  176. A sample
  177. .BR pipefrom ,
  178. .BR /sys/src/cmd/upas/filterkit/pipefrom.sample ,
  179. is provided which adds all addresses of your outgoing
  180. mail to your pattern file.
  181. You should copy it into a directory that normally gets
  182. bound by your profile onto
  183. .BR /bin .
  184. .PP
  185. .I Vf
  186. (virus filter)
  187. takes a mail message as standard input
  188. and searches for executable MIME attachments,
  189. either rewriting them to be non-executable or
  190. rejecting the message.
  191. The behavior depends on the attachment's file name
  192. extension and MIME content type.
  193. .B /sys/lib/mimetype
  194. contains the list of known extensions and MIME content types.
  195. The fifth field of each line specifies the
  196. safety of a particular file type:
  197. .B y
  198. (yes),
  199. .B m
  200. (maybe; treated same as yes),
  201. .B n
  202. (no),
  203. .B p
  204. (previous),
  205. or
  206. .B r
  207. (reject).
  208. .I Vf
  209. allows attachments with safety
  210. .B y
  211. or
  212. .B m
  213. to pass through unaltered.
  214. Attachments with safety
  215. .B n
  216. both are wrapped in extra MIME headers
  217. and have
  218. .B .suspect
  219. appended to their file names, to avoid
  220. automatic execution by mail readers.
  221. Attachments with safety
  222. .B r
  223. (currently,
  224. .BR .bat ,
  225. .BR .com ,
  226. .BR .exe ,
  227. and
  228. .BR .scr ,
  229. all Microsoft executable extensions)
  230. are taken as
  231. cause for the entire message to be rejected.
  232. A safety of
  233. .B p
  234. (used for the
  235. .B x-gunzip
  236. mime type)
  237. causes the previous extension to be tested,
  238. so that
  239. .B x.tar.gz
  240. is treated the same as
  241. .BR x.tar .
  242. .PP
  243. If
  244. .B /mail/lib/validateattachment
  245. exists and is executable,
  246. .B vf
  247. runs it on all attachments with safety
  248. .B n
  249. (attachments it would normally sanitize).
  250. If
  251. .IR validateattachment 's
  252. exit status contains the string
  253. .L discard ,
  254. .I vf
  255. rejects the entire message.
  256. If the status contains the string
  257. .L accept ,
  258. .I vf
  259. does not sanitize the attachment.
  260. Otherwise,
  261. .I vf
  262. sanitizes the attachment as before.
  263. The standard
  264. .I validateattachment
  265. uses
  266. .IR file (1)
  267. to determine the file type.
  268. It accepts text and image files
  269. and discards messages containing
  270. executables or
  271. .I zip
  272. (see
  273. .IR gzip (1))
  274. archives of executables.
  275. .PP
  276. The
  277. .B -r
  278. option causes
  279. .I vf
  280. not to sanitize MIME attachments, only to
  281. reject messages it determines to be viruses.
  282. The
  283. .B -s
  284. option causes
  285. .I vf
  286. to log all attachments of safety
  287. .B r
  288. in the mail box
  289. .IR savefile .
  290. .SH FILES
  291. .TF /mail/box/*/dead.letter
  292. .TP
  293. .B /mail/box/*/pipeto
  294. mail filter
  295. .TP
  296. .B /sys/lib/mimetype
  297. MIME content types
  298. .TP
  299. .B /mail/lib/validateattachment
  300. attachment checker
  301. .SH SOURCE
  302. .TP
  303. .B /sys/src/cmd/upas/send
  304. .TP
  305. .B /sys/src/cmd/upas/filterkit
  306. .TP
  307. .B /sys/src/cmd/upas/vf
  308. .SH "SEE ALSO"
  309. .IR aliasmail (8),
  310. .IR faces (1),
  311. .IR mail (1),
  312. .IR marshal (1),
  313. .IR mlmgr (1),
  314. .IR nedmail (1),
  315. .IR qer (8),
  316. .IR rewrite (6),
  317. .IR send (8),
  318. .IR smtp (8),
  319. .IR upasfs (4)