3 # sylprint.pl - process a Sylpheed mail and print it using enscript or lpr
5 # (c) 2001 by Ricardo Mones Lastra <mones@aic.uniovi.es>
6 # This program is released under the GNU General Public License.
7 # See README.sylprint file for details and usage.
9 # NOTE: If you want to to change configuration edit sylprint.rc file,
10 # all options are further explained in that file.
13 $headerformat = '|%W|$%/$=';
17 $pageheaderfont = 'Times-Roman@11';
18 $mailfont = 'Courier@9/13';
28 $_=`which enscript`; chomp; $ENS=$_;
29 $_=`which lpr`; chomp; $LPR=$_;
30 $_=`which gv`; chomp; $GPR=$_;
31 $_=`which gless`; chomp; $TPR=$_;
34 die "required filename missing\n" unless (defined($ARGV[0]));
37 if (defined($ARGV[1]) && $ARGV[1] eq '-r') { $a++; }
40 delete $spp[(scalar @spp) - 1];
41 $spp = join('/',@spp);
43 if (-x $rcf) { do $rcf; }
44 $rcf="$ENV{'HOME'}/.sylpheed/$rc";
45 if (-x $rcf) { do $rcf; }
48 while (defined($ARGV[$a])) {
52 $printer = (defined($ARGV[$a]))? $ARGV[$a]: $printer;
57 $mailfont = (defined($ARGV[$a]))? $ARGV[$a]: $mailfont;
59 die "$0: invalid font\n" unless (/\w+(\@\d+(\.\d+)?(\/\d+(\.\d+)?)?)?/);
64 $separator = (defined($ARGV[$a]))? $ARGV[$a]: '';
67 if (/-./) { $separator = ''; $a--; }
71 /-h/ && do { $headerformat = ''; last; };
72 /-t/ && do { $translate = 0; last; };
73 /-e/ && do { $usenscript = 0; last; };
74 /-v/ && do { $preview++; last; };
77 $wrapping = (defined($ARGV[$a]))? $ARGV[$a]: 0;
80 if (/-./) { $wrapping = 0; $a--; }
81 else { die "$0: invalid number\n" unless (/\d+/); }
87 if (defined($ARGV[$a + 1])) {
89 do { $remquoted = $_; $a++ ; } unless (/-./);
93 /-S/ && do { $signature = 0; last; };
94 /-H/ && do { $headers = 0; last; };
95 /--/ && do { $a++; @forens = splice(@ARGV,$a); last; };
99 # translations/encoding
100 $lang = (defined($ENV{'LANG'}) && $translate)? $ENV{'LANG'}: 'en';
103 @cabl=("Datum","Od","Komu","Kopie","Diskusní skupiny","Pøedmìt");
104 $encoding = 'latin2'; # Czech (iso-8859-2)
108 @cabl=("Dato","Fra","Til","Cc","Newsgroups","Emne");
112 @cabl=("Datum","Von","An","Cc","Newsgruppen","Betreff");
113 $headerformat = '|%W|Seite $% vom $=';
117 @cabl=("Çìåñïìçíßá","Áðü", "Ðñïò","Êïéíïðïßçóç","Newsgroups","ÈÝìá");
118 $encoding = 'greek'; # Greek (iso-8859-7)
122 @cabl=("Fecha","Desde","Para","Copia","Grupos de noticias","Asunto");
123 $headerformat = '|%W|Pág. $% de $=';
127 @cabl=("Kuupäev","Kellelt","Kellele","Koopia","Uudistegrupid","Pealkiri");
131 @cabl=("Date","De","À","Cc","Groupe de discussion","Sujet");
132 $headerformat = '|%W|Page $% des $=';
136 @cabl=("Datum","Od","Za","Cc","News grupe","Tema");
137 $encoding = 'latin2'; # Croatian (iso-8859-2)
141 @cabl=("Dátum","Feladó","Címzett","Másolat","Üzenet-azonosító","Tárgy");
142 $encoding = 'latin2'; # Hungarian (iso-8859-2)
146 @cabl=("Data","Da","A","Cc","Gruppo di notizie","Oggetto");
147 $headerformat = '|%W|Pag. $% di $=';
151 @cabl=("ÆüÉÕ","º¹½Ð¿Í","°¸Àè","Cc","¥Ë¥å¡¼¥¹¥°¥ë¡¼¥×","·ï̾");
152 warn "$0: charset not supported by enscript: using lpr\n";
157 @cabl=("³¯Â¥","º¸³½ »ç¶÷","¹Þ´Â »ç¶÷","ÂüÁ¶","´º½º±×·ì","Á¦¸ñ");
158 warn "$0: charset not supported by enscript: using lpr\n";
163 @cabl=("Datum","Afzender","Aan","Cc","Nieuwsgroepen","Onderwerp");
167 @cabl=("Data","Od","Do","Kopia","Grupy news","Temat");
168 $encoding = 'latin2'; # Polish (iso-8859-2)
172 @cabl=("Data","De","Para","Cc","Grupos de notícias","Assunto");
176 @cabl=("äÁÔÁ","ïÔ","ëÏÍÕ","ëÏÐÉÑ","çÒÕÐÐÙ ÎÏ×ÏÓÔÅÊ","ôÅÍÁ");
177 $encoding = 'koi8'; # Russian (koi8-r)
181 @cabl=("Datum","Från","Till","Cc","Nyhetsgrupper","Ärende");
185 @cabl=("Tarih","Kimden","Kime","Kk","Haber gruplarý","Konu");
186 warn "$0: charset not supported by enscript: using lpr\n";
190 /zh_CN\.GB2312/ && do {
191 @cabl=("ÈÕÆÚ","·¢¼þÈË£º","ÖÂ(To)£º","³ËÍ(Cc)£º","ÐÂÎÅ×飺","±êÌ⣺");
192 warn "$0: charset not supported by enscript: using lpr\n";
196 /zh_TW\.Big5/ && do {
197 @cabl=("¤é´Á","¨Ó¦Û¡G","¦¬¥ó¤H","°Æ¥»","·s»D¸s²Õ¡G","¼ÐÃD¡G");
198 warn "$0: charset not supported by enscript: using lpr\n";
203 @cabl=("Date","From","To","Cc","Newsgroups","Subject");
207 # headers as given by Sylpheed
208 %cabs = ("Date",0,"From",1,"To",2,"Cc",3,"Newsgroups",4,"Subject",5);
209 @cabn = ("Date","From","To","Cc","Newsgroups","Subject");
210 @cont = ("","","","","","");
213 $tmpfn="/tmp/sylprint.$ENV{'USER'}.$$";
215 open(FIN,"<$ARGV[0]");
220 if ($cont[$ix] eq "") {
222 if (/^$n:\s+(.+)$/) {
228 if ($remquoted ne '' && /^\Q$remquoted\E(.+)$/) { next LN; }
229 if (!$signature && /^--\s*$/) { last; }
230 $body = join('',$body,$ln);
237 $lci = length($cabl[$cabs{$n}]);
238 $ml = (($cont[$cabs{$n}] ne "") && ($lci > $ml))? $lci: $ml;
247 if ($cont[$ix] ne "") {
248 print TMP "$cabl[$ix]", " " x ($ml - length($cabl[$ix])), ": ";
250 my $kk = 1; $wl = $wrapping;
252 while (length($l) > ($wl - $ml)) {
253 $ll = substr($l,0,$wl);
255 while ((substr($ll,$jx,1) ne ' ') && $jx) { $jx--; }
256 $ll = substr($l,0,($jx)? $jx: $wl,'');
257 if ($kk) { print TMP $ll, "\n"; $kk--; }
258 else { print TMP " ", " " x $ml, $ll, "\n"; }
260 if ($kk) { print TMP $l, "\n"; }
261 else { print TMP " ", " " x $ml, $l, "\n"; }
264 print TMP $cont[$ix], "\n";
269 print TMP $separator x (($wrapping)? $wrapping: 79), "\n";
276 @bodyl = split(/\n/,$body);
277 foreach $l (@bodyl) {
278 while (length($l) > $wl) {
279 $ll = substr($l,0,$wl);
281 while ((substr($ll,$ix,1) ne ' ') && $ix) { $ix--; }
282 $ll = substr($l,0,($ix)? $ix: $wl,'');
289 print TMP "\n$body\n";
293 # let enscript do its job
294 if (-x $ENS and $usenscript) {
295 @ecmd = ($ENS,'','','-b',$headerformat,'-M',$papersize,'-X',$encoding,
296 '-i','1c','-h','-f',$mailfont,'-F',$pageheaderfont,@forens,
299 $ecmd[1] = '-p'; $ecmd[2] = "$tmpfn.ps";
301 @vcmd = (split(' ',$GPR),"$tmpfn.ps");
306 $ecmd[1] = '-P'; $ecmd[2] = $printer;
310 else { # no enscript, try lpr
311 if ($usenscript) { warn "$ENS not found, using lpr\n"; }
312 die "$LPR not found\n" unless (-x $LPR);
314 @vcmd = (split(' ',$TPR),$tmpfn);
318 @lprcmd = ($LPR,'-T','Sylpheed Mail',
319 ($headerformat eq '')? '-l': '-p','-P',$printer,@forens, $tmpfn);
320 die "trying lpr: $! \n" unless (system(@lprcmd) != -1);