Description: <short summary of the patch>
 TODO: Put a short summary on the line above and replace this paragraph
 with a longer explanation of this change. Complete the meta-information
 with other relevant fields (see below for details). To make it easier, the
 information below has been extracted from the changelog. Adjust it or drop
 it.
 .
 squirrelmail-attachment-tnef (1.0-1) unstable; urgency=low
 .
   * Initial release (Closes: #nnnn)  <nnnn is the bug number of your ITP>
Author: Jean-Denis Gebhardt <jean-denis.gebhardt@noris.net>

---
The information above should follow the Patch Tagging Guidelines, please
checkout http://dep.debian.net/deps/dep3/ to learn about the format. Here
are templates for supplementary fields that you might want to add:

Origin: <vendor|upstream|other>, <url of original patch>
Bug: <url in upstream bugtracker>
Bug-Debian: http://bugs.debian.org/<bugnumber>
Bug-Ubuntu: https://launchpad.net/bugs/<bugnumber>
Forwarded: <no|not-needed|url proving that it has been forwarded>
Reviewed-By: <name and email of someone who approved the patch>
Last-Update: <YYYY-MM-DD>

--- /dev/null
+++ squirrelmail-attachment-tnef-1.0/Makefile
@@ -0,0 +1,5 @@
+build:
+
+install: build
+	mkdir -p ${DESTDIR}/usr/share/squirrelmail/plugins/
+	cp -a attachment_tnef ${DESTDIR}/usr/share/squirrelmail/plugins/
--- /dev/null
+++ squirrelmail-attachment-tnef-1.0/attachment_tnef/functions.php
@@ -0,0 +1,192 @@
+<?php
+
+/*
+ * functions.php
+ *
+ *  Bernd Wiegmann <bernd@wib-software.de>
+ *  Graham Norbury <gnorbury@bondcar.com>
+ *  (c) 2002 (GNU GPL - see ../../COPYING)
+ *
+ */
+
+/*
+ *   $Header: /storage/repository/attachment_tnef/functions.php,v 1.5 2003/10/10 12:50:52 bernd Exp $
+ *
+ *   $Log: functions.php,v $
+ *   Revision 1.5  2003/10/10 12:50:52  bernd
+ *   Don't try to hide the warning attachment. This prevented some attachments
+ *   to be shown at all.
+ *
+ *   Revision 1.4  2003/09/11 11:36:45  bernd
+ *   Preparations for beta release.
+ *
+ *   Revision 1.2  2003/07/31 15:24:25  bernd
+ *   Complete rework of tnef decoder
+ *
+ *   Revision 1.1.1.1  2003/07/02 09:12:46  bernd
+ *   initial import into CVS
+ *
+ */
+
+$ext_mime_array = array( '.gif' => 'image/gif',
+			 '.jpg' => 'image/jpg',
+			 '.png' => 'image/png',
+			 '.vcf' => 'text/x-vcard',
+			 '.zip' => 'application/zip',
+			 '.rtf' => 'application/rtf',
+			 '.pdf' => 'application/pdf'
+			 );
+
+function ext_to_mime($extension) {
+  global $ext_mime_array;
+
+  return  $ext_mime_array[$extension];
+}
+
+/*
+ *  Generate browser-specific headers to initiate file download.
+ *
+ *  The following logic is a cleaned up version of ../../src/download.php
+ *  which has been modified to include a Content-Length: header needed to
+ *  enable the the download progress bar to work correctly.
+ *
+ *  Ideally this should be a generic method in the ../../functions hierachy
+ *  so it can be called directly without getting all the other html gunk
+ *  created by download.php.
+ *
+ */
+
+function DumpHeaders($type, $filename, $length, $force)
+{
+   global $HTTP_USER_AGENT;
+
+   $isIE = 0;
+   if (strstr($HTTP_USER_AGENT, 'compatible; MSIE ') !== false &&
+       strstr($HTTP_USER_AGENT, 'Opera') === false)
+   {
+      $isIE = 1;
+   }
+
+   $filename = ereg_replace('[^-a-zA-Z0-9\.]', '_', $filename);
+
+   // A Pox on Microsoft and it's Office!
+   if (!$force)
+   {
+      // Try to show in browser window
+      header("Content-Disposition: inline; filename=\"$filename\"");
+      header("Content-Type: $type; name=\"$filename\"");
+      header("Content-Length: $length");
+   }
+   else
+   {
+      // Try to pop up the "save as" box
+      if ($isIE)
+      {
+         header("Content-Disposition: inline; filename=$filename");
+         header("Content-Type: application/download; name=\"$filename\"");
+         header("Content-Length: $length");
+      }
+      else
+      {
+         header("Content-Disposition: attachment; filename=\"$filename\"");
+         header("Content-Type: application/octet-stream; name=\"$filename\"");
+         header("Content-Length: $length");
+      }
+   }
+}
+
+/*
+ * Just a little helper for $tnef_debug == 1
+ * Will not create any output in production environment.
+ */
+
+function tnef_log($string)
+{
+  error_log($string . "\n", 3, "/tmp/tnef.log");
+}
+
+function attachment_tnef_link_do(&$Args)
+{
+  $Args[1]['attachment_tnef']['href'] = '../plugins/attachment_tnef/tnef.php?startMessage=' .
+    $Args[2] . '&passed_id=' . $Args[3] . '&mailbox=' .
+    $Args[4] . '&passed_ent_id=' . $Args[5];
+
+  if (isset($where) &&
+      isset($what))
+    {
+      $Args[1]['attachment_tnef']['href'] .= '&where=' . urlencode($Args[8]) .
+	'&what=' . urlencode($Args[9]);
+    }
+
+  $Args[1]['attachment_tnef']['text'] = _("view");
+  $Args[6] = $Args[1]['attachment_tnef']['href'];
+}
+
+function attachment_tnef_preview_do()
+{
+  // TODO
+  // Display a list of attachments under the tnef file so the user
+  // does not have to click on "view" to directly access its contents
+}
+
+function tnef_getx($size, &$buf)
+{
+   $value = null;
+   $len = strlen($buf);
+   if ($len >= $size)
+   {
+      $value = substr($buf, 0, $size);
+      $buf = substr_replace($buf, '', 0, $size);
+   } else {
+     substr_replace($buf, '', 0, $len);
+   }
+   return $value;
+}
+
+function tnef_geti8(&$buf)
+{
+   $value = null;
+   $len = strlen($buf);
+   if ($len >= 1)
+   {
+      $value = ord($buf{0});
+      $buf = substr_replace($buf, '', 0, 1);
+   } else {
+     substr_replace($buf, '', 0, $len);
+   }
+   return $value;
+}
+
+function tnef_geti16(&$buf)
+{
+   $value = null;
+   $len = strlen($buf);
+   if ($len >= 2)
+   {
+      $value = ord($buf{0}) +
+               (ord($buf{1}) << 8);
+      $buf = substr_replace($buf, '', 0, 2);
+   } else {
+     substr_replace($buf, '', 0, $len);
+   }
+   return $value;
+}
+
+function tnef_geti32(&$buf)
+{
+   $value = null;
+   $len = strlen($buf);
+   if ($len >= 4)
+   {
+      $value = ord($buf{0}) +
+               (ord($buf{1}) << 8) +
+               (ord($buf{2}) << 16) +
+               (ord($buf{3}) << 24);
+      $buf = substr_replace($buf, '', 0, 4);
+   } else {
+     substr_replace($buf, '', 0, $len);
+   }
+   return $value;
+}
+
+?>
--- /dev/null
+++ squirrelmail-attachment-tnef-1.0/attachment_tnef/INSTALL
@@ -0,0 +1,13 @@
+Installing the attachment tnef Plugin
+=====================================
+
+Simply untar the file in the plugins directory:
+
+  $ cd plugins
+  $ tar -zxvf /wherever..../attachment_tnef-0.70-1.4.0.tar.gz
+
+Then go to your config directory and run conf.pl.  Choose option
+8 and add the plugin.  Save and exit, then that should be all.
+
+  $ cd ../config
+  $ ./conf.pl
--- /dev/null
+++ squirrelmail-attachment-tnef-1.0/attachment_tnef/README
@@ -0,0 +1,53 @@
+TNEF Attachment Decoder v0.70
+http://www.wib-software.de/squirrel/ 
+
+bernd@wib-software.de (Bernd Wiegmann) since Version 0.3
+gnorbury@bondcar.com
+
+Description
+-----------
+A squirrelmail plugin to open and extract embedded attachments from ms-tnef encoded
+files such as "winmail.dat".  (As generated by Microsoft Outlook and friends)
+
+With this plugin enabled, an extra "view" option will be added to the available
+hyperlinks whenever a file of mime-type 'application/ms-tnef' is received. After
+selecting this link, you will be taken to a page displaying the contents of the
+file, and given the opportunity to download one or more of the attachments.
+
+Releasenote
+-----------
+This is a complete rewrite of the tnef decoding engine. Additional eMail attributes
+are now displayed and embedded RTF attachments are also decoded.
+RTF Files smaller than 250 Bytes are not shown. The small files I found in the
+attachments were all empty. In most cases the mail itself is also included as a
+RTF File and if the mail itself contains no text, the RTF File is empty as well.
+Before you mail me about empty files please check that there should be something
+else.
+I tried to hide the attachment with the warning message but this provented other
+attachments from beeing displayed at all. Now all attachments are shown with the
+exception of the small rtf files.
+
+Known Bugs
+----------
+Currently the plugin has only been extensively tested with IE 6.0, and somewhat
+less with Solaris Netscape Communicator 4.76.  Since differences do exist between
+browsers, it is more than likely there are still some glitches in the "download" code. 
+
+I don't have an embedded uncompressed RTF attachment and I haven't been able to test
+it and there may be still a bug in this part of the code.
+
+To Do
+-----
+Better integration in SM.
+Reorganize the class structure to eliminate the warning attachments.
+
+Change History
+--------------
+v0.1  2002-06-01 : Initial version
+v0.2  2002-08-26 : Fixed bug with embedded messages.  Now decodes recursively!
+v0.3  2003-06-09 : WIB: Adapted plugin for SquirrelMail 1.4
+v0.4  2003-06-12 : WIB: Now the plugin can be used with PHP's register_globals=off
+v0.5  2003-07-14 : WIB: Removed broken code and fixed translations
+v0.55 2003-09-11 : WIB: The plugin decodes a lot more attributes (beta release)
+v0.6  2003-10-08 : WIB: Compressed RTF decoding implemented.
+v0.7  2003-10-10 : WIB: Bugfixes for nested attachments.
\ No newline at end of file
--- /dev/null
+++ squirrelmail-attachment-tnef-1.0/attachment_tnef/debug_functions.php
@@ -0,0 +1,426 @@
+<?php
+
+/*
+ * debug_functions.php
+ *
+ *  Bernd Wiegmann <bernd@wib-software.de>
+ *  (c) 2003 (GNU GPL - see ../../COPYING)
+ *
+ */
+
+/*
+ *   $Header: /storage/repository/attachment_tnef/debug_functions.php,v 1.1 2003/07/31 15:24:25 bernd Exp $
+ *
+ *   $Log: debug_functions.php,v $
+ *   Revision 1.1  2003/07/31 15:24:25  bernd
+ *   Complete rework of tnef decoder
+ *
+ *
+ */
+
+include_once(SM_PATH . 'plugins/attachment_tnef/functions.php');
+
+function show_tnef_attribute($attribute, $value, $length) {
+  switch($attribute)    {
+  case TNEF_ABODYTEXT:
+    tnef_log(sprintf("TNEF attribute: <b>Embedded message:</b><pre>%s</pre>",$value));
+    break;
+
+  case TNEF_ASUBJECT:
+    $value = substr($value, 0, $length - 1);
+    tnef_log("TNEF attribute: Subject($length)='$value'");
+    break;
+
+  case TNEF_AVERSION:
+    $value = tnef_geti32($value);
+    tnef_log(sprintf("TNEF attribute: TNEF Version = 0x%x", $value));
+    break;
+
+  case TNEF_AOEMCODEPAGE:
+    tnef_log("TNEF attribute: Codepage BYTEs ($length)");
+    break;
+
+  case TNEF_ASTATUS:
+    $value = tnef_geti8($value);
+    tnef_log("TNEF attribute: Message Status=$value");
+    break;
+
+  case TNEF_AMCLASS:
+    $value = substr($value, 0, $length - 1);
+    tnef_log("TNEF attribute: Message Class DWORDs ($length) as String='$value'");
+    break;
+
+  case TNEF_AREQUESTRES:
+    $value = tnef_geti16($value);
+    tnef_log("TNEF attribute: Request Res=$value");
+    break;
+
+  case TNEF_ADATERECEIVED:
+    tnef_log("TNEF attribute: Date received ($length)");
+    break;
+
+  case TNEF_ADATESENT:
+    tnef_log("TNEF attribute: Date sent ($length)");
+    break;
+
+  case TNEF_ADATEMODIFIED:
+    tnef_log("TNEF attribute: Date modified ($length)");
+    break;
+
+  case TNEF_AIDOWNER:
+    $value = tnef_geti32($value);
+    tnef_log("TNEF attribute: ID Owner=$value");
+    break;
+
+  case TNEF_AMESSAGEID:
+    $value = substr($value, 0, $length - 1);
+    tnef_log("TNEF attribute: Message Id='$value'");
+    break;
+
+  case TNEF_APRIORITY:
+    $value = tnef_geti16($value);
+    tnef_log("TNEF attribute: Priority=$value");
+    break;
+
+  case TNEF_AMAPIPROPS:
+    tnef_log("TNEF attribute: MAPI Props ($length)");
+    break;
+
+  case TNEF_AATTACHCREATEDATE:
+    tnef_log("TNEF attribute: Date Attachment created ($length)");
+    break;
+
+  case TNEF_AATTACHMODDATE:
+    tnef_log("TNEF attribute: Date Attachment modified ($length)");
+    break;
+
+  case TNEF_AFROM:
+    tnef_log("TNEF attribute: From (Triples) ($length)");
+    break;
+
+  case TNEF_ARENDDATA:
+    tnef_log("TNEF attribute: ARENDDATA ($length)");
+    break;
+
+  case TNEF_AMAPIATTRS:
+    tnef_log("TNEF attribute: Mapi Attribs ($length)");
+    break;
+
+  case TNEF_AMAPIPROPS:
+    tnef_log("TNEF attribute: Mapi Properties ($length)");
+    break;
+
+  case TNEF_AFILENAME:
+    $value = substr($value, 0, $length - 1);
+    tnef_log("TNEF attribute: Filename='$value'");
+    break;
+
+  case TNEF_ATTACHDATA:
+    tnef_log("TNEF attribute: Attachment Data ($length)");
+    break;
+
+  case TNEF_ATTACHMETAFILE:
+    tnef_log("TNEF attribute: Attach Metafile ($length)");
+    break;
+    
+  default:
+    tnef_log(sprintf("TNEF attribute: [%08x] %d bytes", $attribute, $length));
+    break;
+  }
+}
+
+function show_mapi_attribute($attr_type, $attr_name, $value, $length) {
+
+  switch($attr_name) {
+  case TNEF_MAPI_ATTACH_LONG_FILENAME: // used in preference to AFILENAME value
+    $name = ereg_replace('.*[\/](.*)$', '\1', $value); // strip path
+    tnef_log("MAPI Filename = '$name'");
+    break;
+
+  case TNEF_MAPI_DISPLAY_NAME: // Just to test
+    tnef_log("MAPI Displayname='$value'");
+    break;
+
+  case TNEF_MAPI_ATTACH_MIME_TAG: // Is this ever set, and what is the format?
+    $type0 = ereg_replace('^(.*)/.*', '\1', $value);
+    $type1 = ereg_replace('.*/(.*)$', '\1', $value);
+    tnef_log("MAPI type0=$type0 type1=$type1");
+    break;
+
+  case TNEF_MAPI_ATTACH_DATA:
+    tnef_log("MAPI Attachment. Length=$length");
+    break;
+
+  case TNEF_MAPI_NORMALIZED_SUBJECT:
+    tnef_log("MAPI Normalized Subject=$value");
+    break;
+
+  case TNEF_MAPI_ATTACH_SIZE:
+    tnef_log("MAPI Attach Size=$value");
+    break;
+
+  case TNEF_MAPI_ATTACH_NUM:
+    tnef_log("MAPI Attach Num=$value");
+    break;
+
+  case TNEF_MAPI_RENDERING_POSITION:
+    tnef_log("MAPI Rendering Position=$value");
+    break;
+
+  case TNEF_MAPI_ACCESS_LEVEL:
+    tnef_log("MAPI Access Level=$value");
+    break;
+
+  case TNEF_MAPI_CREATION_TIME:
+    tnef_log("MAPI Creation Time");
+    break;
+
+  case TNEF_MAPI_MODIFICATION_TIME:
+    tnef_log("MAPI Modification Time");
+    break;
+
+  case TNEF_MAPI_ATTACH_METHOD:
+    tnef_log("MAPI Attach Method=$value");
+    break;
+
+  case TNEF_MAPI_ATTACH_ENCODING:
+    tnef_log("MAPI Attach Encoding");
+    break;
+
+  case TNEF_MAPI_ATTACH_EXTENSION:
+    tnef_log("MAPI Attach Extension='$value'");
+    break;
+
+  case TNEF_MAPI_ORIGINAL_AUTHOR:
+    tnef_log("MAPI Original Autor='$value'");
+    break;
+
+  case TNEF_MAPI_SENT_REP_NAME:
+    tnef_log("MAPI Sent Rep Name='$value'");
+    break;
+
+  case TNEF_MAPI_SENT_REP_ADDRTYPE:
+    tnef_log("MAPI Sent Rep Addrtype='$value'");
+    break;
+
+  case TNEF_MAPI_SENT_REP_EMAIL_ADDR:
+    tnef_log("MAPI Sent Rep eMail Addr='$value'");
+    break;
+
+  case TNEF_MAPI_SUBJECT_PREFIX:
+    tnef_log("MAPI Subject Prefix='$value'");
+    break;
+
+  case TNEF_MAPI_CONVERSATION_TOPIC:
+    tnef_log("MAPI Conversation Topic='$value'");
+    break;
+
+  case TNEF_MAPI_MAPPING_SIGNATURE:
+    tnef_log("MAPI Mapping Signature");
+    break;
+
+  case TNEF_MAPI_RECORD_KEY:
+    tnef_log("MAPI Record Key");
+    break;
+
+  case TNEF_MAPI_STORE_RECORD_KEY:
+    tnef_log("MAPI Store Record Key");
+    break;
+
+  case TNEF_MAPI_STORE_ENTRY_ID:
+    tnef_log("MAPI Store Entry ID");
+    break;
+
+  case TNEF_MAPI_OBJECT_TYPE:
+    tnef_log("MAPI Object Type=$value");
+    break;
+
+  case TNEF_MAPI_RTF_SYNC_BODY_TAG:
+    tnef_log("MAPI RTF SYNC Body Tag=$value");
+    break;
+
+  case TNEF_MAPI_RTF_COMPRESSED:
+    tnef_log("MAPI RTF Compressed=($length)");
+    break;
+
+  case TNEF_MAPI_ACCOUNT:
+    tnef_log("MAPI Account='$value'");
+    break;
+
+  case TNEF_MAPI_GENERATION:
+    tnef_log("MAPI Generation='$value'");
+    break;
+
+  case TNEF_MAPI_SENDER_NAME:
+    tnef_log("MAPI Sender Name='$value'");
+    break;
+
+  case TNEF_MAPI_SENDER_ADDRTYPE:
+    tnef_log("MAPI Sender Addrtype='$value'");
+    break;
+
+  case TNEF_MAPI_SENDER_EMAIL_ADDRESS:
+    tnef_log("MAPI Sender eMail Address='$value'");
+    break;
+
+  case TNEF_MAPI_GIVEN_NAME:
+    tnef_log("MAPI Given Name='$value'");
+    break;
+
+  case TNEF_MAPI_INITIALS:
+    tnef_log("MAPI Initials='$value'");
+    break;
+
+  case TNEF_MAPI_KEYWORDS:
+    tnef_log("MAPI Keywords='$value'");
+    break;
+
+  case TNEF_MAPI_LANGUAGE:
+    tnef_log("MAPI Language='$value'");
+    break;
+
+  case TNEF_MAPI_LOCATION:
+    tnef_log("MAPI Location='$value'");
+    break;
+
+  case TNEF_MAPI_SURNAME:
+    tnef_log("MAPI Surname='$value'");
+    break;
+
+  case TNEF_MAPI_COMPANY_NAME:
+    tnef_log("MAPI Company Name='$value'");
+    break;
+
+  case TNEF_MAPI_TITLE:
+    tnef_log("MAPI Title='$value'");
+    break;
+
+  case TNEF_MAPI_DEPARTMENT_NAME:
+    tnef_log("MAPI Department Name='$value'");
+    break;
+
+  case TNEF_MAPI_OFFICE_LOCATION:
+    tnef_log("MAPI Office Location='$value'");
+    break;
+
+  case TNEF_MAPI_COUNTRY:
+    tnef_log("MAPI Country='$value'");
+    break;
+
+  case TNEF_MAPI_LOCALTY:
+    tnef_log("MAPI Localty='$value'");
+    break;
+
+  case TNEF_MAPI_STATE_OR_PROVINCE:
+    tnef_log("MAPI State or Province='$value'");
+    break;
+
+  case TNEF_MAPI_MIDDLE_NAME:
+    tnef_log("MAPI Middle Name='$value'");
+    break;
+
+  case TNEF_MAPI_DISPLAYNAME_PREFIX:
+    tnef_log("MAPI Display Name Prefix='$value'");
+    break;
+
+  case TNEF_MAPI_BUSINESS_TEL_NUMBER:
+    tnef_log("MAPI Business Telefone='$value'");
+    break;
+
+  case TNEF_MAPI_BUSINESS2_TEL_NUMBER:
+    tnef_log("MAPI Business 2 Telefone='$value'");
+    break;
+
+  case TNEF_MAPI_HOME_TEL_NUMBER:
+    tnef_log("MAPI Home Telefone='$value'");
+    break;
+
+  case TNEF_MAPI_PRIMARY_TEL_NUMBER:
+    tnef_log("MAPI Primary Telefone='$value'");
+    break;
+
+  case TNEF_MAPI_POSTAL_ADDRESS:
+    tnef_log("MAPI Postal Address='$value'");
+    break;
+
+  case TNEF_MAPI_MOBILE_TEL_NUMBER:
+    tnef_log("MAPI Mobile Telefone='$value'");
+    break;
+
+  case TNEF_MAPI_RADIO_TEL_NUMBER:
+    tnef_log("MAPI Radio Telefone='$value'");
+    break;
+
+  case TNEF_MAPI_CAR_TEL_NUMBER:
+    tnef_log("MAPI Car Telefone='$value'");
+    break;
+
+  case TNEF_MAPI_OTHER_TEL_NUMBER:
+    tnef_log("MAPI Other Telefone='$value'");
+    break;
+
+  case TNEF_MAPI_PAGER_TEL_NUMBER:
+    tnef_log("MAPI Pager Telefone='$value'");
+    break;
+
+  case TNEF_MAPI_PRIMARY_FAX_NUMBER:
+    tnef_log("MAPI Primary Fax='$value'");
+    break;
+
+  case TNEF_MAPI_BUSINESS_FAX_NUMBER:
+    tnef_log("MAPI Business Fax='$value'");
+    break;
+
+  case TNEF_MAPI_TELEX_NUMBER:
+    tnef_log("MAPI Telex Number='$value'");
+    break;
+
+  case TNEF_MAPI_ISDN_NUMBER:
+    tnef_log("MAPI ISDN Number='$value'");
+    break;
+
+  case TNEF_MAPI_HOME_FAX_NUMBER:
+    tnef_log("MAPI Home Fax='$value'");
+    break;
+
+  case TNEF_MAPI_ASSISTANT_TEL_NUMBER:
+    tnef_log("MAPI Assistant Telefone='$value'");
+    break;
+
+  case TNEF_MAPI_HOME2_TEL_NUMBER:
+    tnef_log("MAPI Home Telefone='$value'");
+    break;
+
+  case TNEF_MAPI_STREET_ADDRESS:
+    tnef_log("MAPI Street Address='$value'");
+    break;
+
+  case TNEF_MAPI_POSTAL_CODE:
+    tnef_log("MAPI Postal Code='$value'");
+    break;
+
+  case TNEF_MAPI_POST_OFFICE_BOX:
+    tnef_log("MAPI Post Office Box='$value'");
+    break;
+
+  case TNEF_MAPI_NICKNAME:
+    tnef_log("MAPI Nickname='$value'");
+    break;
+
+  case TNEF_MAPI_PERSONAL_HOME_PAGE:
+    tnef_log("MAPI Personal Home Page='$value'");
+    break;
+
+  case TNEF_MAPI_BUSINESS_HOME_PAGE:
+    tnef_log("MAPI Business Home Page='$value'");
+    break;
+
+  default:
+    if ($attr_type == TNEF_MAPI_STRING) {
+      tnef_log(sprintf("mapi attribute %04x:%04x value='%s'", $attr_type, $attr_name, $value));
+    } else {
+      tnef_log(sprintf("mapi attribute %04x:%04x", $attr_type, $attr_name));
+    }
+    break;
+  }
+}
--- /dev/null
+++ squirrelmail-attachment-tnef-1.0/attachment_tnef/index.php
@@ -0,0 +1,29 @@
+<?php
+
+/*
+ *   $Header: /storage/repository/attachment_tnef/index.php,v 1.1.1.1 2003/07/02 09:12:46 bernd Exp $
+ *
+ *   $Log: index.php,v $
+ *   Revision 1.1.1.1  2003/07/02 09:12:46  bernd
+ *   initial import into CVS
+ *
+ */
+    
+/**
+ * index.php
+ *
+ * Copyright (c) 1999-2003 The SquirrelMail Project Team
+ * Licensed under the GNU GPL. For full terms see the file COPYING.
+ *
+ * This file simply takes any attempt to view source files and sends those
+ * people to the login screen. At this point no attempt is made to see if
+ * the person is logged or not.
+ *
+ * $Id: index.php,v 1.1.1.1 2003/07/02 09:12:46 bernd Exp $
+ */
+
+header("Location:../index.php");
+
+/* pretty impressive huh? */
+
+?>
--- /dev/null
+++ squirrelmail-attachment-tnef-1.0/attachment_tnef/setup.php
@@ -0,0 +1,62 @@
+<?php
+
+/*
+ * functions.php
+ *
+ *  Bernd Wiegmann <bernd@wib-software.de>
+ *  Graham Norbury <gnorbury@bondcar.com>
+ *  (c) 2002 (GNU GPL - see ../../COPYING)
+ *
+ */
+
+/*
+ *   $Header: /storage/repository/attachment_tnef/setup.php,v 1.1.1.1 2003/07/02 09:12:46 bernd Exp $
+ *
+ *   $Log: setup.php,v $
+ *   Revision 1.1.1.1  2003/07/02 09:12:46  bernd
+ *   initial import into CVS
+ *
+ */
+
+/*
+ *  Allows an attachment of mime type application/ms-tnef (winmail.dat) to be
+ *  opened and its contents downloaded.
+ *
+ *  This file mostly copied and adapted from attachment_common.php
+ *
+ */
+
+function attachment_tnef_version()
+{
+  return '0.4';
+}
+   
+function squirrelmail_plugin_init_attachment_tnef()
+{
+  global $squirrelmail_plugin_hooks;
+
+  $squirrelmail_plugin_hooks['attachment application/ms-tnef']['attachment_tnef'] = 'attachment_tnef_link';
+  $squirrelmail_plugin_hooks['read_body_bottom']['attachment_tnef'] = 'attachment_tnef_preview';
+}
+
+function attachment_tnef_link(&$Args)
+{
+  if (defined('SM_PATH'))
+    include_once(SM_PATH . 'plugins/attachment_tnef/functions.php');
+  else
+    include_once('../plugins/attachment_tnef/functions.php');
+
+  attachment_tnef_link_do($Args);
+}
+
+function attachment_tnef_preview()
+{
+  if (defined('SM_PATH'))
+    include_once(SM_PATH . 'plugins/attachment_tnef/functions.php');
+  else
+    include_once('../plugins/attachment_tnef/functions.php');
+
+  attachment_tnef_preview_do();
+}
+
+?>
--- /dev/null
+++ squirrelmail-attachment-tnef-1.0/attachment_tnef/tnef.php
@@ -0,0 +1,274 @@
+<?php
+
+/*
+ * tnef.php
+ *
+ *  Bernd Wiegmann <bernd@wib-software.de>
+ *  Graham Norbury <gnorbury@bondcar.com>
+ *  (c) 2002 (GNU GPL - see ../../COPYING)
+ *
+ */
+
+/*
+ *   $Header: /storage/repository/attachment_tnef/tnef.php,v 1.22 2003/10/10 12:50:52 bernd Exp $
+ *
+ *   $Log: tnef.php,v $
+ *   Revision 1.22  2003/10/10 12:50:52  bernd
+ *   Don't try to hide the warning attachment. This prevented some attachments
+ *   to be shown at all.
+ *
+ *   Revision 1.21  2003/10/08 15:34:26  bernd
+ *   Fixed some bugs.
+ *
+ *   Revision 1.20  2003/10/08 15:29:23  bernd
+ *   Removed old warning message about RTF attachments.
+ *
+ *   Revision 1.19  2003/10/08 15:19:36  bernd
+ *   Display also RTF attachments and don't show useless attachments like to small
+ *   RTF files or warning messages.
+ *
+ *   Revision 1.18  2003/09/11 11:36:45  bernd
+ *   Preparations for beta release.
+ *
+ *   Revision 1.2  2003/07/12 21:54:10  bernd
+ *   Removed broken code that caused warnings and changed some messages which are now translatable.
+ *
+ *   Revision 1.1.1.1  2003/07/02 09:12:46  bernd
+ *   initial import into CVS
+ *
+ */
+    
+/* 
+ *  Displays table of contents and handles attachment download for ms-tnef files
+ *
+ */
+
+   if (!defined('SM_PATH')) {
+      define('SM_PATH', '../../'); 
+   }
+
+   include_once(SM_PATH . 'include/validate.php');
+
+   include_once(SM_PATH . 'functions/date.php');
+   include_once(SM_PATH . 'functions/page_header.php');
+   include_once(SM_PATH . 'functions/mime.php');
+
+   include_once(SM_PATH . 'plugins/attachment_tnef/tnef_attachment.php');
+
+   header("Pragma: ");
+   header("Cache-Control: cache");
+
+   sqgetGlobalVar('tnef_debug', $tnef_debug, SQ_SESSION);
+   sqgetGlobalVar('tnef_download', $tnef_download, SQ_SESSION);
+
+   sqgetGlobalVar('absolute_dl', $absolute_dl);
+   sqgetGlobalVar('file_id', $file_id);
+   sqgetGlobalVar('key', $key, SQ_COOKIE);
+   sqgetGlobalVar('mailbox', $mailbox);
+   sqgetGlobalVar('passed_ent_id', $passed_ent_id);
+   sqgetGlobalVar('passed_id', $passed_id);
+   sqgetGlobalVar('startMessage', $startMessage);
+   sqgetGlobalVar('username', $username);
+
+   $tnef_debug = 0; // change this to 1 to enable debugging output
+
+   $tnef_download = (!isset($file_id)) ? 0 : 1;       // only display page if not downloading
+   $tnef_debug = ((!$tnef_download) && $tnef_debug);  // debugging disabled when downloading
+
+   sqsession_register($tnef_download, 'tnef_download');
+   sqsession_register($tnef_debug, 'tnef_debug');
+
+   // extract the tnef attachment and decode it
+   $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
+   sqimap_mailbox_select($imapConnection, $mailbox);
+   $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
+   $entity_tnef = getEntity($message,$passed_ent_id);
+
+   $tnef = mime_fetch_body ($imapConnection, $passed_id, $passed_ent_id); 
+   $tnef = decodeBody($tnef, $entity_tnef->header->encoding);
+
+   $attachment = &new TnefAttachment($tnef_debug);
+   $result = $attachment->decodeTnef($tnef);
+   $tnef_files = &$attachment->getFilesNested();
+
+   if (!$tnef_download)  // only display page if not downloading
+   {
+      displayPageHeader($color, "None");
+
+?>
+<br>
+<table width="100%" border="0" cellspacing="0" cellpadding="2" align="center">
+ <tr>
+  <td bgcolor="<?php echo $color[0]; ?>">
+   <b><center>
+<?php
+
+      echo _("Viewing") . " - ";
+      if (isset($where) && isset($what))
+      {
+         // from a search
+         echo "<a href=\"../../src/read_body.php?mailbox=" . urlencode($mailbox) .
+              "&passed_id=$passed_id&where=" . urlencode($where) .
+              "&what=".urlencode($what) . "\">" . _("View message") . "</a>";
+      }
+      else
+      {   
+         echo "<a href=\"../../src/read_body.php?mailbox=" . urlencode($mailbox) .
+              "&passed_id=$passed_id&startMessage=$startMessage&show_more=0\">" .
+              _("View message") . "</a>";
+      }   
+      echo "</center></b></td></tr></table>";
+
+      // IMHO the following html is very difficult to interpret...
+      // For consistency with the way other attachments are displayed
+      // this is more or less a straight copy from mime.php
+      $body = "<TABLE WIDTH=\"100%\" CELLSPACING=0 CELLPADDING=2 " .
+              "BORDER=0 BGCOLOR=\"$color[0]\"><TR>\n" .
+              "<TH ALIGN=\"left\" BGCOLOR=\"$color[9]\"><B>\n" .
+              _("Mail Infos") . ':' .  "</B></TH></TR><TR><TD>\n" .
+              "<TABLE CELLSPACING=0 CELLPADDING=1 BORDER=0>\n";
+
+      $mailinfo = &$attachment->getMailinfo();
+      $subject = $mailinfo->getSubject();
+      $topic = $mailinfo->getTopic();
+      $from_mail = $mailinfo->getFrom();
+      $from_name = $mailinfo->getFromName();
+      $obj = &$mailinfo->getDateSent();
+
+      if ($subject) {
+	$body .= '<TR><TD>&nbsp;&nbsp;</TD><TD><B>' . _("Subject") . ':</B></TD><TD>' . $subject . '</TD></TR>';
+      }
+      if (($topic) && ($topic != $subject)) {
+	$body .= '<TR><TD>&nbsp;&nbsp;</TD><TD><B>' . _("Topic") . ':</B></TD><TD>' . $topic . '</TD></TR>';
+      }
+      if ($from_name) {
+	$body .= '<TR><TD>&nbsp;&nbsp;</TD><TD><B>' . _("Name") . ':</B></TD><TD>' . $from_name . '</TD></TR>';
+      }
+      if ($from_mail) {
+	$body .= '<TR><TD>&nbsp;&nbsp;</TD><TD><B>' . _("Name") . ':</B></TD><TD>' . $from_mail . '</TD></TR>';
+      }
+      if ($obj) {
+	$body .= '<TR><TD>&nbsp;&nbsp;</TD><TD><B>' . _("Date") . ':</B></TD><TD>' . $obj->getString() . '</TD></TR>';
+      }
+
+      $body .= "</TABLE></TD></TR></TABLE>";
+      echo($body);
+
+      // IMHO the following html is very difficult to interpret...
+      // For consistency with the way other attachments are displayed
+      // this is more or less a straight copy from mime.php
+      $body = "<TABLE WIDTH=\"100%\" CELLSPACING=0 CELLPADDING=2 " .
+              "BORDER=0 BGCOLOR=\"$color[0]\"><TR>\n" .
+              "<TH ALIGN=\"left\" BGCOLOR=\"$color[9]\"><B>\n" .
+              _("Attachments") . ':' .  "</B></TH></TR><TR><TD>\n" .
+              "<TABLE CELLSPACING=0 CELLPADDING=1 BORDER=0>\n";
+
+      $show_it = 0;
+      $id = 0;
+      foreach ($tnef_files as $file) {
+
+	if (get_class($file) != "tnefvcard") {
+	  $dl_href = 'tnef.php?' . $HTTP_SERVER_VARS['QUERY_STRING'] . "&file_id=$id";
+	  $body .= '<TR><TD>&nbsp;&nbsp;</TD><TD>' .
+	    "<A HREF=\"$dl_href\">" . $file->getName() . "</A>&nbsp;</TD>" .
+	    '<TD><SMALL><b>' . show_readable_size($file->getSize()) .
+	    '</b>&nbsp;&nbsp;</small></TD>' .
+	    sprintf("<TD><SMALL>[ %s ]&nbsp;</SMALL></TD>", $file->getType() ) .
+	    '<TD><SMALL></SMALL></TD><TD><SMALL>&nbsp;' .
+	    "<A HREF=\"$dl_href&absolute_dl=1\">" . _("download") . "</A>" .
+	    "</SMALL></TD></TR>\n";
+	  $show_it = 1;
+	}
+	$id++;
+      }
+
+      $body .= "</TABLE></TD></TR></TABLE>";
+
+      if ($show_it > 0) {
+	echo($body);
+      }
+
+      foreach ($tnef_files as $file) {
+
+	if (get_class($file) == "tnefvcard") {
+	  // IMHO the following html is very difficult to interpret...
+	  // For consistency with the way other attachments are displayed
+	  // this is more or less a straight copy from mime.php
+	  $body = "<TABLE WIDTH=\"100%\" CELLSPACING=0 CELLPADDING=2 " .
+	    "BORDER=0 BGCOLOR=\"$color[0]\"><TR>\n" .
+	    "<TH ALIGN=\"left\" BGCOLOR=\"$color[9]\"><B>\n" .
+	    _("Contact Information for") . ':&nbsp;' . $file->getName() . "</B></TH></TR><TR><TD>\n" .
+	    "<TABLE CELLSPACING=0 CELLPADDING=1 BORDER=0>\n";
+
+	  $value = $file->getGivenName();
+	  if ($value) {
+	    $disp .= $value;
+	  }
+	  $value = $file->getMiddleName();
+	  if ($value) {
+	    $disp .= ' ' . $value;
+	  }
+	  $value = $file->getSurname();
+	  if ($value) {
+	    $disp .= ' ' . $value;
+	  }
+	  if ($disp) {
+	    $body .= '<TR><TD>&nbsp;&nbsp;</TD><TD><B>' . _("Name") . ':</B></TD><TD>' . $disp . '</TD></TR>';
+	  }
+	  unset($disp);
+
+	  $disp = $file->getCompany();
+	  if ($disp) {
+	    $body .= '<TR><TD>&nbsp;&nbsp;</TD><TD><B>' . _("Company") . ':</B></TD><TD>' . $disp . '</TD></TR>';
+	  }
+	  unset($disp);
+
+	  $telefones = &$file->getTelefones();
+	  ksort($telefones);
+	  foreach ($telefones as $telkey => $telvalue) {
+	    $body .= '<TR><TD>&nbsp;&nbsp;</TD><TD><B>' . _($telkey) . ':</B></TD><TD>' . $telvalue . '</TD></TR>';
+	  }
+
+	  $emails = &$file->getEmails();
+	  ksort($emails);
+	  foreach ($emails as $emailkey => $emailvalue) {
+	    $disp = $emailvalue[EMAIL_DISPLAY];
+	    if (!$disp) {
+	      $disp = $emailkey;
+	    }
+	    $body .= '<TR><TD>&nbsp;&nbsp;</TD><TD><B>' . _($disp) . ':</B></TD><TD>' . $emailvalue[EMAIL_EMAIL] . '</TD></TR>';
+	    unset($disp);
+	  }
+	  $homepages = &$file->getHomepages();
+	  foreach ($homepages as $hpkey => $hpvalue) {
+	    $body .= '<TR><TD>&nbsp;&nbsp;</TD><TD><B>' . _($hpkey) . ':</B></TD><TD>' . $hpvalue . '</TD></TR>';
+	  }
+
+	  $body .= "</TABLE></TD></TR></TABLE>";
+	  echo $body;
+	}
+
+      }
+
+
+?>
+<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=2 ALIGN=CENTER>
+<TR><TD BGCOLOR="<?PHP echo $color[4] ?>">
+</TD></TR></TABLE>
+</body></html>
+<?PHP
+
+   }
+   else //download the requested attachment
+   {
+      set_time_limit(0); // disable 30 second timer in case download takes a while
+
+      DumpHeaders($tnef_files[$file_id]->getType(),
+                  $tnef_files[$file_id]->getName(),
+                  $tnef_files[$file_id]->getSize(),
+                  $absolute_dl);
+
+      echo($tnef_files[$file_id]->getContent());
+   }
+
+?>
--- /dev/null
+++ squirrelmail-attachment-tnef-1.0/attachment_tnef/tnef_attachment.php
@@ -0,0 +1,373 @@
+<?php
+
+/*
+ * tnef_attachment.php
+ *
+ *  Bernd Wiegmann <bernd@wib-software.de>
+ *  (c) 2003 (GNU GPL - see ../../COPYING)
+ *
+ */
+
+/*
+ *   $Header: /storage/repository/attachment_tnef/tnef_attachment.php,v 1.4 2003/10/10 12:50:52 bernd Exp $
+ *
+ *   $Log: tnef_attachment.php,v $
+ *   Revision 1.4  2003/10/10 12:50:52  bernd
+ *   Don't try to hide the warning attachment. This prevented some attachments
+ *   to be shown at all.
+ *
+ *   Revision 1.3  2003/10/08 15:19:36  bernd
+ *   Display also RTF attachments and don't show useless attachments like to small
+ *   RTF files or warning messages.
+ *
+ *   Revision 1.2  2003/09/19 15:51:27  bernd
+ *   First working version of the compressed RTF decoder.
+ *
+ *   Revision 1.1  2003/07/31 15:24:25  bernd
+ *   Complete rework of tnef decoder
+ *
+ *
+ */
+
+include_once(SM_PATH . 'plugins/attachment_tnef/debug_functions.php');
+include_once(SM_PATH . 'plugins/attachment_tnef/functions.php');
+include_once(SM_PATH . 'plugins/attachment_tnef/tnef_consts.php');
+include_once(SM_PATH . 'plugins/attachment_tnef/tnef_file.php');
+include_once(SM_PATH . 'plugins/attachment_tnef/tnef_mailinfo.php');
+include_once(SM_PATH . 'plugins/attachment_tnef/tnef_file_rtf.php');
+include_once(SM_PATH . 'plugins/attachment_tnef/tnef_vcard.php');
+
+class TnefAttachment {
+
+  var $tnef_debug;
+  var $mailinfo;
+  var $files;
+  var $files_nested;
+  var $attachments;
+  var $current_receiver;
+
+  function TnefAttachment($debug) {
+    $this->tnef_debug = $debug;
+    $this->files = array();
+    $this->attachments = array();
+    $this->mailinfo = & new TnefMailinfo;
+  }
+
+  function &getFiles() {
+    return $this->files;
+  }
+
+  function &getFilesNested() {
+    if (!$this->files_nested) {
+      $this->files_nested = array();
+
+      $num_attach = count($this->attachments);
+      if ($num_attach > 0) {
+	for ($cnt = 0; $cnt < $num_attach; $cnt++) {
+	  $this->addFiles($this->files_nested, $this->files);
+	  $this->addFiles($this->files_nested, $this->attachments[$cnt]->getFilesNested());
+	}
+      } else {
+	  $this->addFiles($this->files_nested, $this->files);
+      }
+    }
+
+    return $this->files_nested;
+  }
+
+  function addFiles(&$add_to, &$add) {
+    $num_files = count($add);
+    for ($cnt = 0; $cnt < $num_files; $cnt++) {
+      if ((get_class($add[$cnt]) != "tneffilertf") || ($add[$cnt]->getSize() > 250)) {
+	$add_to[] = &$add[$cnt];
+      }
+    }
+  }
+
+  function addFilesCond(&$add_to, &$add) {
+    $num_files = count($add);
+    for ($cnt = 0; $cnt < $num_files; $cnt++) {
+      if ((get_class($add[$cnt]) == "tneffilertf") && ($add[$cnt]->getSize() > 250)) {
+	$add_to[] = &$add[$cnt];
+      }
+    }
+  }
+
+  function &getAttachments() {
+    return $this->attachments;
+  }
+
+  function &getMailinfo() {
+    return $this->mailinfo;
+  }
+
+  function decodeTnef(&$buffer) {
+    $tnef_signature = tnef_geti32($buffer);
+    if ($tnef_signature == TNEF_SIGNATURE) {
+      $tnef_key = tnef_geti16($buffer);
+      if ($this->tnef_debug) {
+	tnef_log(sprintf("Signature: 0x%08x\nKey: 0x%04x\n", $tnef_signature, $tnef_key));
+      }
+
+      while (strlen($buffer) > 0) {
+	$lvl_type = tnef_geti8($buffer);
+
+	switch($lvl_type) {
+	case TNEF_LVL_MESSAGE:
+	  $this->tnef_decode_attribute($buffer);
+	  break;
+
+	case TNEF_LVL_ATTACHMENT:
+	  $this->tnef_decode_attribute($buffer);
+	  break;
+
+	default:
+	  if ($this->tnef_debug) {
+	    $len = strlen($buffer);
+	    if ($len > 0) {
+	      tnef_log("Invalid file format! Unknown Level $lvl_type. Rest=$len");
+	    }
+	  }
+	  break;
+	}
+      }
+    }
+    else {
+      if ($this->tnef_debug) {
+	tnef_log("Invalid file format! Wrong signature.");
+      }
+    }
+  }
+
+  function tnef_decode_attribute(&$buffer) {
+    $attribute = tnef_geti32($buffer);     // attribute if
+    $length = tnef_geti32($buffer);        // length
+    $value = tnef_getx($length, $buffer);  // data
+    tnef_geti16($buffer);                  // checksum
+
+    if ($this->tnef_debug) {
+      show_tnef_attribute($attribute, $value, $length);
+    }
+
+    switch($attribute) {    
+    case TNEF_ARENDDATA:                   // marks start of new attachment
+      if ($this->tnef_debug) {
+	tnef_log("Creating new File for Attachment");
+      }
+      $this->current_receiver = &new TnefFile($this->tnef_debug);
+      $this->files[] = &$this->current_receiver;
+      break;
+
+    case TNEF_AMAPIATTRS:
+      if ($this->tnef_debug) {
+	tnef_log("mapi attrs");
+      }
+      $this->extract_mapi_attrs($value);
+      break;
+
+    case TNEF_AMAPIPROPS:
+      if ($this->tnef_debug) {
+	tnef_log("mapi props");
+      }
+      $this->extract_mapi_attrs($value);
+      break;
+
+    case TNEF_AMCLASS:
+      $value = substr($value, 0, $length - 1);
+      if ($value == 'IPM.Contact') {
+	if ($this->tnef_debug) {
+	  tnef_log("Creating vCard Attachment");
+	}
+	$this->current_receiver = &new TnefvCard($this->tnef_debug);
+	$this->files[] = &$this->current_receiver;
+      }
+      break;
+
+    default:
+      $this->mailinfo->receiveTnefAttribute($attribute, $value, $length);
+      if ($this->current_receiver) {
+	$this->current_receiver->receiveTnefAttribute($attribute, $value, $length);
+      }
+      break;
+    }
+  }
+
+  function extract_mapi_attrs(&$buffer) {
+    $number = tnef_geti32($buffer); // number of attributes
+    $props = 0;
+    $ended = 0;
+
+    while ((strlen($buffer) > 0) && ($props < $number) && (!$ended)) {
+      $props++;
+      unset($value);
+      unset($named_id);
+      $length = 0;
+      $have_multivalue = 0;
+      $num_multivalues = 1;
+      $attr_type = tnef_geti16($buffer);
+      $attr_name = tnef_geti16($buffer);
+      
+      if (($attr_type & TNEF_MAPI_MV_FLAG) != 0) {
+	if ($this->tnef_debug) {
+	  tnef_log("Multivalue Attribute found.");
+	}
+	$have_multivalue = 1;
+	$attr_type = $attr_type & ~TNEF_MAPI_MV_FLAG;
+      }
+
+      if (($attr_name >= 0x8000) && ($attr_name < 0xFFFE)) {      // Named Attribute
+	$guid = tnef_getx(16, $buffer);
+	$named_type = tnef_geti32($buffer);
+	switch ($named_type) {
+	case TNEF_MAPI_NAMED_TYPE_ID:
+	  $named_id = tnef_geti32($buffer);
+	  $attr_name = $named_id;
+	  if ($this->tnef_debug) {
+	    tnef_log(sprintf("Named Id='0x%04x'", $named_id));
+	  }
+	  break;
+	
+	case TNEF_MAPI_NAMED_TYPE_STRING:
+	  $attr_name = 0x9999;                                             // dummy to identify strings
+	  $idlen = tnef_geti32($buffer);
+	  tnef_log("idlen=$idlen");
+	  $buflen = $idlen + ((4 - ($idlen % 4)) % 4);                     // pad to next 4 byte boundary
+	  tnef_log("buflen=$buflen");
+	  $named_id = substr(tnef_getx($buflen, $buffer), 0, $idlen );     // read and truncate to length
+	  if ($this->tnef_debug) {
+	    tnef_log("Named Id='$named_id'");
+	  }
+	  break;
+
+	default:
+	  if ($this->tnef_debug) {
+	    tnef_log(sprintf("Unknown Named Type 0x%04x found", $named_type));
+	  }
+	  break;
+	}
+      }
+
+      if ($have_multivalue) {
+	$num_multivalues = tnef_geti32($buffer);
+	if ($this->tnef_debug) {
+	  tnef_log("Number of multivalues=$num_multivalues");
+	}
+      }
+
+      switch($attr_type) {
+      case TNEF_MAPI_NULL:
+	break;
+
+      case TNEF_MAPI_SHORT:
+	$value = tnef_geti16($buffer);
+	break;
+
+      case TNEF_MAPI_INT:
+      case TNEF_MAPI_BOOLEAN:
+	for ($cnt = 0; $cnt < $num_multivalues; $cnt++) {
+	  $value = tnef_geti32($buffer);
+	}
+	break;
+
+      case TNEF_MAPI_FLOAT:
+      case TNEF_MAPI_ERROR:
+	$value = tnef_getx(4, $buffer);
+	break;
+
+      case TNEF_MAPI_DOUBLE:
+      case TNEF_MAPI_APPTIME:
+      case TNEF_MAPI_CURRENCY:
+      case TNEF_MAPI_INT8BYTE:
+      case TNEF_MAPI_SYSTIME:
+	$value = tnef_getx(8, $buffer);
+	break;
+
+      case TNEF_MAPI_CLSID:
+	if ($this->tnef_debug) {
+	  tnef_log("What is a MAPI CLSID ????");
+	}
+	break;
+
+      case TNEF_MAPI_STRING:
+      case TNEF_MAPI_UNICODE_STRING:
+      case TNEF_MAPI_BINARY:
+      case TNEF_MAPI_OBJECT:
+	if ($have_multivalue) {
+	  $num_vals = $num_multivalues;
+	} else {
+	  $num_vals = tnef_geti32($buffer);
+	}
+	if ($num_vals > 20) {               // A Sanity check.
+	  $ended = 1;
+	  if ($this->tnef_debug) {
+	    tnef_log("Number of entries in String Attributes=$num_vals. Aborting Mapi parsing.");
+	  }
+	} else {
+	  for ($cnt = 0; $cnt < $num_vals; $cnt++) {
+	    $length = tnef_geti32($buffer);
+	    $buflen = $length + ((4 - ($length % 4)) % 4); // pad to next 4 byte boundary
+	    if ($attr_type == TNEF_MAPI_STRING) {
+	      $length -= 1;
+	    }
+	    $value = substr(tnef_getx($buflen, $buffer), 0, $length); // read and truncate to length
+	  }
+	}
+	break;
+
+      default:
+	if ($this->tnef_debug) {
+	  tnef_log("Unknown mapi attribute! $attr_type");
+	}
+	break;
+      }
+
+      if ($this->tnef_debug) {
+	show_mapi_attribute($attr_type, $attr_name, $value, $length);
+      }
+
+      switch ($attr_name) {
+      case TNEF_MAPI_ATTACH_DATA:
+	if ($this->tnef_debug) {
+	  tnef_log("MAPI Found nested attachment. Processing new one.");
+	}
+	tnef_getx(16, $value); // skip the next 16 bytes (unknown data)
+	$att = & new TnefAttachment($this->tnef_debug);
+	$att->decodeTnef($value);
+	$this->attachments[] = &$att;
+	if ($this->tnef_debug) {
+	  tnef_log("MAPI Finished nested attachment. Continuing old one.");
+	}
+	break;
+
+      case TNEF_MAPI_RTF_COMPRESSED:
+	if ($this->tnef_debug) {
+	  tnef_log("MAPI Found Compressed RTF Attachment.");
+	}
+	$this->files[] = &new TnefFileRTF($this->tnef_debug, $value);;
+	break;
+
+      default:
+	$this->mailinfo->receiveMapiAttribute($attr_type, $attr_name, $value, $length);
+	if ($this->current_receiver) {
+	  $this->current_receiver->receiveMapiAttribute($attr_type, $attr_name, $value, $length);
+	}
+	break;
+      }
+    }
+    if (($this->tnef_debug) && ($ended)) {
+      $len = strlen($buffer);
+      for ($cnt = 0; $cnt < $len; $cnt++) {
+	$ord = ord($buffer{$cnt});
+	if ($ord == 0) {
+	  $char = "";
+	} else {
+	  $char = $buffer{$cnt};
+	}
+	tnef_log(sprintf("Char Nr. %6d = 0x%02x = '%s'", $cnt, $ord, $char));
+      }
+    }
+  }
+
+}
+
+?>
\ No newline at end of file
--- /dev/null
+++ squirrelmail-attachment-tnef-1.0/attachment_tnef/tnef_consts.php
@@ -0,0 +1,183 @@
+<?php
+
+/*
+ * tnef_decoder.php
+ *
+ *  Bernd Wiegmann <bernd@wib-software.de>
+ *  Graham Norbury <gnorbury@bondcar.com>
+ *  (c) 2002 (GNU GPL - see ../../COPYING)
+ *
+ */
+
+/*
+ *   $Header: /storage/repository/attachment_tnef/tnef_consts.php,v 1.1 2003/07/31 15:24:25 bernd Exp $
+ *
+ *   $Log: tnef_consts.php,v $
+ *   Revision 1.1  2003/07/31 15:24:25  bernd
+ *   Complete rework of tnef decoder
+ *
+ *
+ */
+
+define("TNEF_SIGNATURE",      0x223e9f78);
+define("TNEF_LVL_MESSAGE",    0x01);
+define("TNEF_LVL_ATTACHMENT", 0x02);
+
+define("TNEF_TRIPLES", 0x00000000);
+define("TNEF_STRING",  0x00010000);
+define("TNEF_TEXT",    0x00020000);
+define("TNEF_DATE",    0x00030000);
+define("TNEF_SHORT",   0x00040000);
+define("TNEF_LONG",    0x00050000);
+define("TNEF_BYTE",    0x00060000);
+define("TNEF_WORD",    0x00070000);
+define("TNEF_DWORD",   0x00080000);
+define("TNEF_MAX",     0x00090000);
+
+define("TNEF_AIDOWNER",          TNEF_LONG    | 0x0008);
+define("TNEF_AREQUESTRES",       TNEF_SHORT   | 0x0009);
+define("TNEF_AFROM",             TNEF_TRIPLES | 0x8000);
+define("TNEF_ASUBJECT",          TNEF_STRING  | 0x8004);
+define("TNEF_ADATESENT",         TNEF_DATE    | 0x8005);
+define("TNEF_ADATERECEIVED",     TNEF_DATE    | 0x8006);
+define("TNEF_ASTATUS",           TNEF_BYTE    | 0x8007);
+define("TNEF_AMCLASS",           TNEF_WORD    | 0x8008);
+define("TNEF_AMESSAGEID",        TNEF_STRING  | 0x8009);
+define("TNEF_ABODYTEXT",         TNEF_TEXT    | 0x800c);
+define("TNEF_APRIORITY",         TNEF_SHORT   | 0x800d);
+define("TNEF_ATTACHDATA",        TNEF_BYTE    | 0x800f);
+define("TNEF_AFILENAME",         TNEF_STRING  | 0x8010);
+define("TNEF_ATTACHMETAFILE",    TNEF_BYTE    | 0x8011);
+define("TNEF_AATTACHCREATEDATE", TNEF_DATE    | 0x8012);
+define("TNEF_AATTACHMODDATE",    TNEF_DATE    | 0x8013);
+define("TNEF_ADATEMODIFIED",     TNEF_DATE    | 0x8020);
+define("TNEF_ARENDDATA",         TNEF_BYTE    | 0x9002);
+define("TNEF_AMAPIPROPS",        TNEF_BYTE    | 0x9003);
+define("TNEF_AMAPIATTRS",        TNEF_BYTE    | 0x9005);
+define("TNEF_AVERSION",          TNEF_DWORD   | 0x9006);
+define("TNEF_AOEMCODEPAGE",      TNEF_BYTE    | 0x9007);
+
+define("TNEF_MAPI_NULL",           0x0001);
+define("TNEF_MAPI_SHORT",          0x0002);
+define("TNEF_MAPI_INT",            0x0003);
+define("TNEF_MAPI_FLOAT",          0x0004);
+define("TNEF_MAPI_DOUBLE",         0x0005);
+define("TNEF_MAPI_CURRENCY",       0x0006);
+define("TNEF_MAPI_APPTIME",        0x0007);
+define("TNEF_MAPI_ERROR",          0x000a);
+define("TNEF_MAPI_BOOLEAN",        0x000b);
+define("TNEF_MAPI_OBJECT",         0x000d);
+define("TNEF_MAPI_INT8BYTE",       0x0014);
+define("TNEF_MAPI_STRING",         0x001e);
+define("TNEF_MAPI_UNICODE_STRING", 0x001f);
+define("TNEF_MAPI_SYSTIME",        0x0040);
+define("TNEF_MAPI_CLSID",          0x0048);
+define("TNEF_MAPI_BINARY",         0x0102);
+
+define("TNEF_MAPI_MV_FLAG",              0x1000);
+define("TNEF_MAPI_NAMED_TYPE_ID",        0x0000);
+define("TNEF_MAPI_NAMED_TYPE_STRING",    0x0001);
+
+define("TNEF_MAPI_SUBJECT_PREFIX",       0x003D);
+define("TNEF_MAPI_SENT_REP_NAME",        0x0042);
+define("TNEF_MAPI_ORIGINAL_AUTHOR",      0x004D);
+define("TNEF_MAPI_SENT_REP_ADDRTYPE",    0x0064);
+define("TNEF_MAPI_SENT_REP_EMAIL_ADDR",  0x0065);
+define("TNEF_MAPI_CONVERSATION_TOPIC",   0x0070);
+define("TNEF_MAPI_SENDER_NAME",          0x0c1A);
+define("TNEF_MAPI_SENDER_ADDRTYPE",      0x0c1E);
+define("TNEF_MAPI_SENDER_EMAIL_ADDRESS", 0x0c1F);
+define("TNEF_MAPI_NORMALIZED_SUBJECT",   0x0E1D);
+define("TNEF_MAPI_ATTACH_SIZE",          0x0E20);
+define("TNEF_MAPI_ATTACH_NUM",           0x0E21);
+define("TNEF_MAPI_ACCESS_LEVEL",         0x0FF7);
+define("TNEF_MAPI_MAPPING_SIGNATURE",    0x0FF8);
+define("TNEF_MAPI_RECORD_KEY",           0x0FF9);
+define("TNEF_MAPI_STORE_RECORD_KEY",     0x0FFA);
+define("TNEF_MAPI_STORE_ENTRY_ID",       0x0FFB);
+define("TNEF_MAPI_OBJECT_TYPE",          0x0FFE);
+define("TNEF_MAPI_RTF_SYNC_BODY_TAG",    0x1008);
+define("TNEF_MAPI_RTF_COMPRESSED",       0x1009);
+define("TNEF_MAPI_DISPLAY_NAME",         0x3001);
+define("TNEF_MAPI_CREATION_TIME",        0x3007);
+define("TNEF_MAPI_MODIFICATION_TIME",    0x3008);
+define("TNEF_MAPI_ATTACH_DATA",          0x3701);
+define("TNEF_MAPI_ATTACH_ENCODING",      0x3702);
+define("TNEF_MAPI_ATTACH_EXTENSION",     0x3703);
+define("TNEF_MAPI_ATTACH_METHOD",        0x3705);
+define("TNEF_MAPI_ATTACH_LONG_FILENAME", 0x3707);
+define("TNEF_MAPI_RENDERING_POSITION",   0x370B);
+define("TNEF_MAPI_ATTACH_MIME_TAG",      0x370E);
+define("TNEF_MAPI_ACCOUNT",              0x3A00);
+define("TNEF_MAPI_GENERATION",           0x3A05);
+define("TNEF_MAPI_GIVEN_NAME",           0x3A06);
+define("TNEF_MAPI_BUSINESS_TEL_NUMBER",  0x3A08);
+define("TNEF_MAPI_HOME_TEL_NUMBER",      0x3A09);
+define("TNEF_MAPI_INITIALS",             0x3A0A);
+define("TNEF_MAPI_KEYWORDS",             0x3A0B);
+define("TNEF_MAPI_LANGUAGE",             0x3A0C);
+define("TNEF_MAPI_LOCATION",             0x3A0D);
+define("TNEF_MAPI_SURNAME",              0x3A11);
+define("TNEF_MAPI_POSTAL_ADDRESS",       0x3A15);
+define("TNEF_MAPI_COMPANY_NAME",         0x3A16);
+define("TNEF_MAPI_TITLE",                0x3A17);
+define("TNEF_MAPI_DEPARTMENT_NAME",      0x3A18);
+define("TNEF_MAPI_OFFICE_LOCATION",      0x3A19);
+define("TNEF_MAPI_PRIMARY_TEL_NUMBER",   0x3A1A);
+define("TNEF_MAPI_BUSINESS2_TEL_NUMBER", 0x3A1B);
+define("TNEF_MAPI_MOBILE_TEL_NUMBER",    0x3A1C);
+define("TNEF_MAPI_RADIO_TEL_NUMBER",     0x3A1D);
+define("TNEF_MAPI_CAR_TEL_NUMBER",       0x3A1E);
+define("TNEF_MAPI_OTHER_TEL_NUMBER",     0x3A1F);
+define("TNEF_MAPI_PAGER_TEL_NUMBER",     0x3A21);
+define("TNEF_MAPI_PRIMARY_FAX_NUMBER",   0x3A23);
+define("TNEF_MAPI_BUSINESS_FAX_NUMBER",  0x3A24);
+define("TNEF_MAPI_HOME_FAX_NUMBER",      0x3A25);
+define("TNEF_MAPI_COUNTRY",              0x3A26);
+define("TNEF_MAPI_LOCALTY",              0x3A27);
+define("TNEF_MAPI_STATE_OR_PROVINCE",    0x3A28);
+define("TNEF_MAPI_STREET_ADDRESS",       0x3A29);
+define("TNEF_MAPI_POSTAL_CODE",          0x3A2A);
+define("TNEF_MAPI_POST_OFFICE_BOX",      0x3A2B);
+define("TNEF_MAPI_TELEX_NUMBER",         0x3A2C);
+define("TNEF_MAPI_ISDN_NUMBER",          0x3A2D);
+define("TNEF_MAPI_ASSISTANT_TEL_NUMBER", 0x3A2E);
+define("TNEF_MAPI_HOME2_TEL_NUMBER",     0x3A2F);
+define("TNEF_MAPI_ASSISTANT",            0x3A30);
+define("TNEF_MAPI_MIDDLE_NAME",          0x3A44);
+define("TNEF_MAPI_DISPLAYNAME_PREFIX",   0x3A45);
+define("TNEF_MAPI_PROFESSION",           0x3A46);
+define("TNEF_MAPI_SPOUSE_NAME",          0x3A48);
+define("TNEF_MAPI_MANAGER_NAME",         0x3A4E);
+define("TNEF_MAPI_NICKNAME",             0x3A4F);
+define("TNEF_MAPI_PERSONAL_HOME_PAGE",   0x3A50);
+define("TNEF_MAPI_BUSINESS_HOME_PAGE",   0x3A51);
+define("TNEF_MAPI_CONTACT_EMAIL_ADDR",   0x3A56);
+define("TNEF_MAPI_HOME_ADDR_CITY",       0x3A59);
+define("TNEF_MAPI_HOME_ADDR_COUNTRY",    0x3A5A);
+define("TNEF_MAPI_HOME_ADDR_ZIP",        0x3A5B);
+define("TNEF_MAPI_HOME_ADDR_STATE",      0x3A5C);
+define("TNEF_MAPI_HOME_ADDR_STREET",     0x3A5D);
+define("TNEF_MAPI_HOME_ADDR_PO_BOX",     0x3A5E);
+define("TNEF_MAPI_OTHER_ADDR_CITY",      0x3A5F);
+define("TNEF_MAPI_OTHER_ADDR_COUNTRY",   0x3A60);
+define("TNEF_MAPI_OTHER_ADDR_ZIP",       0x3A61);
+define("TNEF_MAPI_OTHER_ADDR_STATE",     0x3A62);
+define("TNEF_MAPI_OTHER_ADDR_STREET",    0x3A63);
+define("TNEF_MAPI_OTHER_ADDR_PO_BOX",    0x3A64);
+
+define("TNEF_MAPI_OTHER_HOME_PAGE",      0x804F);
+define("TNEF_MAPI_EMAIL1_DISPLAY",       0x8080);
+define("TNEF_MAPI_EMAIL1_TRANSPORT",     0x8082);
+define("TNEF_MAPI_EMAIL1_EMAIL",         0x8083);
+define("TNEF_MAPI_EMAIL1_EMAIL2",        0x8084);
+define("TNEF_MAPI_EMAIL2_DISPLAY",       0x8090);
+define("TNEF_MAPI_EMAIL2_TRANSPORT",     0x8092);
+define("TNEF_MAPI_EMAIL2_EMAIL",         0x8093);
+define("TNEF_MAPI_EMAIL2_EMAIL2",        0x8094);
+define("TNEF_MAPI_EMAIL3_DISPLAY",       0x80A0);
+define("TNEF_MAPI_EMAIL3_TRANSPORT",     0x80A2);
+define("TNEF_MAPI_EMAIL3_EMAIL",         0x80A3);
+define("TNEF_MAPI_EMAIL3_EMAIL2",        0x80A4);
+
+?>
\ No newline at end of file
--- /dev/null
+++ squirrelmail-attachment-tnef-1.0/attachment_tnef/tnef_date.php
@@ -0,0 +1,48 @@
+<?php
+
+/*
+ * tnef_date.php
+ *
+ *  Bernd Wiegmann <bernd@wib-software.de>
+ *  (c) 2003 (GNU GPL - see ../../COPYING)
+ *
+ */
+
+/*
+ *   $Header: /storage/repository/attachment_tnef/tnef_date.php,v 1.1 2003/07/31 15:24:25 bernd Exp $
+ *
+ *   $Log: tnef_date.php,v $
+ *   Revision 1.1  2003/07/31 15:24:25  bernd
+ *   Complete rework of tnef decoder
+ *
+ *
+ */
+
+class TnefDate {
+
+  var $year;
+  var $month;
+  var $day;
+  var $hour;
+  var $minute;
+  var $second;
+
+  function TnefDate() {
+  }
+
+  function setTnefBuffer($buffer) {
+    $this->year = tnef_geti16($buffer);
+    $this->month = tnef_geti16($buffer);
+    $this->day = tnef_geti16($buffer);
+    $this->hour = tnef_geti16($buffer);
+    $this->minute = tnef_geti16($buffer);
+    $this->second = tnef_geti16($buffer);
+  }
+
+  function getString() {
+    return sprintf("%04d-%02d-%02d %02d:%02d:%02d",
+		   $this->year, $this->month, $this->day, $this->hour, $this->minute, $this->second);
+  }
+}
+
+?>
\ No newline at end of file
--- /dev/null
+++ squirrelmail-attachment-tnef-1.0/attachment_tnef/tnef_file.php
@@ -0,0 +1,85 @@
+<?php
+
+/*
+ * tnef_file.php
+ *
+ *  Bernd Wiegmann <bernd@wib-software.de>
+ *  (c) 2003 (GNU GPL - see ../../COPYING)
+ *
+ */
+
+/*
+ *   $Header: /storage/repository/attachment_tnef/tnef_file.php,v 1.2 2003/09/19 15:51:27 bernd Exp $
+ *
+ *   $Log: tnef_file.php,v $
+ *   Revision 1.2  2003/09/19 15:51:27  bernd
+ *   First working version of the compressed RTF decoder.
+ *
+ *   Revision 1.1  2003/07/31 15:24:25  bernd
+ *   Complete rework of tnef decoder
+ *
+ *
+ */
+
+include_once(SM_PATH . 'plugins/attachment_tnef/tnef_file_base.php');
+
+class TnefFile extends TnefFileBase {
+  var $metafile;
+
+  function TnefFile($tnef_debug) {
+    $this->TnefFileBase($tnef_debug);
+  }
+
+  function getMetafile() {
+    return $this->metafile;
+  }
+
+  function receiveTnefAttribute($attribute, $value, $length) {
+    switch ($attribute) {
+    case TNEF_AFILENAME:                                        // filename
+      $this->name = ereg_replace('.*[\/](.*)$', '\1', $value);
+      break;
+
+    case TNEF_ATTACHDATA:                                       // the attachment itself
+      $this->content = $value;
+      break;
+
+    case TNEF_ATTACHMETAFILE:                                   // a metafile
+      $this->metafile = $value;
+      break;
+
+    case TNEF_AATTACHCREATEDATE:
+      $this->created = & new TnefDate;
+      $this->created->setTnefBuffer($value);
+      break;
+
+    case TNEF_AATTACHMODDATE:
+      $this->modified = & new TnefDate;
+      $this->modified->setTnefBuffer($value);
+      break;
+    }
+  }
+
+  function receiveMapiAttribute($attr_type, $attr_name, $value, $length) {
+    switch ($attr_name) {
+    case TNEF_MAPI_ATTACH_LONG_FILENAME:                        // used in preference to AFILENAME value
+      $this->name = ereg_replace('.*[\/](.*)$', '\1', $value);  // strip path
+      break;
+
+    case TNEF_MAPI_ATTACH_MIME_TAG:                             // Is this ever set, and what is format?
+      $type0 = ereg_replace('^(.*)/.*', '\1', $value);
+      $type1 = ereg_replace('.*/(.*)$', '\1', $value);
+      $this->type = "$type0/$type1";
+      break;
+
+    case TNEF_MAPI_ATTACH_EXTENSION:
+      $type = ext_to_mime($value);
+      if ($type) {
+	$this->type = $type;
+      }
+      break;
+    }
+  }
+}
+
+?>
\ No newline at end of file
--- /dev/null
+++ squirrelmail-attachment-tnef-1.0/attachment_tnef/tnef_file_base.php
@@ -0,0 +1,62 @@
+<?php
+
+/*
+ * tnef_file_base.php
+ *
+ *  Bernd Wiegmann <bernd@wib-software.de>
+ *  (c) 2003 (GNU GPL - see ../../COPYING)
+ *
+ */
+
+/*
+ *   $Header: /storage/repository/attachment_tnef/tnef_file_base.php,v 1.1 2003/10/06 16:21:55 bernd Exp $
+ *
+ *   $Log: tnef_file_base.php,v $
+ *   Revision 1.1  2003/10/06 16:21:55  bernd
+ *   Preparations for 0.6
+ *
+ *
+ */
+
+class TnefFileBase {
+  var $name;
+  var $type;
+  var $content;
+  var $created;
+  var $modified;
+  var $tnef_debug;
+
+  function TnefFileBase($tnef_debug) {
+    $this->name = "Untitled";
+    $this->type = "application/octet-stream";
+    $this->content = "";
+    $this->tnef_debug = $tnef_debug;
+  }
+
+  function getName() {
+    return $this->name;
+  }
+
+  function getType() {
+    return $this->type;
+  }
+
+  function getSize() {
+    return strlen($this->content);
+  }
+
+  function &getCreated() {
+    return $this->created;
+  }
+
+  function &getModified() {
+    return $this->modified;
+  }
+
+  function getContent() {
+    return $this->content;
+  }
+
+}
+
+?>
\ No newline at end of file
--- /dev/null
+++ squirrelmail-attachment-tnef-1.0/attachment_tnef/tnef_file_rtf.php
@@ -0,0 +1,113 @@
+<?php
+
+/*
+ * tnef_file_rtf.php
+ *
+ *  Bernd Wiegmann <bernd@wib-software.de>
+ *  (c) 2003 (GNU GPL - see ../../COPYING)
+ *
+ */
+
+/*
+ *   $Header: /storage/repository/attachment_tnef/tnef_file_rtf.php,v 1.2 2003/10/08 15:55:46 bernd Exp $
+ *
+ *   $Log: tnef_file_rtf.php,v $
+ *   Revision 1.2  2003/10/08 15:55:46  bernd
+ *   Added .rtf for RTF Filename.
+ *
+ *   Revision 1.1  2003/10/06 16:21:55  bernd
+ *   Preparations for 0.6
+ *
+ *
+ */
+
+include_once(SM_PATH . 'plugins/attachment_tnef/tnef_file_base.php');
+
+define("CRTF_UNCOMPRESSED",          0x414c454d);
+define("CRTF_COMPRESSED",            0x75465a4c);
+
+class TnefFileRTF extends TnefFileBase {
+  var $size;
+
+  function TnefFileRTF($tnef_debug, $buffer) {
+    $this->TnefFileBase($tnef_debug);
+    $this->type = "application/rtf";
+    $this->name = "EmbeddedRTF.rtf";
+
+    $this->decode_crtf($buffer);
+  }
+
+  function getSize() {
+    return $this->size;
+  }
+
+  function decode_crtf(&$buffer) {
+    $size_compressed = tnef_geti32($buffer);
+    $this->size = tnef_geti32($buffer);
+    $magic = tnef_geti32($buffer);
+    $crc32 = tnef_geti32($buffer);
+
+    if ($this->tnef_debug) {
+      tnef_log("CRTF: size comp=$size_compressed, size=$this->size");
+    }
+
+    switch ($magic) {
+    case CRTF_COMPRESSED:
+      $this->uncompress_rtf($buffer);
+      break;
+
+    case CRTF_UNCOMPRESSED:
+      $this->content = $buffer;
+      break;
+
+    default:
+      if ($this->tnef_debug) {
+	tnef_log("Unknown Compressed RTF Format");
+      }
+      break;
+    }
+  }
+
+  function uncompress_rtf(&$buffer) {
+    $uncomp = array();
+    $in = 0;
+    $out = 0;
+    $flags = 0;
+    $flag_count = 0;
+
+    $preload = "{\\rtf1\ansi\mac\deff0\deftab720{\fonttbl;}{\f0\fnil \froman \fswiss \fmodern \fscript \fdecor MS Sans SerifSymbolArialTimes New RomanCourier{\colortbl\\red0\green0\blue0\n\r\par \pard\plain\f0\fs20\b\i\u\\tab\\tx";
+    $length_preload = strlen($preload);
+    for ($cnt = 0; $cnt < $length_preload; $cnt++) {
+      $uncomp[$out++] = $preload{$cnt};
+    }
+    while ($out < ($this->size + $length_preload)) {
+      if (($flag_count++ % 8) == 0) {
+	$flags = ord($buffer{$in++});
+      } else {
+	$flags = $flags >> 1;
+      }
+      if (($flags & 1) != 0) {
+	$offset = ord($buffer{$in++});
+	$length = ord($buffer{$in++});
+	$offset = ($offset << 4) | ($length >> 4);
+	$length = ($length & 0xF) + 2;
+	$offset = ((int)($out / 4096)) * 4096 + $offset;
+	if ($offset >= $out) {
+	  $offset -= 4096;
+	}
+	$end = $offset + $length;
+	while ($offset < $end) {
+	  $uncomp[$out++] = $uncomp[$offset++];
+	}
+      } else {
+	$uncomp[$out++] = $buffer{$in++};
+      }
+    }
+    $this->content = substr_replace(implode("", $uncomp), "", 0, $length_preload);
+    $length=strlen($this->content);
+    tnef_log("real=$length, est=$this->size out=$out");
+  }
+
+}
+
+?>
\ No newline at end of file
--- /dev/null
+++ squirrelmail-attachment-tnef-1.0/attachment_tnef/tnef_mailinfo.php
@@ -0,0 +1,97 @@
+<?php
+
+/*
+ * tnef_mailinfo.php
+ *
+ *  Bernd Wiegmann <bernd@wib-software.de>
+ *  (c) 2003 (GNU GPL - see ../../COPYING)
+ *
+ */
+
+/*
+ *   $Header: /storage/repository/attachment_tnef/tnef_mailinfo.php,v 1.4 2003/09/19 15:51:27 bernd Exp $
+ *
+ *   $Log: tnef_mailinfo.php,v $
+ *   Revision 1.4  2003/09/19 15:51:27  bernd
+ *   First working version of the compressed RTF decoder.
+ *
+ *   Revision 1.3  2003/09/11 11:36:45  bernd
+ *   Preparations for beta release.
+ *
+ *
+ *   Revision 1.1  2003/07/31 15:24:25  bernd
+ *   Complete rework of tnef decoder
+ *
+ *
+ */
+
+include_once(SM_PATH . 'plugins/attachment_tnef/tnef_date.php');
+
+class TnefMailinfo {
+
+  var $subject;
+  var $topic;
+  var $from;
+  var $from_name;
+  var $date_sent;
+
+  function TnefMailinfo() {
+  }
+
+  function getTopic() {
+    return $this->topic;
+  }
+
+  function getSubject() {
+    return $this->subject;
+  }
+
+  function getFrom() {
+    return $this->from;
+  }
+
+  function getFromName() {
+    return $this->from_name;
+  }
+
+  function &getDateSent() {
+    return $this->date_sent;
+  }
+
+  function receiveTnefAttribute($attribute, $value, $length) {
+    switch($attribute) {
+    case TNEF_ASUBJECT:
+      $this->subject = substr($value, 0, $length - 1);
+      break;
+
+    case TNEF_ADATERECEIVED:
+      if (!$this->date_sent) {
+	$this->date_sent = & new TnefDate;
+	$this->date_sent->setTnefBuffer($value);
+      }
+
+    case TNEF_ADATESENT:
+      $this->date_sent = & new TnefDate;
+      $this->date_sent->setTnefBuffer($value);
+    }
+  }
+
+  function receiveMapiAttribute($attr_type, $attr_name, $value, $length) {
+    switch($attr_name) {
+    case TNEF_MAPI_CONVERSATION_TOPIC:
+      $this->topic = $value;
+      break;
+
+    case TNEF_MAPI_SENT_REP_EMAIL_ADDR:
+      $this->from = $value;
+      break;
+
+    case TNEF_MAPI_SENT_REP_NAME:
+      $this->from_name = $value;
+      break;
+    }
+  }
+
+}
+
+?>
\ No newline at end of file
--- /dev/null
+++ squirrelmail-attachment-tnef-1.0/attachment_tnef/tnef_vcard.php
@@ -0,0 +1,255 @@
+<?php
+
+/*
+ * tnef_vcard.php
+ *
+ *  Bernd Wiegmann <bernd@wib-software.de>
+ *  (c) 2003 (GNU GPL - see ../../COPYING)
+ *
+ */
+
+/*
+ *   $Header: /storage/repository/attachment_tnef/tnef_vcard.php,v 1.1 2003/07/31 15:24:25 bernd Exp $
+ *
+ *   $Log: tnef_vcard.php,v $
+ *   Revision 1.1  2003/07/31 15:24:25  bernd
+ *   Complete rework of tnef decoder
+ *
+ *
+ */
+
+$telefone_mapping = array (
+			   TNEF_MAPI_PRIMARY_TEL_NUMBER    => "Primary Telefone",
+			   TNEF_MAPI_HOME_TEL_NUMBER       => "Home Telefone",
+			   TNEF_MAPI_HOME2_TEL_NUMBER      => "Home2 Telefone",
+			   TNEF_MAPI_BUSINESS_TEL_NUMBER   => "Business Telefone",
+			   TNEF_MAPI_BUSINESS2_TEL_NUMBER  => "Business2 Telefone",
+			   TNEF_MAPI_MOBILE_TEL_NUMBER     => "Mobile Telefone",
+			   TNEF_MAPI_RADIO_TEL_NUMBER      => "Radio Telefone",
+			   TNEF_MAPI_CAR_TEL_NUMBER        => "Car Telefone",
+			   TNEF_MAPI_OTHER_TEL_NUMBER      => "Other Telefone",
+			   TNEF_MAPI_PAGER_TEL_NUMBER      => "Pager Telefone",
+			   TNEF_MAPI_PRIMARY_FAX_NUMBER    => "Primary Fax",
+			   TNEF_MAPI_BUSINESS_FAX_NUMBER   => "Business Fax",
+			   TNEF_MAPI_HOME_FAX_NUMBER       => "Home Fax"
+			   );
+
+$homepage_mapping = array (
+			   TNEF_MAPI_PERSONAL_HOME_PAGE    => "Personal Homepage",
+			   TNEF_MAPI_BUSINESS_HOME_PAGE    => "Business Homepage",
+			   TNEF_MAPI_OTHER_HOME_PAGE       => "Other Homepage"
+			   );
+
+define ("EMAIL_DISPLAY",       1);
+define ("EMAIL_TRANSPORT",     2);
+define ("EMAIL_EMAIL",         3);
+define ("EMAIL_EMAIL2",        4);
+
+$email_mapping = array (
+			TNEF_MAPI_EMAIL1_DISPLAY           => array ( "eMail 1", EMAIL_DISPLAY ),
+			TNEF_MAPI_EMAIL1_TRANSPORT         => array ( "eMail 1", EMAIL_TRANSPORT ),
+			TNEF_MAPI_EMAIL1_EMAIL             => array ( "eMail 1", EMAIL_EMAIL ),
+			TNEF_MAPI_EMAIL1_EMAIL2            => array ( "eMail 1", EMAIL_EMAIL2 ),
+			TNEF_MAPI_EMAIL2_DISPLAY           => array ( "eMail 2", EMAIL_DISPLAY ),
+			TNEF_MAPI_EMAIL2_TRANSPORT         => array ( "eMail 2", EMAIL_TRANSPORT ),
+			TNEF_MAPI_EMAIL2_EMAIL             => array ( "eMail 2", EMAIL_EMAIL ),
+			TNEF_MAPI_EMAIL2_EMAIL2            => array ( "eMail 2", EMAIL_EMAIL2 ),
+			TNEF_MAPI_EMAIL3_DISPLAY           => array ( "eMail 3", EMAIL_DISPLAY ),
+			TNEF_MAPI_EMAIL3_TRANSPORT         => array ( "eMail 3", EMAIL_TRANSPORT ),
+			TNEF_MAPI_EMAIL3_EMAIL             => array ( "eMail 3", EMAIL_EMAIL ),
+			TNEF_MAPI_EMAIL3_EMAIL2            => array ( "eMail 3", EMAIL_EMAIL2 )
+			);
+
+define ("ADDRESS_STREET",      "Street");
+define ("ADDRESS_ZIP",         "Zip");
+define ("ADDRESS_CITY",        "City");
+define ("ADDRESS_COUNTRY",     "Country");
+define ("ADDRESS_STATE",       "State");
+define ("ADDRESS_PO_BOX",      "PO Box");
+
+$address_mapping = array (
+			  TNEF_MAPI_LOCALTY                => array ( "Address", ADDRESS_CITY ),
+			  TNEF_MAPI_COUNTRY                => array ( "Address", ADDRESS_COUNTRY ),
+			  TNEF_MAPI_POSTAL_CODE            => array ( "Address", ADDRESS_ZIP ),
+			  TNEF_MAPI_STATE_OR_PROVINCE      => array ( "Address", ADDRESS_STATE ),
+			  TNEF_MAPI_STREET_ADDRESS         => array ( "Address", ADDRESS_STREET ),
+			  TNEF_MAPI_POST_OFFICE_BOX        => array ( "Address", ADDRESS_PO_BOX ),
+			  TNEF_MAPI_HOME_ADDR_CITY         => array ( "Home Address", ADDRESS_CITY ),
+			  TNEF_MAPI_HOME_ADDR_COUNTRY      => array ( "Home Address", ADDRESS_COUNTRY ),
+			  TNEF_MAPI_HOME_ADDR_ZIP          => array ( "Home Address", ADDRESS_ZIP ),
+			  TNEF_MAPI_HOME_ADDR_STATE        => array ( "Home Address", ADDRESS_STATE ),
+			  TNEF_MAPI_HOME_ADDR_STREET       => array ( "Home Address", ADDRESS_STREET ),
+			  TNEF_MAPI_HOME_ADDR_PO_BOX       => array ( "Home Address", ADDRESS_PO_BOX ),
+			  TNEF_MAPI_OTHER_ADDR_CITY        => array ( "Other Address", ADDRESS_CITY ),
+			  TNEF_MAPI_OTHER_ADDR_COUNTRY     => array ( "Other Address", ADDRESS_COUNTRY ),
+			  TNEF_MAPI_OTHER_ADDR_ZIP         => array ( "Other Address", ADDRESS_ZIP ),
+			  TNEF_MAPI_OTHER_ADDR_STATE       => array ( "Other Address", ADDRESS_STATE ),
+			  TNEF_MAPI_OTHER_ADDR_STREET      => array ( "Other Address", ADDRESS_STREET ),
+			  TNEF_MAPI_OTHER_ADDR_PO_BOX      => array ( "Other Address", ADDRESS_PO_BOX )
+                         );
+
+class TnefvCard {
+
+  var $tnef_debug;
+  var $name;
+  var $type;
+  var $content;
+  var $metafile;
+  var $created;
+  var $modified;
+  var $surname;
+  var $given_name;
+  var $middle_name;
+  var $nickname;
+  var $company;
+
+  var $homepages;
+  var $addresses;
+  var $emails;
+  var $telefones;
+
+  function TnefvCard($tnef_debug) {
+    $this->tnef_debug = $tnef_debug;
+    $this->name = "Untitled";
+    $this->type = "text/x-vcard";
+    $this->content = "";
+    $this->telefones = array();
+    $this->homepages = array();
+    $this->emails = array();
+    $this->addresses = array();
+  }
+
+  function getName()              { return $this->name;  }
+  function getType()              { return $this->type;  }
+  function getMetafile()          { return $this->metafile;   }
+  function getSize()              { return strlen($this->content);   }
+  function getContent()           { return $this->content;   }
+  function &getCreated()          { return $this->created;   }
+  function &getModified()         { return $this->modified;   }
+  function &getTelefones()        { return $this->telefones;   }
+  function getSurname()           { return $this->surname;  }
+  function getGivenName()         { return $this->given_name;  }
+  function getMiddleName()        { return $this->middle_name;  }
+  function getNickname()          { return $this->nickname;  }
+  function getCompany()           { return $this->company;  }
+  function &getHomepages()        { return $this->homepages;  }
+  function &getEmails()           { return $this->emails;  }
+  function &getAddresses()        { return $this->addresses;  }
+
+  function receiveTnefAttribute($attribute, $value, $length) {
+  }
+
+  function receiveMapiAttribute($attr_type, $attr_name, $value, $length) {
+    switch($attr_name) {
+    case TNEF_MAPI_DISPLAY_NAME:
+      $this->name = $value;
+      break;
+
+    case TNEF_MAPI_SURNAME:
+      $this->surname = $value;
+      break;
+
+    case TNEF_MAPI_GIVEN_NAME:
+      $this->given_name = $value;
+      break;
+
+    case TNEF_MAPI_MIDDLE_NAME:
+      $this->middle_name = $value;
+      break;
+
+    case TNEF_MAPI_NICKNAME:
+      $this->nickname = $value;
+      break;
+
+    case TNEF_MAPI_COMPANY_NAME:
+      $this->company = $value;
+      break;
+
+    default:
+      $rc = $this->evaluateTelefoneAttribute($attr_type, $attr_name, $value, $length);
+      if (!$rc) {
+	$rc = $this->evaluateEmailAttribute($attr_type, $attr_name, $value, $length);
+      }
+      if (!$rc) {
+	$rc = $this->evaluateAddressAttribute($attr_type, $attr_name, $value, $length);
+      }
+      if (!$rc) {
+	$rc = $this->evaluateHomepageAttribute($attr_type, $attr_name, $value, $length);
+      }
+      break;
+    }
+  }
+
+  function evaluateTelefoneAttribute($attr_type, $attr_name, $value, $length) {
+    global $telefone_mapping;
+    $rc = 0;
+
+    if ($length > 0) {
+      if (array_key_exists($attr_name, $telefone_mapping)) {
+	$telefone_key = $telefone_mapping[$attr_name];
+	$this->telefones[$telefone_key] = $value;
+	$rc = 1;
+	if ($this->tnef_debug) {
+	  tnef_log("Setting telefone '$telefone_key' to value '$value'");
+	}
+      }
+    }
+    
+    return $rc;
+  }
+
+  function evaluateEmailAttribute($attr_type, $attr_name, $value, $length) {
+    global $email_mapping;
+    $rc = 0;
+
+    if ($length > 0) {
+      if (array_key_exists($attr_name, $email_mapping)) {
+	$email_key = $email_mapping[$attr_name];
+	if (!array_key_exists($email_key[0], $this->emails)) {
+	  $this->emails[$email_key[0]] = array ( EMAIL_DISPLAY => "", EMAIL_TRANSPORT => "", EMAIL_EMAIL => "", EMAIL_EMAIL2 => "");
+	}
+	$this->emails[$email_key[0]][$email_key[1]] = $value;
+      }
+    }
+
+    return $rc;
+  }
+
+  function evaluateAddressAttribute($attr_type, $attr_name, $value, $length) {
+    global $address_mapping;
+    $rc = 0;
+
+    if ($length > 0) {
+      if (array_key_exists($attr_name, $address_mapping)) {
+	$address_key = $address_mapping[$attr_name];
+	if (!array_key_exists($address_key[0], $this->addresses)) {
+	  $this->addresses[$address_key[0]] = array ( );
+	}
+	$this->addresses[$address_key[0]][$address_key[1]] = $value;
+      }
+    }
+
+    return $rc;
+  }
+
+  function evaluateHomepageAttribute($attr_type, $attr_name, $value, $length) {
+    global $homepage_mapping;
+    $rc = 0;
+
+    if ($length > 0) {
+      if (array_key_exists($attr_name, $homepage_mapping)) {
+	$homepage_key = $homepage_mapping[$attr_name];
+	$this->homepages[$homepage_key] = $value;
+	$rc = 1;
+	if ($this->tnef_debug) {
+	  tnef_log("Setting homepage '$homepage_key' to value '$value'");
+	}
+      }
+    }
+    
+    return $rc;
+  }
+
+}
+
+?>
\ No newline at end of file
--- /dev/null
+++ squirrelmail-attachment-tnef-1.0/attachment_tnef/version
@@ -0,0 +1,2 @@
+TNEF Attachment Decoder
+0.70
\ No newline at end of file
