Support for RAR attachments in IMP

Joaquim Homrighausen joho@webbplatsen.se
Wed, 06 Jun 2001 15:34:54 +0200



Since RAR archives are becoming more and more popular, here's code
for IMP to support viewing of their contents, much like for ZIP.


In ./imp/lib/mimetypes.lib, above the "mime_view_zip ()" function:

function mime_view_rar ($mime) {
   global $default;

   $contents = MimeFetchContent($mime);
   $rar_name = tempnam('/tmp', 'imp.rar');
   horde_cleanup($rar_name);

   $fh = fopen($rar_name, 'w');
   fwrite($fh, imap_base64($contents));
   fclose($fh);

   $pipe = popen("$default->path_to_rar l $rar_name 2>&1", 'r');
   $data = "<b><u>Contents of RAR archive</u></b>".
           "<br><table><tr><td align=left><pre>";
   $re = '';
   while (($rc=fgets($pipe,10)))
     $re .= $rc;
   pclose($pipe);
   $data .= htmlspecialchars($re);
   $data .= "</pre></td></tr></table>";

   $pipe = popen("$default->path_to_rar t -idp $rar_name 2>&1", 'r');
   $data .= "<b><u>Test of RAR archive</u></b>".
            "<br><table><tr><td align=left><pre>";
   $re = '';
   while (($rc=fgets($pipe,10)))
     $re .= $rc;
   pclose($pipe);
   $data .= htmlspecialchars($re);
   $data .= "</pre></td></tr></table>";

   return $data;
}


In ./imp/config/defaults.php3:

$default->path_to_rar = '/usr/local/bin/rar';


In ./imp/config/mime.php3:

( Somewhere around $mime_actions['application/zip'] )

// .rar - Uses RAR.
// By: Joaquim Homrighausen <joho@webbplatsen.se>
// Define $default->path_to_rar in defaults.php3.

$mime_actions['application/x-rar-compressed'] =
array(
      'action'          => 'default',
      'view'            => true,
      'view_function'   => 'mime_view_rar',
      'download'        => true,
      'icon'            => 'mime_compressed.gif'
      );





:: Who dares wins ::