]> git.deb.at Git - pkg/t-prot.git/blob - contrib/t-prot.sl
Imported Upstream version 1.99.1
[pkg/t-prot.git] / contrib / t-prot.sl
1 % $Id: t-prot.sl,v 1.14 2005/03/31 19:39:08 jochen Exp $
2 % Copyright (c) 2003 Jochen Striepe <t-prot@tolot.escape.de>
3 %
4 % This file is provided as an example implemention for articles to be
5 % filtered through t-prot before displayed. They are still filtered if
6 % you reply to such a message so you will have to deactivate this if
7 % you want to include quotes of the original article.
8 %
9 % Activate this macro by adding
10 %   interpret t-prot.sl
11 % to your ~/.slrnrc.
12 %
13 % If you are not happy with the suggested t-prot default parameters,
14 % put something like
15 %   variable t_prot_params = "-cemtS";
16 %   variable t_prot_tmpdir = "$HOME/.tmpdir";
17 %   variable t_prot_qp     = "";
18 % into ~/.slrn/t-prot-cfg and add
19 %   interpret .slrn/t-prot-cfg
20 % to your ~/.slrnrc (after 'interpret t-prot.sl'). If "mimedecode" is
21 % installed on your system you might want to use
22 %   variable t_prot_qp     = "mimedecode";
23 % You can get mimedecode at
24 %   http://packages.debian.org/stable/mail/mimedecode.html
25 %
26 % However, please keep in mind that the path of the temp directory should
27 % NOT be readable to other users -- otherwise it might reveal information on
28 % what you read, and probably even be a security hole. Please see t-prot's
29 % man page for details on command line parameters.
30 %
31 % If you want to toggle t-prot filtering on/off without leaving slrn,
32 % you may want to add something like
33 %   setkey article   register_t_prot "\e6"
34 %   setkey article unregister_t_prot "\e7"
35 % to your ~/.slrnrc -- press ESC-6 to activate t-prot filtering, and
36 % ESC-7 to disable it (this will take effect on the next article you
37 % read, see the package's TODO file).
38 %
39 % Requirements/Bugs: tr(1) and rm(1) are POSIX and should be available
40 % on any Unix-like system, mktemp(1) should be available on any recent
41 % OpenBSD or Debian Linux system -- you can get the sources there
42 % if your system happens to lack this program. This macro has been
43 % tested with slrn-0.9.7.4 to slrn-0.9.8.0 and S-Lang v1.4.5, it might
44 % fail with other versions. As always, bug reports, patches (preferrably
45 % in unified diff format), comments and suggestions are welcome.
46 %
47 % License: This file is part of the t-prot package and therefore
48 % available under the same conditions. See t-prot's man page for
49 % details.
50
51
52 % these should be reasonable defaults (they work fine for me, SCNR):
53 variable t_prot_params = "-aceklmtS --diff --bigq -L$HOME/.slrn/mlfooters -A$HOME/.slrn/adfooters";
54 variable t_prot_tmpdir = "$HOME/tmp/slrn";
55 variable t_prot_qp = "perl -i -p -e '$p=1 if /^Content-Transfer-Encoding: quoted-printable/i; if ($p==1) { s/=([0-9a-f][0-9a-f])/chr(hex($1))/egi; s/=\n//eg; };'";
56
57 define t_prot () {
58         variable art, f, fname, line, qp;
59         art = "";
60
61         % Keep in mind that the path should NOT be readable to other users --
62         % otherwise it might reveal information on what you read, and probably
63         % even be a security hole:
64         f = popen ("mktemp -q "+t_prot_tmpdir+"/t-prot.sl.XXXXXX | tr -d '\n'", "r");
65         if (f == NULL) return;
66         if (-1 == fgets (&fname, f)) return;
67         pclose (f);
68
69
70         if (t_prot_qp != "") { qp = t_prot_qp+"|"; } else { qp = ""; }
71
72         f = popen (qp+"t-prot "+t_prot_params+" >"+fname, "w");
73         if (f == NULL) {
74                 error ("Unable to filter article to "+fname);
75                 return;
76         }
77         () = fputs (article_as_string(), f);
78         () = pclose (f);
79
80
81         f = fopen (fname, "r");
82         if (f == NULL) {
83                 error (fname+" could not be opened.");
84                 return;
85         }
86         while (-1 != fgets (&line, f)) {
87                 art = art + line;
88         }
89         fclose (f);
90
91         if (0 != remove(fname)) error ("Unable to remove "+fname);
92
93         replace_article (art);
94 }
95
96 define register_t_prot () {
97         if (1 == register_hook("read_article_hook", "t_prot")) {
98                 error("t-prot filtering activated");
99         }
100         else {
101                 error("t-prot filtering NOT activated");
102         }
103 }
104
105 define unregister_t_prot () {
106         if (1 == unregister_hook("read_article_hook", "t_prot")) {
107                 error("t-prot filtering deactivated");
108         }
109         else {
110                 error("t-prot filtering NOT deactivated");
111         }
112 }
113
114 % filtering is enabled by default:
115 register_hook("read_article_hook", "t_prot");