<?php	// TWIG		Attachment Viewing Feature Module ?>
<?php 

 include("features/common.inc");

 $mbox=twig_auth("TWIG",$logout);  
 $structure=imap_fetchstructure($mbox,$message);
 $px=$structure->parts[$spart-1];
 if (count($px->parameters)) {
  $pxx=$px->parameters[0];
  $bytes = $px->bytes;
  $atdesc=$pxx->value;
 }
 else {
  $pxx=$px;
  $bytes = $px->bytes;
  $atdesc=$px->description;
 }

 $prebody=imap_fetchbody($mbox,$message,$spart);
 if ($px->encoding == 1) { $body = imap_8bit($prebody); }
 elseif ($px->encoding == 2) { $body = imap_binary($prebody); }
 elseif ($px->encoding == 3) { $body = imap_base64($prebody); }
 else { $body = $prebody; }

 $contenttype=$mimetype[$px->encoding];
 $filename=$pxx->value;

 if ($atdesc == "us-ascii") { $inline=1; }
 if (eregi("quoted-printable",$contenttype)) { $inline = 1; }

 if (!$inline) {
  Header("Content-Disposition: attachment; filename=$filename");
  Header("Content-type: $contenttype");
  echo $body;
 }
 else {
  // Clean up the mess
  $body = eregi_replace("=3d","=",$body);
  $body = eregi_replace("=20","\n",$body);
  $command=attachment;
  include("index.php3");
 }

?>

