Bug 130709 - can't open attachments using apps that immediately return
Summary: can't open attachments using apps that immediately return
Status: RESOLVED FIXED
Alias: None
Product: kmail
Classification: Unclassified
Component: general (show other bugs)
Version: unspecified
Platform: unspecified Linux
: NOR normal with 2 votes (vote)
Target Milestone: ---
Assignee: kdepim bugs
URL:
Keywords:
: 114707 115703 115834 128553 133385 138102 138752 140085 140690 143670 145409 149537 (view as bug list)
Depends on:
Blocks:
 
Reported: 2006-07-12 17:59 UTC by Elmar
Modified: 2009-11-18 08:50 UTC (History)
19 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Elmar 2006-07-12 17:59:35 UTC
Version:           1.9.1 (using KDE 3.5.1 Level "a" , SUSE 10.1)
Compiler:          Target: i586-suse-linux
OS:                Linux (i686) release 2.6.16.13-4-smp

It is not possible, to open .doc or .otd attachment files with OpenOffice.
I get the errormessage that the file do not exist in /tmp -folder.
With .pdf or any other atteachments I get no probblems.
Comment 1 Ingo Klöcker 2006-07-14 00:16:21 UTC
Did you probably select another message while OpenOffice was still starting up?
Comment 2 Elmar 2006-07-17 18:03:02 UTC
No, I select only one message without a (before) started OpenOffice!
It's strange, isn't it?
Comment 3 Jonathan Marten 2006-10-29 16:48:32 UTC

*** This bug has been marked as a duplicate of 39537 ***
Comment 4 Jonathan Marten 2006-10-29 17:17:42 UTC
KDE-PIM bug weekend:  Still reported as a problem, but only in certain cases.
(openoffice works for some, gimp doesn't).  Reopening for further investigation.
Comment 5 Philip Rodrigues 2006-11-30 20:40:05 UTC
*** Bug 138102 has been marked as a duplicate of this bug. ***
Comment 6 Philip Rodrigues 2006-11-30 20:43:47 UTC
As per bug 138102, here's an analysis:

kmail calls amarok, which (almost immediately) returns, having run some subprocess, or whatever. KMail/KIO says "oh, the app's done" and removes the file from /tmp, so amarok can't open it.

For an easy example, try opening an mp3 with the following shell script:
#!/bin/sh
nohup mpg123 $1 &
exit

It will fail :-). If you remove the 'nohup' and the '&' it works fine.
Comment 7 Jonathan Marten 2006-12-01 20:23:34 UTC
*** Bug 133385 has been marked as a duplicate of this bug. ***
Comment 8 Jonathan Marten 2006-12-01 20:35:28 UTC
KMail opens the attachment using KRun::run(), with the tempFiles option set to true.  That eventually runs kioexec in a subprocess with the --tempfiles option, which runs the real application in another subprocess to open the file.  When that application finishes and returns to kioexec, the temporary file is deleted.

Unfortunately, if the application forks and the parent process exits immediately, as desktop applications often do, kioexec will delete the file before the forked application has had the chance to read it.

One solution would be to modify kioexec to not delete the temporary file immediately - wait for a reasonable time so that even if the application does fork it will have time to start up and read the file before it gets deleted:

--- kdelibs-3.5svn/kio/kioexec/main.cpp (revision 607803)
+++ kdelibs-3.5svn/kio/kioexec/main.cpp (working copy)
@@ -260,6 +260,10 @@ void KIOExec::slotRunApp()
             if (!tempfiles && dest.isLocalFile())
                 continue;
         }
+
+       kdDebug() << "sleeping..." << endl;
+       sleep(120);
+       kdDebug() << "about to delete " << QFile::encodeName(src) << endl;
         unlink( QFile::encodeName(src) );
     }

Doing this fixes the attachment opening problem (unless the application takes more than 2 minutes to start up :-)  However, I don't know whether there will be implications for any other users of kioexec or KRun.

Should this bug be reassigned to kdelibs/kio?
Comment 9 Philip Rodrigues 2006-12-01 20:58:24 UTC
Yes, it should be reassigned :-)
Comment 10 Philip Rodrigues 2006-12-12 00:10:55 UTC
*** Bug 114707 has been marked as a duplicate of this bug. ***
Comment 11 Jonathan Marten 2006-12-13 18:17:08 UTC
*** Bug 138752 has been marked as a duplicate of this bug. ***
Comment 12 Philip Rodrigues 2007-01-11 19:37:24 UTC
*** Bug 128553 has been marked as a duplicate of this bug. ***
Comment 13 Eckhart Wörner 2007-01-27 01:01:16 UTC
*** Bug 140690 has been marked as a duplicate of this bug. ***
Comment 14 Elmar 2007-02-03 14:05:17 UTC
After error message, if I try to open the attachment a second time, it works.
Comment 15 Ferdinand Gassauer 2007-02-03 14:49:08 UTC
see also
http://bugs.kde.org/show_bug.cgi?id=140953
which might be a different imap related thing
Comment 16 Maciej Pilichowski 2007-02-03 14:52:03 UTC
Elmar, what kind of WORKSFORME is this? "After an error"? Yeah, not counting errors there are hardly any bugs in software.
Comment 17 Elmar 2007-02-03 15:06:55 UTC
I get the errormessage that the file do not exist in /tmp -folder.
Comment 18 Maciej Pilichowski 2007-02-03 15:38:57 UTC
I am aware of that. But you set the status to worksforme, because when you try the second time it works. It is a workaround of the bug, this does not resolve the problem.
Comment 19 Jonathan Marten 2007-02-03 16:29:30 UTC
And it may or may not worksforme, due to timing issues - if the application is already in memory the second time, it will respond faster and possibly open the temporary file in time.  So leaving the bug open until it gets resolved.
Comment 20 Jonathan Marten 2007-02-03 16:41:27 UTC
See also bug 94336, possible duplicate

Comment 21 Jonathan Marten 2007-02-04 20:45:36 UTC
Bug 94336 is also the same root cause, but with an added complication.
Comment 22 Jonathan Marten 2007-02-04 20:46:01 UTC
*** Bug 94336 has been marked as a duplicate of this bug. ***
Comment 23 David Faure 2007-02-04 21:21:22 UTC
Amarok needs to implement --tempfile so that it says "I handle the deletion of the tempfile myself". With X-KDE-HasTempFileOption=true in its .desktop file, it can indicate that it supports the option, and then kmail/kioexec won't delete the file, amarok will. This is necessary in all kde applications which have a helper binary that talks to the running program - like amarok/amarokapp and kfmclient/konqueror.

For OpenOffice (when it's already running), I don't know a good solution. I guess we need a last-resort option, basically a "delete this temp file in a very long time (or never)" (in kio) for those apps which cannot implement proper handling of tempfiles.
Comment 24 Ferdinand Gassauer 2007-02-04 22:32:12 UTC
IMHO it is necessary for all (?) applications to handle "remote" files the way described in 
http://bugs.kde.org/show_bug.cgi?id=130709#c23

to achieve the network transparency wich KDE is claiming to provide.

How can this be checked / implemented ?
Comment 25 David Faure 2007-02-05 00:21:35 UTC
All KDE applications support remote files via KIO, that's not the problem here.
The problem is temporary files (they are local, not remote, and they need to be deleted), and temporary files are only a problem for applications that "talk to a running instance" (like kfmclient, amarok and openoffice.org). No problem for kedit, for instance: you open kedit on the temp file, and whenever kedit is closed, kioexec deletes the tempfile.
Comment 26 Ferdinand Gassauer 2007-02-08 19:18:48 UTC
David, does your explanation in
http://bugs.kde.org/show_bug.cgi?id=130709#c25
explains 
http://bugs.kde.org/show_bug.cgi?id=140953#c2 ?

Comment 27 David Faure 2007-02-08 19:53:10 UTC
No, online imap and loading attachments on demand or not, is probably another problem.
Of which I have no clue about; I use (and wrote parts of) cached imap, but not online imap.
Probably another code path that deals with tempfiles.
Comment 28 David Faure 2007-03-11 23:45:07 UTC
Reassigning to amarok, see comment #23.
Comment 29 Thomas McGuire 2007-03-31 19:14:23 UTC
*** Bug 143670 has been marked as a duplicate of this bug. ***
Comment 30 Thomas McGuire 2007-04-09 21:08:56 UTC
Assigning back to KMail. The original problem is with OpenOffice, and it seems not solved yet.

Anyone having the same problem with Amarok should open a new bug report there if none exists yet.
Comment 31 Jason 'vanRijn' Kasper 2007-04-09 21:14:58 UTC
This problem exists with OpenOffice as well, or at least this problem is exhibited when the ooffice quickstart applet is running.  Is it really the right approach to expect all of the applications that exhibit the same problem (kaffeine, openoffice quickstart, amarok, etc.) to have to deal with this problem?  Shouldn't this be addressed in the kde code that deals with tempfile creation/destruction?  Is it possible for that code to create the tempfile, sleep X amount of time, and then loop looking for still-open filehandles in the OS before unlink()ing the tempfile?
Comment 32 Jonathan Marten 2007-04-12 09:35:07 UTC
This bug is getting thrown back and forth between various owners, with no resolution in sight yet.  Could at least the fix (=hack, acknowledged) in comment#8 be accepted into kdelibs - this would fix the problem in the common cases with the most popular applications, and avoid the duplicate bug reports.
Comment 33 David Faure 2007-04-12 11:35:39 UTC
SVN commit 652915 by dfaure:

forwardport 652914:
OK, we can wait 3mn before deleting a tempfile, if it helps with apps that fork on startup like OOo or amarok.
Thanks to Jonathan Marten for the idea and patch.
BUG: 130709


 M  +9 -2      main.cpp  


--- trunk/KDE/kdebase/runtime/kioexec/main.cpp #652914:652915
@@ -240,9 +240,16 @@
             }
         }
 
-        // don't delete a local file, except it is defined to be temporary (with --tempfiles switch)
-        if ( !dest.isLocalFile() || tempfiles )
+        if ( !dest.isLocalFile() ) {
             unlink( QFile::encodeName(src) );
+        } else if ( tempfiles ) {
+            // Wait for a reasonable time so that even if the application forks on startup (like OOo or amarok)
+            // i will have time to start up and read the file before it gets deleted. #130709.
+            kdDebug() << "sleeping..." << endl;
+            sleep(180); // 3 mn
+            kdDebug() << "about to delete " << src << endl;
+            unlink( QFile::encodeName(src) );
+        }
     }
 
     QApplication::exit(0);
Comment 34 Jason 'vanRijn' Kasper 2007-04-12 13:22:09 UTC
Thanks David!!  =:)
Comment 35 Ferdinand Gassauer 2007-04-12 17:58:49 UTC
Please could someone cross check -

opening documents (excel , oasis) with OO from sftp connections does not work any more - 
If OO is not runnning - I get the splash screen, but OO exists immediatly afterwards.
If OO is running - it exists immediately.

kspread works, gnumeric asks for password and opens.

cu
Comment 36 David Faure 2007-04-12 18:08:10 UTC
On Thursday 12 April 2007, Ferdinand Gassauer wrote:
> opening documents (excel , oasis) with OO from sftp connections does not work any more - 
> If OO is not runnning - I get the splash screen, but OO exists immediatly afterwards.
> If OO is running - it exists immediately.

Ah, right. Remote documents in non-kde apps need the same treatment as temp files from e.g. kmail.
I'll adjust the fix.
Comment 37 David Faure 2007-04-12 18:11:33 UTC
SVN commit 653071 by dfaure:

Wait before deleting the tempfile in the "tempfile due to opening a remote file" case too, of course.
CCBUG: 130709


 M  +2 -4      main.cpp  


--- branches/KDE/3.5/kdelibs/kio/kioexec/main.cpp #653070:653071
@@ -255,11 +255,9 @@
             }
         }
 
-        if ( !dest.isLocalFile() ) {
-            unlink( QFile::encodeName(src) );
-        } else if ( tempfiles ) {
+        if ( !dest.isLocalFile() || tempfiles ) {
             // Wait for a reasonable time so that even if the application forks on startup (like OOo or amarok)
-            // i will have time to start up and read the file before it gets deleted. #130709.
+            // it will have time to start up and read the file before it gets deleted. #130709.
             kdDebug() << "sleeping..." << endl;
             sleep(180); // 3 mn
             kdDebug() << "about to delete " << src << endl;
Comment 38 Ferdinand Gassauer 2007-04-12 20:27:25 UTC
Hi David!
the patch  #37 didn't help

trying to open a sftp-xls I get this


konqueror: KonqMainWindow::openView ok=false bOthersFollowed=false returning false
konqueror: emit m_extension->openURLRequest( sftp://gass@sw-ssh:22001/daten/dos/private/gass/kg_stat.xls,application/msexcel)
konqueror: KonqMainWindow::slotOpenURLRequest frameName=
konqueror: KonqMainWindow::openURL (from slotOpenURLRequest) url=sftp://gass@sw-ssh:22001/daten/dos/private/gass/kg_stat.xls
konqueror: KonqMainWindow::openURL : url = 'sftp://gass@sw-ssh:22001/daten/dos/private/gass/kg_stat.xls'  serviceType='application/msexcel req=[]' view=0xb0aa70
konqueror: trying openView for sftp://gass@sw-ssh:22001/daten/dos/private/gass/kg_stat.xls (serviceType application/msexcel)
kio (KTrader): KServiceTypeProfile::offers serviceType=application/msexcel genericServiceType=Application
konqueror: KonqMainWindow::openView application/msexcel sftp://gass@sw-ssh:22001/daten/dos/private/gass/kg_stat.xls 0xb0aa70 req:[]
konqueror: KonqMainWindow::openView application/msexcel sftp://gass@sw-ssh:22001/daten/dos/private/gass/kg_stat.xls 0xa7a840 req:[followMode]
konqueror: KonqView::openURL url=sftp://gass@sw-ssh:22001/daten/dos/private/gass/kg_stat.xls locationBarURL=sftp://gass@sw-ssh:22001/daten/dos/private/gass/kg_stat.xls
konqtree: KonqDirTree::followURL: sftp://gass@sw-ssh:22001/daten/dos/private/gass/kg_stat.xls
konqtree: KonqDirTree::followURL: Not found
libkonq: ## addToHistory: sftp://gass@sw-ssh:22001/daten/dos/private/gass/kg_stat.xls Typed URL: sftp://gass@sw-ssh:22001/daten/dos/private/gass/kg_stat.xls, Title:
konqueror: KonqMainWindow::openView ok=true bOthersFollowed=false returning true
libkonq: No X-KDE-AutoEmbed, looking for group
libkonq: KonqFMSettings::shouldEmbed : serviceTypeGroup=application
konqueror: openView: KonqFMSettings says: don't embed this servicetype
konqueror: KonqMainWindow::openView ok=false bOthersFollowed=false returning false

does it help - or is it a different thing.
Comment 39 David Faure 2007-04-13 00:31:03 UTC
On Thursday 12 April 2007, Ferdinand Gassauer wrote:
> konqueror: KonqMainWindow::openView ok=false bOthersFollowed=false returning false


The question is what happens after that.
And can you see a kioexec process (e.g. in ksysguard) after clicking on the file?
Comment 40 Ferdinand Gassauer 2007-04-13 07:27:18 UTC
the command
kioexec oocalc sftp://gass@sw-ssh:22001/daten/dos/private/gass/kg_stat.xls
works
so it must be elsewhere - I'll recompile kdelibs and kdebase
Comment 41 Ferdinand Gassauer 2007-04-13 15:35:20 UTC
Att: David!

Is I said before kioexec works fine if called from the command line, both if OO is open or not and writes back the changes to the sftp directory after closing all instances of OO. IMHO to late as many/most users will keep OO open for the working day. We have discussed this matter already many,many month ago.

Could it be that konqueror calls kioexec for sftp files with --tempfiles switch?

kioexec --tempfiles swriter sftp://gass@sw-ssh:22001/daten/dos/private/gass/ASP-offen1.doc

I get this:
 
Remote URL
sftp://gass@sw-ssh:22001/daten/dos/private/gass/ASP-offen1.doc
not allowed with --tempfiles switch

and kioexec exits. 

BTW: I do not get the errormessage with konqueror
Comment 42 Andres Mujica - SEAQ 2007-05-06 03:45:28 UTC
Hi. i'm linking this bug to bug #70981 reported in Ubuntu

https://bugs.launchpad.net/kdepim/+bug/70981

I hope this can be addressed soon.

Thanks a lot for your help
Comment 43 Andres Mujica - SEAQ 2007-05-06 03:48:32 UTC
please note that the bug # provided before (C42) corresponds to the associated bug report in Ubuntu's Launchpad.

Thanks
Comment 44 michael 2007-05-08 04:18:06 UTC
I would like to note, that not only OO attachments fail, but often others like kview, acroreader et al also exhibit the same behavior.  The one thing that is referenced in the comments, but doesn't seem to be fully explained is why the naming convention mismatch, ie the tmp files are in the tmp directory, but with a different name, (ie without the _(random_chars) inserted in the file name.
Comment 45 Thomas McGuire 2007-05-08 15:50:38 UTC
*** Bug 140085 has been marked as a duplicate of this bug. ***
Comment 46 Maciej Pilichowski 2007-05-23 14:16:23 UTC
KDE 3.5.7 with OOWriter -- still does not work. Even if I load OOWriter in advance still, the attached doc is not opened.

Is the status FIXED really applies here?
Comment 47 m.wege 2007-05-23 15:12:35 UTC
works here with kubuntu (Feisty) and KDE 3.5.7 with .doc and .odt
Comment 48 Jonathan Marten 2007-05-23 15:17:22 UTC
Comment #46: WORKSFORME here with oowriter and any supported type of attachment.  Note that oowriter does not fork the application, so the race condition for deleting the temporary file should not apply here anyway.

Could you attach the results of:

grep kioexec ~/.xsession-errors

(or whatever log file receives the KDE debug output)?
Comment 49 Maciej Pilichowski 2007-05-23 15:51:08 UTC
Hmm, I tuned it a bit and it works, but I am not sure where the sub-bug lies.

Jonathan (#48 comment) grep shows nothing, I didn't switch KDE debug output (I believe), so if it is the default one, there is no info here.

I tested KDE 3.5.7 + OO 2.1, it failed. Then I tested with OO 2.2. It also failed, but I noticed that KMail asks about OO Writer 2.1. I went to file association, move OO Writer up (the order was OOW 2.1, OOW, OOW2.0 ???, KWord). Apply. I tested, it finally works.

Was it a problem with packaging of OO, that it didn't register correctly?
Comment 50 Christoph Probst 2007-06-01 13:38:35 UTC
For what it's worth:

You can easily workaround this bug by creating a wrapper script sleeping a while before returning:

  chris@nisroc:~/bin$ cat ooffice-delay
  #!/bin/bash
  ooffice "$@"
  sleep 180

If you start opening your office documents using this wrapper you will be able to open all documents as expected.
Comment 51 Bram Schoenmakers 2007-07-15 01:16:10 UTC
*** Bug 145409 has been marked as a duplicate of this bug. ***
Comment 52 Thomas McGuire 2007-07-17 15:00:34 UTC
*** Bug 115703 has been marked as a duplicate of this bug. ***
Comment 53 Andres Mujica - SEAQ 2007-08-10 02:59:54 UTC
I don't believe that comment #50 is a valid solution for this bug.  Why an user must create a script to open an office file, if he always opens such a file directly wiht openoffice???

this won't help linux on the desktop at all..

Please consider your users

Thanks a lot!!
Comment 54 Thomas McGuire 2007-08-10 12:18:49 UTC
*** Bug 115834 has been marked as a duplicate of this bug. ***
Comment 55 Tommi Tervo 2007-09-04 13:13:12 UTC
*** Bug 149537 has been marked as a duplicate of this bug. ***
Comment 56 Toni 2009-07-20 21:03:23 UTC
What i can confirm:

Clickin on an ODS file in konqueror:sftp/fish does not work. I get the OpenOffice splash screen, but OO exists immediatly afterwards.

Konqueror 3.5.9
KDE 3.5.10
OpenOffice 2.4.1
Debian Lenny/stable
Comment 57 David Faure 2009-11-18 02:41:14 UTC
Did anyone experience this bug with KDE 4?
Comment 58 Franklin Weng 2009-11-18 02:45:22 UTC
(In reply to comment #57)
> Did anyone experience this bug with KDE 4?

Not here.
Comment 59 m.wege 2009-11-18 08:50:11 UTC
no