[imp] problem displaying msword attachement

Jie Gao jiegao at mail.usyd.edu.au
Thu Feb 12 15:52:03 PST 2004


Hi All,

horde-2.2.4 + imp-3.2.2
-----------------------

I am having problems with displaying attachments (msword) as well. I
can download the attachment all right, but I can't display them (a
blank screen I got). I tried to do some debugging and here is what I've
got:

I added some addtional logging in msword.php:

class MIME_Viewer_msword extends MIME_Viewer {
            // return _("Unable to translate this Word document");

    /**
     * Render out the currently set contents using wvWare.  The
     * $mime_part class variable has the information to render out,
     * encapsulated in a MIME_Part object.
     *
     * @return string HTML pretty-print of the content
     */
    function render($params = null)
    {
        global $mime_drivers;

        /* Check to make sure the program actually exists. */
        if (file_exists($mime_drivers['horde']['msword']['location']) === false) {
            error_log("wvhtml does not exist\n", 3, '/var/log/horde.log');

            return '<pre>' . sprintf(_("The program used to view this message type (%s) was not found on
the system."), $mime_driver
s['horde']['msword']['location']) . '</pre>';
        }

        # wvHtml format:  wvHtml --targetdir=/tmp /tmp/USYDnetContentPolicyV3.doc jie5

        #
        # Looks like Horde::getTempFile('msword') generates a file name.
        #
        $tmp_word = Horde::getTempFile('msword');

            error_log("tmp_word file: $tmp_word\n", 3, '/var/log/horde.log');

        $tmp_word_output = Horde::getTempFile('msword');

            error_log("tmp_word_output_file: $tmp_word_output\n", 3, '/var/log/horde.log');

        $tmp_dir = Horde::getTempDir();

            error_log("tmp_dir is: $tmp_dir\n", 3, '/var/log/horde.log');

        $tmp_file   = str_replace($tmp_dir . '/', '', $tmp_word_output);
            error_log("tmp_file is: $tmp_file\n", 3, '/var/log/horde.log');

        $version = explode('.', exec($mime_drivers['horde']['msword']['location'] . ' --version'));
        #error_log("version: $version\n", 3, '/var/log/horde.log');

        if (count($version) > 2 && ($version[0] > 0 || $version[1] >= 7)) {
            $args = " --targetdir=$tmp_dir $tmp_word $tmp_file";
        } else {
            $args = " $tmp_word $tmp_word_output";
        }

            error_log("args: $args\n", 3, '/var/log/horde.log');

        if (!is_writable($tmp_dir)) {
            error_log("Unable to create files in $tmp_dir\n", 3, '/var/log/horde.log');
            return _("Unable to create files in $tmp_dir.");
        }

#var_dump($this);
var_dump($this->mime_part->getContents());

        $fh = fopen($tmp_word, 'w');
        fwrite($fh, $this->mime_part->getContents());
        fclose($fh);

        if (!file_exists($tmp_word)) {
            error_log("tmp_word input file populated exists.\n", 3, '/var/log/horde.log');
            return _("tmp_word input populated file exists.");
        }

        $file_size_w = filesize($tmp_word);
        error_log("$tmp_word populated has $file_size_w bytes\n", 3, '/var/log/horde.log');

        exec($mime_drivers['horde']['msword']['location'] . $args . ' 2>&1' , $error);
        foreach($error as $errorline) {
            error_log("Error exec wvHtml: $errorline\n", 3, '/var/log/horde.log');
        }

        if (!file_exists($tmp_word_output)) {
            error_log("Unable to translate this Word document\n", 3, '/var/log/horde.log');
            return _("Unable to translate this Word document");
        }

        if (!is_readable($tmp_word_output)) {
            error_log("Unable to read translated Word document\n", 3, '/var/log/horde.log');
            return _("Unable to read translated this Word document");
        }

        $file_size_w = filesize($tmp_word);
        error_log("$tmp_word populated has $file_size_w bytes\n", 3, '/var/log/horde.log');

        exec($mime_drivers['horde']['msword']['location'] . $args . ' 2>&1' , $error);
        foreach($error as $errorline) {
            error_log("Error exec wvHtml: $errorline\n", 3, '/var/log/horde.log');
        }

        if (!file_exists($tmp_word_output)) {
            error_log("Unable to translate this Word document\n", 3, '/var/log/horde.log');
            return _("Unable to translate this Word document");
        }

        if (!is_readable($tmp_word_output)) {
            error_log("Unable to read translated Word document\n", 3, '/var/log/horde.log');
            return _("Unable to read translated this Word document");
        }

        $file_size = filesize($tmp_word_output);
        error_log("$tmp_word_output has $file_size bytes\n", 3, '/var/log/horde.log');
        $out = fopen($tmp_word_output, 'r');
        $data = '';
        while (($rc = fgets($out, 8192))) {
            $data .= $rc;
            error_log("data in loop: \"$data\"\n", 3, '/var/log/horde.log');
        }

        error_log("data: $data\n", 3, '/var/log/horde.log');
        return $data;
    }

    function getType()
    {
        return 'text/html';
    }
}

In the error_log, I get:

tmp_word file: /tmp/mswordjt8HBk
tmp_word_output_file: /tmp/msworduVw53u
tmp_dir is: /tmp
tmp_file is: msworduVw53u
args:  --targetdir=/tmp /tmp/mswordjt8HBk msworduVw53u
/tmp/mswordjt8HBk populated has 1 bytes
Error exec wvHtml: Diagnostic: (./wvWare.c:389)
/tmp/msworduVw53u has 0 bytes
data:
tmp_word file: /tmp/mswordkovRGC
tmp_word_output_file: /tmp/mswordCYbXe5
tmp_dir is: /tmp
tmp_file is: mswordCYbXe5
args:  --targetdir=/tmp /tmp/mswordkovRGC mswordCYbXe5
/tmp/mswordkovRGC populated has 1 bytes
Error exec wvHtml: Diagnostic: (./wvWare.c:389)
/tmp/mswordCYbXe5 has 0 bytes
data:


Obviously there's something wrong with the 0-sized output file. I can
run wvHtml without problem and get good output on command line.


Using the following:

    var_dump($this);

I get:

    object(mime_viewer_msword)(2) { ["mime_part"]=>  &object(mime_part)(8) { ["type"]=>  string(11)
"application" ["subtype"]=>  string(6) "msword" ["contents"]=>  string(1) ""USYDnetContentPolicyV3.doc"
["charset"]=>  string(8) "us-ascii" ["disposition"]=>  string(10) "attachment" } ["conf"]=>  array(4) {
["location"]=>  string(15) "/usr/bin/wvHtml" ["inline"]=>  bool(true) ["handles"]=>  array(4) { [0]=>
string(18) "application/msword" [1]=>string(8) "text/rtf" [2]=>  string(15) "x-extension/doc" [3]=>
string(15) "x-extension/rtf" } ["icons"]=>  array(1) { ["default"]=>  string(10) "msword.gif" } } }


Using the following:

    var_dump($this->mime_part->getContents());

I get:

    string(1) ""


Any help for further debugging would be appreciated.

Regards,




Jie




More information about the imp mailing list