]> git.deb.at Git - pkg/t-prot.git/blob - contrib/t-prot.sl
Imported Upstream version 2.101
[pkg/t-prot.git] / contrib / t-prot.sl
1 % $Id: t-prot.sl,v 1.18 2010/02/19 16:21:14 jochen Exp $
2 % Copyright (c) 2003-2005 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 = "-c -emtS";
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 (and will definitely fail with S-Lang v2.x).
45 % As always, bug reports, patches (preferrably in unified diff format),
46 % comments and suggestions are welcome.
47 %
48 % License: This file is part of the t-prot package and therefore
49 % available under the same conditions. See t-prot's man page for
50 % details.
51
52
53 % these should be reasonable defaults (they work fine for me, SCNR):
54 variable t_prot_params = "-aeklmtc -S --diff --bigq -L$HOME/.slrn/mlfooters -A$HOME/.slrn/adfooters";
55 variable t_prot_tmpdir = "$HOME/tmp/slrn"; % you better make sure it exists
56 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; };'";
57
58 define t_prot () {
59         variable art, f, fname, line, qp;
60         art = "";
61
62         % Keep in mind that the path should NOT be readable to other users --
63         % otherwise it might reveal information on what you read, and probably
64         % even be a security hole:
65         f = popen ("mktemp -q "+t_prot_tmpdir+"/t-prot.sl.XXXXXX | tr -d '\n'", "r");
66         if (f == NULL) return;
67         if (-1 == fgets (&fname, f)) return;
68         pclose (f);
69
70
71         if (t_prot_qp != "") { qp = t_prot_qp+"|"; } else { qp = ""; }
72
73         f = popen (qp+"t-prot "+t_prot_params+" >"+fname, "w");
74         if (f == NULL) {
75                 error ("Unable to filter article to "+fname);
76                 return;
77         }
78         () = fputs (article_as_string(), f);
79         () = pclose (f);
80
81
82         f = fopen (fname, "r");
83         if (f == NULL) {
84                 error (fname+" could not be opened.");
85                 return;
86         }
87         while (-1 != fgets (&line, f)) {
88                 art = art + line;
89         }
90         fclose (f);
91
92         if (0 != remove(fname)) error ("Unable to remove "+fname);
93
94         replace_article (art);
95 }
96
97 define register_t_prot () {
98         if (1 == register_hook("read_article_hook", "t_prot")) {
99                 error("t-prot filtering activated");
100         }
101         else {
102                 error("t-prot filtering NOT activated");
103         }
104 }
105
106 define unregister_t_prot () {
107         if (1 == unregister_hook("read_article_hook", "t_prot")) {
108                 error("t-prot filtering deactivated");
109         }
110         else {
111                 error("t-prot filtering NOT deactivated");
112         }
113 }
114
115 % filtering is enabled by default:
116 register_hook("read_article_hook", "t_prot");