Bug 81989 - kmail need to support HTML signature
Summary: kmail need to support HTML signature
Status: RESOLVED FIXED
Alias: None
Product: kmail
Classification: Applications
Component: composer (show other bugs)
Version: unspecified
Platform: Gentoo Packages Linux
: NOR wishlist
Target Milestone: ---
Assignee: kdepim bugs
URL:
Keywords:
: 158028 (view as bug list)
Depends on:
Blocks:
 
Reported: 2004-05-22 03:44 UTC by Mathieu Jobin
Modified: 2008-11-08 13:32 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
patch to strip html from signatures (1.09 KB, patch)
2004-07-17 05:00 UTC, Ben Smith
Details
Patch to enable HTMl signatures (2.94 KB, patch)
2005-01-24 20:15 UTC, Jason Keirstead
Details
HTML signature (7.51 KB, patch)
2008-01-23 20:54 UTC, Edwin Schepers
Details
HTML signature (kdepimlibs) (3.02 KB, patch)
2008-01-23 20:56 UTC, Edwin Schepers
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Mathieu Jobin 2004-05-22 03:44:18 UTC
Version:            (using KDE KDE 3.2.2)
Installed from:    Gentoo Packages
OS:                Linux

kmail need to support HTML signature

right now, the code are just pasted, as a plain/text signature
Comment 1 Eduardo Silva 2004-05-30 12:44:11 UTC
This also ahppens in kde 3.3.0 alpa, even though kmail now supports formatting HTML mail. This need to be supported.
Comment 2 Ben Smith 2004-07-17 05:00:39 UTC
Created attachment 6704 [details]
patch to strip html from signatures

Well, until this gets fixed, here's something to at least make things a little
nicer and mirror some functionality of Evolution.  This patch uses some code
borrowed from kmmessage.cpp to strip the HTML from signatures.
Comment 3 Avi Alkalay 2004-08-29 16:10:26 UTC
I also want nice HTML-formated signatures, including images (that should probably be attached), etc.
Comment 4 Jason Keirstead 2005-01-24 20:15:18 UTC
Created attachment 9268 [details]
Patch to enable HTMl signatures

Here is a patch to add full HTML signature support. It tries to auto-detect if
the signature has HTML in it. If so, and you have FOrmatting (HTML) enabled,
the signature will be inserted as HTML.
Comment 5 Manolo Canga 2005-01-24 20:27:51 UTC
why dont 
http://bugs.kde.org/show_bug.cgi?id=97603 
?
Comment 6 Martin Köbele 2005-08-08 16:09:45 UTC
yes, please add this feature, I need it as well!! :)
Thanks!
Comment 7 Martin Köbele 2005-08-09 14:18:40 UTC
I applied that patch on kde 3.4.2's kmail: it works :)

please port it to current trunk
Comment 8 Martin Köbele 2005-08-09 14:36:44 UTC
oh I found a bug in that patch:

if you have several identities with different html signatures, the signature is not  changed when you change the indentity.
Comment 9 Martin Köbele 2005-08-09 14:54:27 UTC
another bug: replying and forwarding destroys the formatting: each line becomes its own paragraph (<p>).
The colouring of quotes won't work anymore either.

Comment 10 Rich Birch 2005-10-06 18:32:32 UTC
I've taken a look at how other clients do this and it seems that both mozilla 
firebird and outlook send html signatures as attachments. Doing it this way 
provides a way of displaying images within the html by also sending them as 
attachments.

I'm gonna have a dig in the code to see if it might be simple enough to 
implement this way.
Comment 11 Paulo Fidalgo 2006-07-02 17:59:11 UTC
Hi!
This is still missing on the current stable kmail.
Any chance to get it?
Comment 12 brazzmonkey 2006-10-26 17:11:53 UTC
i really need this feature... my boss is driving me nuts because my signature cannot be compliant to my company's standards.
Comment 13 Allen Winter 2006-10-26 18:59:47 UTC
SVN commit 599323 by winterz:

FEATURE: HTML Signatures

Apply patch that Jason Keirstead provided over 1.5 years ago.
Please test.

CCMAIL: jason@keirstead.org
CCBUGS: 81989


 M  +55 -7     branches/work/kdepim-3.5.5+/kmail/kmcomposewin.cpp  
 M  +6 -0      branches/work/kdepim-3.5.5+/kmail/kmcomposewin.h  


--- branches/work/kdepim-3.5.5+/kmail/kmcomposewin.cpp #599322:599323
@@ -3498,7 +3498,7 @@
 #undef KeyPress
 #endif
 
-  QKeyEvent k(QEvent::KeyPress, Key_C , 0 , ControlButton);
+  QKeyEvent k(QEvent::KeyPress, Key_C, 0, ControlButton);
   kapp->notify(fw, &k);
 }
 
@@ -3518,7 +3518,7 @@
 #undef KeyPress
 #endif
 
-    QKeyEvent k(QEvent::KeyPress, Key_V , 0 , ControlButton);
+    QKeyEvent k(QEvent::KeyPress, Key_V, 0, ControlButton);
     kapp->notify(fw, &k);
   }
 
@@ -4029,19 +4029,67 @@
 {
   bool mod = mEditor->isModified();
 
-  const KPIM::Identity & ident =
-    kmkernel->identityManager()->identityForUoidOrDefault( mIdentity->currentIdentity() );
+  const KPIM::Identity &ident =
+    kmkernel->identityManager()->
+    identityForUoidOrDefault( mIdentity->currentIdentity() );
+
   mOldSigText = ident.signatureText();
+  kdDebug() << "KMAIL: APPEND SIG " << mOldSigText << endl;
   if( !mOldSigText.isEmpty() )
   {
-    mEditor->append(mOldSigText);
-    mEditor->setModified(mod);
+    mEditor->sync();
+    kdDebug() << "KMAIL: HAS A SIG TO APPEND" << endl;
+    bool sigHasTags =
+      mOldSigText.contains( QRegExp( QString::fromLatin1( "<[^>]*>" ) ) );
+
+    if( markupAction->isChecked() && sigHasTags ) {
+      kdDebug() << "KMAIL: TOGGLE MARKUP TRUE" << endl;
+      // Turn on markup since we have an HTML sig
+      toggleMarkup( true );
+
+      // Replace separator linefeed, will always be this format according
+      // to Signature
+      mOldSigText = QString::fromLatin1( "--<p>" ) + mOldSigText.mid( 4 );
+
+      // Note - Can't use append() because it always inserts plain text
+      mEditor->setText( mEditor->text() +
+                        QString::fromLatin1( "<p>" ) + mOldSigText );
+    } else {
+      kdDebug() << "KMAIL: NOT AN HTML SIG" << endl;
+      mEditor->append( sigHasTags ? stripHTML( mOldSigText ) : mOldSigText );
+    }
+
+    mEditor->update();
+    mEditor->setModified( mod );
     mEditor->setContentsPos( 0, 0 );
-    mEditor->sync();
   }
 }
 
+QString KMComposeWin::stripHTML( const QString &str )
+{
+  QRegExp htmlTags( QString::fromLatin1( "<[^>]*>" ) );
+  QString data = str;
 
+  //remove linebreak and multiple spaces
+  data.replace( QRegExp( QString::fromLatin1( "\\s*[\n\r\t]+\\s*" ), false ),
+                QString::fromLatin1(" " )) ;
+  data.replace( QRegExp( QString::fromLatin1( "< */ *p[^>]*>" ), false ),
+                QString::fromLatin1( "\n" ) );
+  data.replace( QRegExp( QString::fromLatin1( "< */ *div[^>]*>" ), false ),
+                QString::fromLatin1( "\n" ) );
+  data.replace( QRegExp( QString::fromLatin1( "< *br */? *>" ), false ),
+                QString::fromLatin1( "\n" ) );
+  data.replace( htmlTags, QString::null );
+
+  data.replace( QString::fromLatin1( "&gt;" ), QString::fromLatin1( ">" ) );
+  data.replace( QString::fromLatin1( "&lt;" ), QString::fromLatin1( "<" ) );
+  data.replace( QString::fromLatin1( "&quot;" ), QString::fromLatin1( "\"" ) );
+  data.replace( QString::fromLatin1( "&nbsp;" ), QString::fromLatin1( " " ) );
+  data.replace( QString::fromLatin1( "&amp;" ), QString::fromLatin1( "&" ) );
+
+  return data;
+}
+
 //-----------------------------------------------------------------------------
 void KMComposeWin::slotHelp()
 {
--- branches/work/kdepim-3.5.5+/kmail/kmcomposewin.h #599322:599323
@@ -630,6 +630,12 @@
                KMComposeWin::SaveIn saveIn = KMComposeWin::None );
 
   /**
+   * Returns a string contains the input string @p str that has been striped of
+   * all @acronym HTML tags.
+   */
+  QString stripHTML( const QString &str );
+
+  /**
    * Returns the autosave interval in milliseconds (as needed for QTimer).
    */
   int autoSaveInterval() const;
Comment 14 Allen Winter 2006-10-26 19:02:28 UTC
s some of you might now, we are in the process of testing a new kdepim features branch.  You might want to read my blog for some details:

http://www.kdedevelopers.org/blog/1451

Anyhow, I am committing Jason's patch that is included in this bug report to the kmail that is in that new branch.

But I don't know the typical use case for html signatures so I need some folks to help test.

I'll put up a new blog entry with more info soon.
Comment 15 brazzmonkey 2006-10-26 19:05:48 UTC
i don't have the faintest idea about how to apply this patch...
guidelines welcome.
thanks.

Le jeudi 26 octobre 2006 18:59, Allen Winter a écrit :
[bugs.kde.org quoted mail]
Comment 16 Allen Winter 2006-10-26 20:00:08 UTC
Then please don't even try.

I wasn't clear.  I should have stated to apply the patch if you know how to compile and install the KDE software (or know someone who will help you).
Comment 17 Alessandro Grande 2007-04-01 23:53:54 UTC
Are there any news about html signature? I've installed kde 3.5.6 and it's not supported yet.
Comment 18 Thomas McGuire 2007-04-02 23:06:32 UTC
>Are there any news about html signature? I've installed kde 3.5.6 and it's not supported yet. 
It is not yet supported in the main branch, only in the PIM 3.5.5+ branch, If you want to try this, you need to manually compile the subversion checkout from there.

http://techbase.kde.org/Projects/kdepim/Installing_the_KDE_PIM_3.5.5+_feature_branch

Note that that branch also contains unstable, crashy things like label support.
Comment 19 Fred van Zwieten 2007-09-05 10:01:30 UTC
I'll give this more votes, because it is really needed!! I'm trying to convince my wife to switch to KDE, but if she can't compose nice colourfull mail's with ditto sig's, it's a nono.
Comment 20 Mathieu Jobin 2007-09-06 05:14:37 UTC
in the mean time, she could use a different email client than kmail?

switching to KDE is a great thing. if she does not use kmail for a year or two yet. it is still awesome.

I dont know of any client who does html signature though, so sorry no suggestion.

but get her to switch. gambatte.
Comment 21 John Murphy 2007-09-06 05:38:58 UTC
On Kmail 1.9.6, KDE 3.5.7: 
Best way to add a HTML signature is to create a HTML file (say with NVU), then go to the template folder (should be under drafts folder) and create a template and attach that HTML file.  Next, while still in the Message, open the properties of the HTML file and choose "Suggest Automatic Display" and make sure the type (at the top of the panel) is text/html.  Now save it back into the templates folder and you will see it does what you want.  Use the template every time you need a new email - you can send it straight from the template folder without having to re-create the original.  So now you have the ability to write a non-html e-mail (and please the purists) but send it with a HTML attachment (and then infuriate them).  Best of all worlds really
Comment 22 Manfred Moser 2007-09-28 18:16:51 UTC
Our corporate signature I have to use is a html snippet including an image. I tried Johns approach, but I cant seem to get the image to display. Any hints?
Comment 23 R. J. 2007-10-01 10:49:15 UTC
honestly Fred, your wife wont like kmail.  Until the kmail team stop this anal attitude of putting out what is a dated e-mail client, Kmail will be the downfall of KDE.  Many people I know use gnome simply for evolution and wont touch KDE because of Kmail, and those that do use Kmail use evolution on it.  All you have to do is look at all the other email clients, Evolution, Apple Mail, Windows Live Mail, Firefox, they are all moving in a direction allowing users to get huge enjoyment out of their email, including, inserting photo's emails, etc.  Kmail, is still stuck in the early 90's wanting to be a boring old piece of crap.

Manfred, install Evolution, dpending on what distro you are on it isn't hard.
Comment 24 Mathieu Jobin 2007-10-02 04:00:53 UTC
kmail was my favorite mail client since KDE 1.0 and I've been swearing by it and only by it... until their unstable support for dIMAP killed many of my mails. that's without mentioning the numerous crashes.
Comment 25 Manfred Moser 2007-10-05 19:34:05 UTC
To clarify Johns instructions a bit and what I had to do to get the image there. Just create a new message. Add the signature you want. Attach the image you want at the bottom. Right click on the image and select properties. Click suggest automatic display. That seems to do the trick for me. I have a non html email (beautiful) and I still adhere to the corporate overlords requiring the signature image (with address and stuff not readable... dumb but true).
Comment 26 Manfred Moser 2007-10-05 19:37:11 UTC
Oh and a note to alienwithin@gmail.com: I tried Evolution. It just reminded me too much of Outlook to be painless to use. Anyway .. I used to use Thunderbird under Windows and that was fine too. But now that I work under Linux/KDE all day Kontact is it for me... 

Comment 27 jerald jackson 2007-11-06 19:18:18 UTC
Well, this is my answer.  The other comments are right on, this is 2007 and any email client needs to support html signatures.  They are required by many employers and the continued lack of support after this bug was opened in May of 2004 shows me that kmail is not being developed as a serious email client.

For the record, I was a Unix admin for 12 years and prefer text based email over anything else.  However, we all have to grow up someday.

I suggest to everyone else that you cease using kmail if you want HTML signature support and look to other clients.  This lack of support is more than a little juvenile.
Comment 28 Michael 2007-11-26 17:13:24 UTC
wow, what a hidden gem it is! you can do inline images with kmail if you get to right click and then check some "advanced" option. Is so hard to leave there also CID field? Or is it so hard to guess it automatically from the filename?
 cDisp += "\nContent-ID: <" + encName.replace( '\\', "\\\\" ).replace( '"', "\\\"" ) + ">";
 One should realize how easier it could make the things.
Don't get me wrong, I am KDE and KMail fan since some 2.x KDE version. Evolution is worse than Outlook, Thunderbird is worse than Outlook Express even. The only option I find usable is KMail.
But there are things that are just unacceptable. "Patch to enable HTMl signatures"? Does it worth anything without images? Don't you realize that must people just want a table with company logo in the left td and info in the right one?
I do understand that a good support for inline images would require reworking of the current message editor, so just make a workaround, do some shortcuts...

>Use the template every time you need a new email
Oh... how nice... what about reply and forward? is there an option like "reply using template from templates folder"?

with all the respect this issue falls directly into "power of ignorance".
sorry for being so aggressive.
Comment 29 Thomas McGuire 2007-11-26 17:39:57 UTC
> with all the respect this issue falls directly into "power of ignorance".
> sorry for being so aggressive.

No, it does not fall into "power of ignorance". It rather falls into "lack of 
time" and "shortage of developers".
Comment 30 Peter Tselios 2007-11-26 21:09:28 UTC
Dear all,
   I use KMail from day 1, but, the arrogance of the kdepim regarding HTML support is something that kills me. You cannot fight Spam by not permitting HTML emails. Besides, Linux is about choice. Give users both options and leave it to us to decide if we want HTML or not.
Of course, if any option is hidden somewhere, is useless. 
Comment 31 Thomas McGuire 2007-11-26 21:19:51 UTC
> I use KMail from day 1, but, the arrogance of the kdepim regarding HTML support is something that kills me.
Huh? I just said in the previous comment that this has nothing to do with unwillingness or even arrogance, but rather the lack of time by the developers and the actual lack of developers.
Patches for the trunk (KDE4) versions are always welcome. The 3.5 branch is in a feature freeze however.
Comment 32 Fred van Zwieten 2007-11-26 22:50:33 UTC
Gentlemen, gentlemen...calm...down!

The right way of getting this done is one of three things:
1. If you're a developer, start developing
2. If you're not a developer, vote this thing up. Find other users to vote for this. Make it THE most popular request for the pim package.
3. Keep bugging the developers on the dev-list (although they might not like this option)
Comment 33 Michael 2007-11-27 15:59:23 UTC
>Additional Comment #29 From Thomas McGuire 2007-11-26 17:39
Thomas, it is not the matter of "lack of time". If one does not have time to finish something then just don't start! That is the problem! I was soooo happy when I've seen "Patch to enable HTMl signatures", but can you compare what I have expected with what I've got? Obviously it is less related to kdepim and more to the way things work in community driven projects.

Sorry for my previous post, it was certainly overreacted. Again, I thought my favorite software just got better and instead I was disappointed enough to try the Evolution-Thunderbird-GMail cycle again for a day.
Comment 34 Michael 2007-11-27 16:04:18 UTC
> Additional Comment #32 From Fred van Zwieten 2007-11-26 22:50
I am not a developer, especially when it comes to C++, neither I can start learning KDE code internal logics. I've tried for an hour to find in the code the reason why "Content-ID" gets stripped with "new from template" approach, or where I can add "Content-ID: <filename>" again... no luck. All I've found was to add it through attachment properties dialog as I've posted above. If someone would be so kind to point me into where it is I'd be very grateful.
Comment 35 Jason Keirstead 2007-11-27 16:13:01 UTC
>Additional Comment #33 From Michael 2007-11-27 15:59

Michael you have to understand that 99% people who work on KDE do it for fun in their spare time. If no one finds development on KMail fun anymore they will work on something else, which is what has happened. Until either a company steps up to fund a complete re-write of the KMail composer subsystem (which is what is actually needed to fix all of its problems if you look at the crazy code), it is not going to get done. People have moved onto other things in KDE. You being frustrated and yelling at people won't motivate anyone.

I do agree with you that it is somewhat sad and frustrating that such an important piece of the desktop is so badly neglected. If I had the spare time I would step up and fix it myself. Using KMail is like going back to the dark ages of email - I can't put up with it anymore, I use Thunderbird always now.
Comment 36 Bart Verwilst 2007-11-27 16:41:42 UTC
Maybe you have better luck with asking the Mailody developer, which seems to be less abandoned than kmail.. 
http://www.mailody.net/
Comment 37 Michael 2007-11-27 18:14:32 UTC
>Additional Comment #35 From Jason Keirstead 2007-11-27 16:13
Jason, I do understand perfectly that most of the contributions done to kde are "free time". I have GNU/Linux only computers since I've seen windows XP for the first and for the last time on a new notebook, so I have some experince.
And I know what it is to "have fun" when doing something, I know it very well, I have some "free time" projects too (not to mention projects I do for money, which are even more boring).

And I am not yelling, ok maybe I do ;)

the thing is that nobody can fix kmail without rewriting most of it, so just give up with that, don't say you support anything until you DO support it. Otherwise it seems like a toy and this way nobody will grow up. not kde. not linux.
Thunderbird is terrible in all the rest of functionality. Only composer works good.
Comment 38 Michael 2007-11-27 18:16:36 UTC
>Additional Comment #36 From Bart Verwilst  2007-11-27 16:41
tried the latest today, will better wait until it gets qt4 ported. looks promising but not really working ;)
Comment 39 Peter Tselios 2007-11-28 09:49:04 UTC
>Patches for the trunk (KDE4) versions are always welcome. The 3.5 branch is in a feature freeze however. 

Well, in case not enough developers create code for KMail, then, why is it a part of KDE? I mean, there are alternatives! Of course that's not an option. What IS an option, is to ask large companies for support!
Comment 40 Michael 2007-12-02 17:32:04 UTC
http://kde-apps.org/content/show.php?content=29552
constructive?
Comment 41 Mathieu Jobin 2007-12-03 16:02:12 UTC
I dont see how is this related...

Comment 42 Edwin Schepers 2008-01-23 20:54:26 UTC
Created attachment 23227 [details]
HTML signature

Hi,
This (and the next) is a patch against trunk that enables HTML signatures.
Can I commit?
It still needs some finetuning (like naming), but the functionality is
basically there.

Regards,
Edwin
Comment 43 Edwin Schepers 2008-01-23 20:56:24 UTC
Created attachment 23228 [details]
HTML signature (kdepimlibs)

This is a kdepimlibs patch against trunk that enables HTML signatures together
with the previous patch.
Comment 44 Allen Winter 2008-01-23 21:46:24 UTC
You have my blessing to please commit the patch for kdepimlibs.

Thomas has promised to look at the patch for the KMail part soon.
Comment 45 Thomas McGuire 2008-01-26 22:35:48 UTC
Thanks for the patch.
I tested it, but it seems that it doesn't work. When I enable HTML signatures, KMail adds the signature as HTML code instead of actually formatting it as HTML.
It seems that this is because of KMeditor::insertSignature(), which always calls insertPlainText(). You probably need to change that so it calls insertHtml() instead, but only if the signature is a HTML signature.


>+    QString _InlinedHtml = config.readEntry( sigTypeInlinedHtmlKey );
>+    if ( _InlinedHtml == "true")
>+      mInlinedHtml = true;
No need to take the detour to read a QString and changing it to a bool then, readEntry supports reading bools directly. Change that to 
>mInlinedHtml = config.readEntry( sigTypeInlinedHtmlKey, false );
Otherwise, mInlinedHtml is even undefined if _InlinedHtml is something else than "true", which leads to the signature being always HTML, regardless of the config value.

A couple of minor nitpicks follow now:

>+      /** @return true if the inlined signature is html formatted */
>+      bool SignatureIsInlinedHtml() const;
You need to add "@since 4.1" into the comment to make clear that this method does not exist with the kdepimlibs from 4.0
Additionally, method names should always start with a lowercase letter, so change it to signatureIsInlinedHtml.

>+      void setInlinedHtml( bool isHtml );
>+      bool isInlinedHtml() const;
add "@since 4.1", and comments for @return and @param isHtml. Generally, new methods for libraries should be well documented.


>+    mHtmlCheck = new QCheckBox( i18n("&use HTML"), page );
Should be "&Use HTML"

>+    void setBtnState(ViewMode state);
Change this to the following, as per the KMail code style:
>+    void setBtnState( ViewMode state );

Same with:
>+      setBtnState(ShowHtml);
>+      setBtnState(ShowCode);
>+  void SignatureConfigurator::setBtnState(ViewMode state) {
and maybe others

>+  }
>+  void SignatureConfigurator::setBtnState(ViewMode state) {
Add a newline between the two lines

>+    kDebug(5006) << "SignatureConfigurator::slotSetHtml";
Unnecessary, change it to
>kDebug(5006);



Comment 46 Thomas McGuire 2008-01-26 22:45:16 UTC
Oh, and another thing: The HTML produced by QTextEdit is crap, it has lots of unneccesary tags. For "Hello World" I get:
><html><head><meta name="qrichtext" content="1" /><style type="text/css"> p, li 
> { white-space: pre-wrap; }
> </style></head><body style=" font-family:'Monospace'; font-size:10pt;
> font-weight:400; font-style:normal;">
> <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; 
> margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" 
> font-weight:600;">Hello World</span></p></body></html>

But that is a Qt bug. However, it makes manually adding some tags to the signature a pain.
Maybe most of the above standard tags can be removed when switching from plaintext to HTML?
Comment 47 Thomas McGuire 2008-01-26 22:53:02 UTC
Oh, another thing that needs to be fixed is that changing the identity in the composer does not change the signature.
Comment 48 Tom Albers 2008-01-27 12:29:46 UTC
(as maintainer of that part of kdepimlibs)
After you fix the issues outlined by tmg, you can commit the kdepimlibs part.
Comment 49 Edwin Schepers 2008-01-30 23:22:54 UTC
SVN commit 768920 by eschepers:

FEATURE: HTML signatures
BUG: 81989

TODO : - correct handling when changing identity
       - inserting images
       - some kind of button/toolbar to create html signature in wysiwyg mode?


 M  +7 -1      kmcomposewin.cpp  
 M  +99 -4     signatureconfigurator.cpp  
 M  +16 -0     signatureconfigurator.h  


WebSVN link: http://websvn.kde.org/?view=rev&revision=768920
Comment 50 Pino Toscano 2008-02-19 01:51:48 UTC
*** Bug 158028 has been marked as a duplicate of this bug. ***