Question
I am using
MailInContrib with
MsOfficeAttachmentsAsHTMLPlugin. Both are working correctly on their own, but when I send an e-mail with a .doc attachment, it is not converted to HTML. Instead the attachment is converted to an HTML and saved to the Main.WebHome pub directory. I don't know if the problem is MailInContrib not correctly specifying what topic is being worked on or if MsOfficeAttachment is making some incorrect assumptions. Below is debug output when attaching a .doc directly and through MailInContrib. You can see for the second case that MsOfficeAttachment gets confused about what topic it's working on.
debug output when attaching .doc:
| 11 Sep 2007 - 08:53 | - TWiki::Plugins::MsOfficeAttachmentsAsHTMLPlugin::initPlugin( Sandbox.TestMail ) is OK
| 11 Sep 2007 - 08:53 | - TWiki::Plugins::MsOfficeAttachmentsAsHTMLPlugin::initPlugin( Sandbox.TestMail ) is OK
| 11 Sep 2007 - 08:53 | - MsOfficeAttachmentsAsHTMLPlugin::beforeAttachmentSaveHandler( Sandbox.TestMail)
| 11 Sep 2007 - 08:53 | attributes: HASH(0x8d84d84)
| 11 Sep 2007 - 08:53 | attachment = test.doc
| 11 Sep 2007 - 08:53 | comment =
| 11 Sep 2007 - 08:53 | user = Main.ChrisPurves
| 11 Sep 2007 - 08:53 | stream = test.doc
| 11 Sep 2007 - 08:53 | tmpFilename = /tmp/paqGNG7vCI
| 11 Sep 2007 - 08:53 | Hmm. Got a test.doc
| 11 Sep 2007 - 08:53 | Converting test.doc
| 11 Sep 2007 - 08:53 | $attachdir = /home/httpd/twiki/pub/Sandbox/TestMail
| 11 Sep 2007 - 08:53 | /usr/bin/wvHtml --targetdir=/home/httpd/twiki/pub/Sandbox/TestMail /tmp/paqGNG7vCI test.doc.txt
| 11 Sep 2007 - 08:53 |
| 11 Sep 2007 - 08:53 | after
| 11 Sep 2007 - 08:53 | Web = Sandbox Topic = TestMail
| 11 Sep 2007 - 08:53 | Before: $text = %META:TOPICINFO{author="ChrisPurves" date="1189522408" format="1.1" reprev="1.8" version="1.8"}%
percentMETA:FILEATTACHMENT{name="test.doc" attachment="test.doc" attr="" comment="" date="1189524772" path="test.doc" size="19968" stream="test.doc" tmpFilename="/tmp/GC5PJMTOun" user="Main.ChrisPurves" version="1"}percent
| 11 Sep 2007 - 08:53 | afterSaveHandler called: $text = %META:TOPICINFO{author="ChrisPurves" date="1189522408" format="1.1" reprev="1.8" version="1.8"}%
This text was automatically generated from the attachment test.doc
%INCLUDE{%ATTACHURL%/test.doc.txt}%
percentMETA:FILEATTACHMENT{name="test.doc" attachment="test.doc" attr="" comment="" date="1189524772" path="test.doc" size="19968" stream="test.doc" tmpFilename="/tmp/GC5PJMTOun" user="Main.ChrisPurves" version="1"}percent
$topic = TestMail, $web = Sandbox
| 11 Sep 2007 - 08:53 | Current Topic Page: %META:TOPICINFO{author="ChrisPurves" date="1189522408" format="1.1" reprev="1.8" version="1.8"}%
This text was automatically generated from the attachment test.doc
%INCLUDE{%ATTACHURL%/test.doc.txt}%
percentMETA:FILEATTACHMENT{name="test.doc" attachment="test.doc" attr="" comment="" date="1189524772" path="test.doc" size="19968" stream="test.doc" tmpFilename="/tmp/GC5PJMTOun" user="Main.ChrisPurves" version="1"}percent
| 11 Sep 2007 - 08:53 | Ok. writing Sandbox.TestMail
| 11 Sep 2007 - 08:53 | afterSaveHandler called: $text = %META:TOPICINFO{author="ChrisPurves" date="1189522408" format="1.1" reprev="1.8" version="1.8"}%
percentMETA:FILEATTACHMENT{name="test.doc" attachment="test.doc" attr="" comment="" date="1189524772" path="test.doc" size="19968" stream="test.doc" tmpFilename="/tmp/GC5PJMTOun" user="Main.ChrisPurves" version="1"}percent
$topic = TestMail, $web = Sandbox
| 11 Sep 2007 - 08:53 | - TWiki::Plugins::MsOfficeAttachmentsAsHTMLPlugin::initPlugin( Sandbox.TestMail ) is OK
debug output when attaching same file to e-mail:
| 11 Sep 2007 - 09:00 | - TWiki::Plugins::MsOfficeAttachmentsAsHTMLPlugin::initPlugin( Main.WebHome ) is OK
| 11 Sep 2007 - 09:00 | - MsOfficeAttachmentsAsHTMLPlugin::beforeAttachmentSaveHandler( Sandbox.TestMail)
| 11 Sep 2007 - 09:00 | attributes: HASH(0x8f508f4)
| 11 Sep 2007 - 09:00 | attachment = test.doc
| 11 Sep 2007 - 09:00 | comment = Submitted by e-mail
| 11 Sep 2007 - 09:00 | user = Main.ChrisPurves
| 11 Sep 2007 - 09:00 | stream = GLOB(0x8f84e74)
| 11 Sep 2007 - 09:00 | tmpFilename = /tmp/3P5FYRA1j7
| 11 Sep 2007 - 09:00 | Hmm. Got a test.doc
| 11 Sep 2007 - 09:00 | Converting test.doc
| 11 Sep 2007 - 09:00 | $attachdir = /home/httpd/twiki/pub/Main/WebHome
| 11 Sep 2007 - 09:00 | /usr/bin/wvHtml --targetdir=/home/httpd/twiki/pub/Main/WebHome /tmp/3P5FYRA1j7 test.doc.txt
| 11 Sep 2007 - 09:00 |
| 11 Sep 2007 - 09:00 | after
| 11 Sep 2007 - 09:00 | afterSaveHandler called: $text = %META:TOPICINFO{author="ChrisPurves" date="1189522841" format="1.1" reprev="1.8" version="1.8"}%
percentMETA:FILEATTACHMENT{name="test.doc" attachment="test.doc" attr="" comment="Submitted by e-mail" stream="GLOB(0x8f84e74)" tmpFilename="/tmp/3P5FYRA1j7" user="Main.ChrisPurves" version="1"}percent
$topic = TestMail, $web = Sandbox
| 11 Sep 2007 - 09:00 | afterSaveHandler called: $text = %META:TOPICINFO{author="ChrisPurves" date="1189522841" format="1.1" reprev="1.8" version="1.8"}%
* *test e-mail attachment*:
-- Main.ChrisPurves - 11 Sep 2007 - 09:00 * test.doc
percentMETA:FILEATTACHMENT{name="test.doc" attachment="test.doc" attr="" comment="Submitted by e-mail" stream="GLOB(0x8f84e74)" tmpFilename="/tmp/3P5FYRA1j7" user="Main.ChrisPurves" version="1"}percent
$topic = TestMail, $web = Sandbox
Environment
--
ChrisPurves - 10 Sep 2007
Answer
If you answer a question - or someone answered one of your questions - please remember to edit the page and set the status to answered. The status selector is below the edit box.
IANAPP
The problem, from what I could see, is that when initPlugin is called it uses Main.WebHome as the web and topic. Later, when beforeAttachmentSaveHandler is called, the web and topic are reset, but where beforeAttachmentSaveHandler calls other subroutines, the web and topic variables set with initPlugin are used instead. A similar thing happens with afterSaveHandler. I believe this is caused because the variables are stored only locally with beforeAttachmentSaveHandler and afterSaveHandler as
my $topic....
To resolve this I made $topic and $web set by beforeAttachmentSaveHandler global instead of local in order to override the incorrect values set by initPlugin.
sub beforeAttachmentSaveHandler {
### my ( $attachmentAttr, $topic, $web ) = @_; # do not uncomment, use $_[0],
$_[1]... instead
my $attachmentAttr = $_[0];
my $topic = $_[1];
my $web = $_[2];
becomes
sub beforeAttachmentSaveHandler {
### my ( $attachmentAttr, $topic, $web ) = @_; # do not uncomment, use $_[0],
$_[1]... instead
my $attachmentAttr = $_[0];
$topic = $_[1];
$web = $_[2];
--
ChrisPurves - 11 Sep 2007