3 # View one attachment from a message
6 require './mailboxes-lib.pl';
8 &can_user($in{'user'}) || &error($text{'mail_ecannot'});
10 @folders = &list_user_folders($in{'user'});
11 $folder = $folders[$in{'folder'}];
12 @mail = &mailbox_list_mails($in{'idx'}, $in{'idx'}, $folder);
13 $mail = $mail[$in{'idx'}];
15 @sub = split(/\0/, $in{'sub'});
17 # We are looking at a mail within a mail ..
18 local $amail = &extract_mail($mail->{'attach'}->[$s]->{'data'});
22 $attach = $mail->{'attach'}->[$in{'attach'}];
25 # Scale the gif or jpeg image to 48 pixels high
26 local $temp = &transname();
28 print TEMP $attach->{'data'};
30 $SIG{'CHLD'} = sub { wait; };
31 if ($attach->{'type'} eq 'image/gif') {
32 ($pnmin, $pnmout) = &pipeopen("giftopnm $temp");
34 elsif ($attach->{'type'} eq 'image/jpeg') {
35 ($pnmin, $pnmout) = &pipeopen("djpeg -fast $temp");
44 $type =~ /^P[0-9]/ || &dump_erroricon();
45 $size =~ /(\d+)\s+(\d+)/ || &dump_erroricon();
53 ($jpegin, $jpegout) = &pipeopen("pnmscale $scale 2>/dev/null | cjpeg");
56 while(read($pnmout, $buf, 1024)) {
61 print "Content-type: image/jpeg\n\n";
62 while(read($jpegout, $buf, 1024)) {
68 # Just output the attachment
69 print "X-no-links: 1\n";
70 @download = split(/\t+/, $config{'download'});
72 # Display as a specific MIME type
73 print "Content-type: $in{'type'}\n\n";
74 print $attach->{'data'};
80 print "Content-Disposition: Attachment\n";
82 if ($attach->{'type'} eq 'message/delivery-status') {
83 print "Content-type: text/plain\n\n";
86 print "Content-type: $attach->{'type'}\n\n";
89 if ($attach->{'type'} =~ /^text\/html/i && !$in{'save'}) {
90 print &safe_urls(&filter_javascript($attach->{'data'}));
93 print $attach->{'data'};
100 print "Content-type: image/gif\n\n";
101 open(ICON, "images/error.gif");
102 while(<ICON>) { print; }
111 local $inr = "INr$pipe";
112 local $inw = "INw$pipe";
113 local $outr = "OUTr$pipe";
114 local $outw = "OUTw$pipe";
120 open(STDIN, "<&$inr");
121 open(STDOUT, ">&$outw");
125 print STDERR "exec failed : $!\n";
130 return ($inw, $outr);