[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-pim
Subject:    Re: [Kde-pim] KMail sendMessage() DCOP call fails to add attachments
From:       David Jarvie <lists () astrojar ! org ! uk>
Date:       2007-05-07 19:47:40
Message-ID: 200705072047.41386.lists () astrojar ! org ! uk
[Download RAW message or body]

On Saturday 05 May 2007 21:51:33 Ingo Klöcker wrote:
> On Saturday 05 May 2007 15:27, David Jarvie wrote:
> > There is a bug in the KMail sendMessage() DCOP call
> > (http://bugs.kde.org/show_bug.cgi?id=144958) whereby attachments are
> > not added to the message before being sent. This causes errors for
> > KAlarm which uses the DCOP call. The reason for the error is due to a
> > KIO job being used to access the attachment, but sendMessage()
> > doesn't wait for the job to complete before sending the message.
> >
> > I'd like to try to get this fixed for KDE 3.5.7. It could be that
> > this issue is already addressed elsewhere in KMail. If anybody could
> > give me a further pointer to such code (so as to produce a solution
> > which fits in with how KMail does things elsewhere), I'm willing to
> > look at it further and hopefully produce a patch.
>
> I don't think this situation is already addressed in KMail. I guess the
> same would happen if one added an attachment in the composer and then
> immediately clicked on the 'Send' button.

Attached is a patch which fixes the bug. It is designed to try to avoid 
messing up if more than one sendMessage() call is being processed 
simultaneously. OK to commit?

-- 
David Jarvie.
KAlarm author and maintainer.
http://www.astrojar.org.uk/kalarm

["kmail.diff" (text/x-diff)]

diff -u /home/david/src/svn/3.5/kdepim/kmail/composer.h ./composer.h
--- /home/david/src/svn/3.5/kdepim/kmail/composer.h	2006-06-08 22:06:57.000000000 \
                +0100
+++ ./composer.h	2007-05-07 12:47:25.000000000 +0100
@@ -42,6 +42,7 @@
      * From MailComposerIface
      */
     virtual void send( int how ) = 0;
+    virtual void addAttachmentsAndSend(const KURL::List &urls, const QString \
&comment, int how) = 0;  virtual void addAttachment( KURL url, QString comment ) = 0;
     virtual void addAttachment( const QString & name,
                                 const QCString & cte,
@@ -136,7 +137,7 @@
     virtual void autoSaveMessage() = 0;
 
   public: // kmkernel, attachmentlistview
-    virtual void addAttach( const KURL url ) = 0;
+    virtual bool addAttach( const KURL url ) = 0;
 
   public: // kmcommand
     /**
diff -u /home/david/src/svn/3.5/kdepim/kmail/kmcomposewin.cpp ./kmcomposewin.cpp
--- /home/david/src/svn/3.5/kdepim/kmail/kmcomposewin.cpp	2007-05-07 \
                13:52:46.000000000 +0100
+++ ./kmcomposewin.cpp	2007-05-07 14:07:39.000000000 +0100
@@ -461,6 +461,41 @@
 }
 
 //-----------------------------------------------------------------------------
+void KMComposeWin::addAttachmentsAndSend(const KURL::List &urls, const QString \
&/*comment*/, int how) +{
+  if (urls.isEmpty())
+  {
+    send(how);
+    return;
+  }
+  mAttachFilesSend = how;
+  mAttachFilesPending = urls;
+  connect(this, SIGNAL(attachmentAdded(const KURL&, bool)), \
SLOT(slotAttachedFile(const KURL&))); +  for( KURL::List::ConstIterator itr = \
urls.begin(); itr != urls.end(); ++itr ) { +    if (!addAttach( *itr ))
+      mAttachFilesPending.remove(mAttachFilesPending.find(*itr)); // only remove one \
copy of the url +  }
+
+  if (mAttachFilesPending.isEmpty() && mAttachFilesSend == how)
+  {
+    send(mAttachFilesSend);
+    mAttachFilesSend = -1;
+  }
+}
+
+void KMComposeWin::slotAttachedFile(const KURL &url)
+{
+  if (mAttachFilesPending.isEmpty())
+    return;
+  mAttachFilesPending.remove(mAttachFilesPending.find(url)); // only remove one copy \
of url +  if (mAttachFilesPending.isEmpty())
+  {
+    send(mAttachFilesSend);
+    mAttachFilesSend = -1;
+  }
+}
+
+//-----------------------------------------------------------------------------
 void KMComposeWin::addAttachment(KURL url,QString /*comment*/)
 {
   addAttach(url);
@@ -2220,13 +2255,13 @@
 }
 
 //-----------------------------------------------------------------------------
-void KMComposeWin::addAttach(const KURL aUrl)
+bool KMComposeWin::addAttach(const KURL aUrl)
 {
   if ( !aUrl.isValid() ) {
     KMessageBox::sorry( this, i18n( "<qt><p>KMail could not recognize the location \
                of the attachment (%1);</p>"
                                  "<p>you have to specify the full path if you wish \
                to attach a file.</p></qt>" )
                         .arg( aUrl.prettyURL() ) );
-    return;
+    return false;
   }
   KIO::TransferJob *job = KIO::get(aUrl);
   KIO::Scheduler::scheduleJob( job );
@@ -2238,10 +2273,12 @@
     ld.encoding = aUrl.fileEncoding().latin1();
 
   mMapAtmLoadData.insert(job, ld);
+  mAttachJobs[job] = aUrl;
   connect(job, SIGNAL(result(KIO::Job *)),
           this, SLOT(slotAttachFileResult(KIO::Job *)));
   connect(job, SIGNAL(data(KIO::Job *, const QByteArray &)),
           this, SLOT(slotAttachFileData(KIO::Job *, const QByteArray &)));
+  return true;
 }
 
 
@@ -2588,10 +2625,20 @@
 {
   QMap<KIO::Job*, atmLoadData>::Iterator it = mMapAtmLoadData.find(job);
   assert(it != mMapAtmLoadData.end());
+  KURL attachURL;
+  QMap<KIO::Job*, KURL>::iterator jit = mAttachJobs.find(job);
+  bool attachURLfound = (jit != mAttachJobs.end());
+  if (attachURLfound)
+  {
+    attachURL = jit.data();
+    mAttachJobs.remove(jit);
+  }
   if (job->error())
   {
     mMapAtmLoadData.remove(it);
     job->showErrorDialog();
+    if (attachURLfound)
+      emit attachmentAdded(attachURL, false);
     return;
   }
   if ((*it).insert)
@@ -2603,6 +2650,8 @@
     else
       mEditor->insert( QString::fromLocal8Bit( (*it).data ) );
     mMapAtmLoadData.remove(it);
+    if (attachURLfound)
+      emit attachmentAdded(attachURL, true);
     return;
   }
   const QCString partCharset = (*it).url.fileEncoding().isEmpty()
@@ -2697,6 +2746,8 @@
     if (!dlg.exec()) {
       delete msgPart;
       msgPart = 0;
+      if (attachURLfound)
+        emit attachmentAdded(attachURL, false);
       return;
     }
   }
@@ -2705,6 +2756,9 @@
 
   // add the new attachment to the list
   addAttach(msgPart);
+
+  if (attachURLfound)
+    emit attachmentAdded(attachURL, true);
 }
 
 
diff -u /home/david/src/svn/3.5/kdepim/kmail/kmcomposewin.h ./kmcomposewin.h
--- /home/david/src/svn/3.5/kdepim/kmail/kmcomposewin.h	2007-05-07 13:52:46.000000000 \
                +0100
+++ ./kmcomposewin.h	2007-05-07 14:10:12.000000000 +0100
@@ -111,6 +111,7 @@
    * From MailComposerIface
    */
   void send(int how);
+  void addAttachmentsAndSend(const KURL::List &urls, const QString &comment, int \
how);  void addAttachment(KURL url,QString comment);
   void addAttachment(const QString &name,
                     const QCString &cte,
@@ -253,6 +254,7 @@
   void slotPrint();
   void slotAttachFile();
   void slotInsertRecentFile(const KURL&);
+  void slotAttachedFile(const KURL&);
 public slots: // kmkernel, callback
   void slotSendNow();
 private slots:
@@ -454,7 +456,7 @@
   void alignmentChanged( int );
 
 public: // kmkernel, attachmentlistview
-  void addAttach(const KURL url);
+  bool addAttach(const KURL url);
 
 public: // kmcommand
   /**
@@ -470,6 +472,7 @@
 
 signals:
   void applyChangesDone( bool );
+  void attachmentAdded( const KURL&, bool success );
 
 private:
   /**
@@ -751,6 +754,9 @@
 
   QStringList mFolderNames;
   QValueList<QGuardedPtr<KMFolder> > mFolderList;
+  QMap<KIO::Job*, KURL> mAttachJobs;
+  KURL::List mAttachFilesPending;
+  int mAttachFilesSend;
 
 private:
   // helper method for slotInsert(My)PublicKey()
diff -u /home/david/src/svn/3.5/kdepim/kmail/mailserviceimpl.cpp \
                ./mailserviceimpl.cpp
--- /home/david/src/svn/3.5/kdepim/kmail/mailserviceimpl.cpp	2006-06-08 \
                22:06:58.000000000 +0100
+++ ./mailserviceimpl.cpp	2007-05-07 00:59:12.000000000 +0100
@@ -75,12 +75,7 @@
   KMail::Composer * cWin = KMail::makeComposer( msg );
   cWin->setCharset("", TRUE);
 
-  for( KURL::List::ConstIterator itr = attachments.begin();
-       itr != attachments.end(); ++itr ) {
-    cWin->addAttachment( *itr, "" );
-  }
-
-  cWin->send( 1 );//send now
+  cWin->addAttachmentsAndSend(attachments, "", 1);//send now
   return true;
 }
 



_______________________________________________
kde-pim mailing list
kde-pim@kde.org
https://mail.kde.org/mailman/listinfo/kde-pim
kde-pim home page at http://pim.kde.org/

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic