Bug 1015

Summary: kmail should have templates
Product: [Applications] kmail Reporter: Unknown <null>
Component: composerAssignee: kdepim bugs <kdepim-bugs>
Status: RESOLVED FIXED    
Severity: wishlist CC: arutha, berkessels, bigbug21-bugtrack, davidpjames, gerard.seibert, j.fuerst, jg, jjm, j_albers, kde-bugzilla, lefty, m.wege, martin.hohenberg, msantos, shelton, skipper
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: unspecified   
OS: Other   
Latest Commit: Version Fixed In:
Attachments: Template patch for KDE 3.4.2
Updated patch for KDE 3.5.3, part 1
Updated patch for KDE 3.5.3, part 2
Thebat-like template engine for kmail
Thebat-like template engine for kmail
Thebat-like template engine for kmail
Thebat-like template engine for kmail
templates for kmail -- patch for KDE4 trunk

Description trebor 1999-03-20 02:23:01 UTC
Package: kmail
Version: 1.1-2rh5x
Severity: wishlist

It would be nice if kmail had the abilty to create mail templates for
example for submitting KDE bug reports.  That way we wouldn't have to
keep re-typing the Package: and Version: lines.  Granted the "Insert
File" function gives you the same functionality but I'm lazy and don't
want to push all those buttons.

Basically what I'd like to see is a special folder called "Templates"
that allows you to save partially-created mail messages in it.  Then when
you double click (or something) the message the mail composer pops up
with a copy of the template in it so you can finish filling it out.

--
Trebor A. Rude
trebor@bwn.net
Registered Linux User #89308
http://counter.li.org/
Comment 1 trebor 1999-03-20 02:23:01 UTC
(*** This bug was imported into bugs.kde.org ***)

Package: kmail
Version: 1.1-2rh5x
Severity: wishlist

It would be nice if kmail had the abilty to create mail templates for
example for submitting KDE bug reports.  That way we wouldn't have to
keep re-typing the Package: and Version: lines.  Granted the "Insert
File" function gives you the same functionality but I'm lazy and don't
want to push all those buttons.

Basically what I'd like to see is a special folder called "Templates"
that allows you to save partially-created mail messages in it.  Then when
you double click (or something) the message the mail composer pops up
with a copy of the template in it so you can finish filling it out.

--
Trebor A. Rude
trebor@bwn.net
Registered Linux User #89308
http://counter.li.org/
Comment 2 Rob Kaper 2001-08-09 19:14:32 UTC
KMail has a Drafts folder for this purpose.

Regards

Rob <kaper@kde.org>
Comment 3 Ingo Kl 2001-08-09 20:23:46 UTC
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Thursday 9. August 2001 21:18 Stephan Kulow wrote:
> Your message with subj: Drafts folder
>
> KMail has a Drafts folder for this purpose.

The Drafts folder isn't very usable for this because edited messages 
disappear from the drafts folder after you send them.

We should add a separate Templates folder from which messages which you 
edit aren't removed after sending them so that you can use those 
templates more than one time.

Therefore I reopen this wish.

As a workaround one can of course create a folder Templates to store 
the templates. And then each time one want's to use such a template 
one could simply copy the template to the Drafts folder edit it and 
send it away.
But a separate Templates folder would still be nice. And it shouldn't 
be really hard to implement. We would simply have to copy the Drafts 
folder related stuff and make the Templates folder not remove messages 
which are edited. Maybe Florian (Hi Florian!) wants to do it as I'm 
currently busy with the PGP/GnuPG stuff.

Regards
Ingo
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE7cvFSGnR+RTDgudgRAt7FAJ93GnPwJA8w7bLe0HI1l3UrsiwwMACfUB37
WXJAX0svmG10SBnkDfrr2bc=
=dsN0
-----END PGP SIGNATURE-----
Comment 4 OlliK 2003-04-03 17:31:52 UTC
Hi there! 
 
I also just wanted to put a similar wish to the wishlist. Such a feature is included in an 
eMail-Client called "The Bat!". If you press on the "new message"-button, your new eMail 
allready contains: 
Dear Mr.  (or Hello, or ... what erver you want) 
... 
and  just before the signature: 
Best regards, 
 
Name 
 
It is a very good feature and I'd like to see it in my prefered Client kmail aswell. 
 
Happy developing and hava a nice day! 
Oliver Kasch 
 
Comment 5 Tom Emerson 2003-04-03 18:53:19 UTC
Oliver: if all you want is a prefix at the start and a prettier signature, Kmail does this already 
 
  1) select settings/configure kmail/composer/phrases -- there you can specify the initial text  
      (of course, kmail can't read your mind on a NEW message...) 
 
   2) for signatures, you specify "per identity" what signature should be created, which can 
       include specific text (the "sincerely,..." line would go AFTER the "-- " indicator) 
Comment 6 Ingo Klöcker 2003-04-04 23:25:47 UTC
Subject: Re:  kmail should have templates

What Oliver wants is already possible. Simply enter the following in the 
signature input field:
=====
Dear Mr.

blabla

Best regards,

Name

Comment 7 Chs 2003-05-03 18:44:33 UTC
I wish "The Bat!" templates in KMail too.


"The Bat!" have templates for "new", "forward", "reply" messages.


I need a specific thing for example: hiding e-mail address in forwarded message 
(now I do it manually).


"The Bat!" have a rich templates engine and if simular template engine will be 
in KMail it will be very nice.




(To previous comment's author):


"The Bat!" allow to insert in temlapes sender name, address and so on, not 
simple inserting "Dear Mr.". Message text, various sender and recipient 
information allowed - that may be important to somebody.


Comment 8 Dmitry Golubev 2003-08-18 22:11:58 UTC
I have been using FoxMail before switched to Linux. Foxmail also have powerful 
template engine to create new messages, replies and forwards, specifying the 
particular place to place all needed information (called macros there: 
subject, data, time, sender, recepient, etc.) and even where the cursor should 
be. 
 
Now I have to use Phrases, but they can be used only for replies (yes, by the 
way, could you allow to customize Forwarding phrase somehow in order to allow 
to get rid of these minuses!), and do not provide many things I want 
 
Thanks for the great product, 
Dmitry Golubev 
Comment 9 Ulrich Moser 2003-10-01 07:49:50 UTC
I just wanted to add the same wish. As far as I understand the previous 
comments there are two things that people want from KMail. First thing is a 
simple template function that allows to send prepared messages and just add 
some individual details. In some MUAs this is called create message from 
stationery. You could for instance prepare a message that you want to send to 
all your contacts you had on a fair. 
 
The other thing is more elaborated and allows insertion of text elements into 
the message like with bulk mail you generate in a text processor. This 
includes that you are able to a list of input data to the message and maybe 
also other text elements. But to be honest this can be reduced to the 
insertion of the salutation and the name from KAddressbook. Enabling KMail for 
bulk mail IMHO an overkill. First of all there are enough bulk mailers around 
and second before sending bulk mail people should sit back for a minute and 
remember what they do about bulk mail, they delete it.  
 
The conclusion is that a templates folder with the stationery function is very 
helpful. Insertion of addressbook fields would be a nice to have but leave the 
bulk mail functions to the bulk mailers. No one really wants bulk mail in his 
mailbox so why should you support others to send such crap. 
Comment 10 David P James 2004-01-19 21:58:11 UTC
I think this could be implemented without adding another default folder. In the Settings dialog, Composer pane there would be a tab for 'Templates'. The Templates themselves would be text files created by the user place anywhere the user pleases. The Templates tab would roughly resemble the Headers tab with a Name for each template and a second column specifying the file itself.

To create a message from a template would be fairly straightforward and would use the 'Insert file' code (at least I assume it would). The New Message button would have a dropdown with the list of templates. Alternatively, one could have a new button 'Create Message from Template' or something with the same thing, plus a menu item under Message of course.
Comment 11 Ismail Donmez 2004-07-20 21:02:08 UTC
*** Bug 82399 has been marked as a duplicate of this bug. ***
Comment 12 Juergen Gerner 2004-07-21 10:37:33 UTC
I'm not sure if the template system I described (Bug #82399) is the same as this thread means. My idea was a template mainly for companies' needs, with some extra features:
- Based on HTML to create a real design (with graphics/logo, like a stationary)
- Input widgets included (=LineEdits or TextEdits, but more like on a web form, not one big TextEdit)
- Pre-defined values (=ComboBoxes)
- Auto-filling values (e.g. for current date, no input widget)

I would prefer to set those templates in the normal config dialog, and select one in the composer window (like I can do with identities).
Comment 13 Jeroen Baten 2004-09-30 19:58:02 UTC
I think the following is in line and solves a lot of first wishes:
-kmail would support a templates dir with er templates
-a template is an xml file with things like:
<template>
  <name>
    <description>Omschrijving</description>
  </name>
  <header>
    Text to set at top of message
  </header>
  <selectionlist>
    <selection
      <description>Std reply to rtfm mail</description>
      <text>RTFM!</text>
    </selection>
    etcetera

  <paragraph>
    <text>
     Text in between results from selectionlists
    </text>
  </paragraph>
  <footer></footer>
</template>

-Upon clicking on the button 'template' a window pops up with the headers text, some selectionlist for prefap paragraphs and a footer.
-After selecting the right selectionlist items the user clicks on 'merge' or something
-Now he gets his usual builtin editor for the finishing touch.

hope this helps. Sorry I can't program this myself.
Comment 14 Sergey Y. Afonin 2004-10-01 17:41:23 UTC
I think, what two actions would can be added also: "Forward with template" and "Reply with temlate". Possible with templates list.
Comment 15 Dmitry Golubev 2004-10-01 19:05:30 UTC
See how (freeware) FoxMail (pages are in chinese, but there will be an "English" button) does this for a working example...
Comment 16 Till Adam 2004-10-23 10:36:46 UTC
*** Bug 91882 has been marked as a duplicate of this bug. ***
Comment 17 Don Sanders 2004-12-31 07:12:02 UTC
CVS commit by sanders: 

Add an Insert Recent File action to the composer Message menu, as discussed with Ingo.

This can act as a thrifty man's template system; put your often used phrases in descriptively named files and then quic
kly insert them again using the Insert Recent File popup menu.

Later on files with a specific suffix, say, .template could be passed for, say, '%' quoted commands like %DATE etc.

Hopefully the implementation is ok. There's a bit of code to make sure the encoding used when inserting a recent file i
s the same as when the file was inserted using the modified file dialog that includes an encoding combobox. Also some l
ogic is required to stop the config file from growing without bound.

CCMAIL:1015@bugs.kde.org


  M +2 -1      kmcomposerui.rc   1.37
  M +52 -2     kmcomposewin.cpp   1.901
  M +3 -0      kmcomposewin.h   1.268


--- kdepim/kmail/kmcomposerui.rc  #1.36:1.37
@@ -1,3 +1,3 @@
-<!DOCTYPE kpartgui ><kpartgui version="23" name="kmcomposer" >
+<!DOCTYPE kpartgui ><kpartgui version="24" name="kmcomposer" >
  <MenuBar>
   <Menu noMerge="1" name="file" >
@@ -11,4 +11,5 @@
    <Separator/>
    <Action name="insert_file" />
+   <Action name="insert_file_recent" />
    <Action name="file_print" />
    <Separator/>

--- kdepim/kmail/kmcomposewin.h  #1.267:1.268
@@ -65,4 +65,5 @@ class KToggleAction;
 class KSelectColorAction;
 class KURL;
+class KRecentFilesAction;
 class SpellingFilter;
 class MessageComposer;
@@ -406,4 +407,5 @@ public slots:
   void slotPrint();
   void slotAttachFile();
+  void slotInsertRecentFile(const KURL&);
   void slotSendNow();
   void slotSendLater();
@@ -824,4 +826,5 @@ protected:
   KAction *mAttachPK, *mAttachMPK,
           *mAttachRemoveAction, *mAttachSaveAction, *mAttachPropertiesAction;
+  KRecentFilesAction *mRecentAction;
 
   KToggleAction *mSignAction, *mEncryptAction, *mRequestMDNAction;

--- kdepim/kmail/kmcomposewin.cpp  #1.900:1.901
@@ -91,4 +91,5 @@ using KRecentAddress::RecentAddresses;
 #include <kstatusbar.h>
 #include <kaction.h>
+#include <kstdaction.h>
 #include <kdirwatch.h>
 #include <kstdguiitem.h>
@@ -934,4 +935,11 @@ void KMComposeWin::setupActions(void)
                       this,  SLOT(slotInsertFile()),
                       actionCollection(), "insert_file");
+  mRecentAction = new KRecentFilesAction (i18n("&Insert File Recent"),
+                      "fileopen", 0,
+                      this,  SLOT(slotInsertRecentFile(const KURL&)),
+                      actionCollection(), "insert_file_recent");
+                                        
+  mRecentAction->loadEntries( KMKernel::config() );
+
   (void) new KAction (i18n("&Address Book"), "contents",0,
                       this, SLOT(slotAddrBook()),
@@ -2366,5 +2374,37 @@ void KMComposeWin::slotInsertFile()
 
   KURL u = fdlg.selectedURL();
+  mRecentAction->addURL(u);
+  // Prevent race condition updating list when multiple composers are open
+  {
+    KConfig *config = KMKernel::config();
+    KConfigGroupSaver saver( config, "Composer" );
+    QString encoding = KGlobal::charsets()->encodingForName(combo->currentText()).latin1();
+    QStringList urls = config->readListEntry( "recent-urls" );
+    QStringList encodings = config->readListEntry( "recent-encodings" );
+    // Prevent config file from growing without bound
+    // Would be nicer to get this constant from KRecentFilesAction
+    uint mMaxRecentFiles = 30;
+    while (urls.count() > mMaxRecentFiles)
+      urls.erase( urls.fromLast() );
+    while (encodings.count() > mMaxRecentFiles)
+      urls.erase( encodings.fromLast() );
+    // sanity check
+    if (urls.count() != encodings.count()) {
+      urls.clear();
+      encodings.clear();
+    }
+    urls.prepend( u.prettyURL() );
+    encodings.prepend( encoding );
+    config->writeEntry( "recent-urls", urls );
+    config->writeEntry( "recent-encodings", encodings );
+    mRecentAction->saveEntries( config );
+  }
+  slotInsertRecentFile(u);
+}
 
+
+//-----------------------------------------------------------------------------
+void KMComposeWin::slotInsertRecentFile(const KURL& u)
+{
   if (u.fileName().isEmpty()) return;
 
@@ -2374,6 +2414,16 @@ void KMComposeWin::slotInsertFile()
   ld.data = QByteArray();
   ld.insert = true;
-  ld.encoding = KGlobal::charsets()->encodingForName(
-    combo->currentText()).latin1();
+  // Get the encoding previously used when inserting this file
+  {
+    KConfig *config = KMKernel::config();
+    KConfigGroupSaver saver( config, "Composer" );
+    QStringList urls = config->readListEntry( "recent-urls" );
+    QStringList encodings = config->readListEntry( "recent-encodings" );
+    int index = urls.findIndex( u.prettyURL() );
+    if (index != -1) {
+      QString encoding = encodings[ index ];
+      ld.encoding = encoding.latin1();
+    }
+  }
   mMapAtmLoadData.insert(job, ld);
   connect(job, SIGNAL(result(KIO::Job *)),


Comment 18 Stephan Binner 2005-02-19 19:51:18 UTC
*** Bug 99804 has been marked as a duplicate of this bug. ***
Comment 19 Sebastian Damm 2005-05-06 11:46:35 UTC
I'd like to see templates similar to "The Bat!" in KMail, too. You can set Preferences for every folder already, so if you could please add templates to it. The normal behavior for every folder should be to use the global templates for the account or identity. But you should be able to override these settings. 

Also templates on a per-user basis would be nice. Macros for filling in the texts would make sense in this context. So you could check a special field in the kaddressbook entry and dependent on what is in there you fill in the template. For example you can examine the nickname field of a contact, and if there is something filled in, then use it in the salutation, otherwise use the first name. Or you could have a special field where you place whether you name him by first name or by last name and check for this field, then create the greeting "Dear $firstname" oder "Dear Mr. $lastname" - of course you have to check for the gender, too.

There are many customizations, which can make using emails easier.
Comment 20 Carsten Burghardt 2005-05-15 12:24:33 UTC
*** Bug 104314 has been marked as a duplicate of this bug. ***
Comment 21 Carsten Burghardt 2005-05-15 12:25:13 UTC
*** Bug 105571 has been marked as a duplicate of this bug. ***
Comment 22 J. Albers 2005-06-29 09:49:31 UTC
Hi,

many people are waiting for this feature but it seems that the kmail developers don't like it. I'm using kmail in my daily work and I miss this feature very much. A simple (text) template file like the signature (Configuration->Identity-Signature / but above the "-- " line) would be nice! To write these things into the signature file isn't a good solution! 

TIA
 Jens
Comment 23 Carsten Burghardt 2005-06-29 10:26:21 UTC
> many people are waiting for this feature but it seems that the kmail
> developers don't like it. I'm using kmail in my daily work and I miss this
> feature very much.


Jens, kmail is opensource so feel free to implement this.
And it's simply not true that we "don't like this feature" but as our time
is limited each developer has to decide what has a higher priority.


Carsten
Comment 24 Tim 2005-07-06 10:11:17 UTC
Templates are really important in a business environment. This is because people are either lazy (me) or incompetent. 

Currently I have +100 Users all using kmail. Many requests can be answered with our templates, but we needed to invest hell of a lot time (month!) to teach them how to copy and paste. 

It would be great if we would have under "answer" a choose "choose template" field. 
The template should be placeable on the server. So we need configuration item for "group templates" and "privat templates" 

thanks for your ear
Comment 25 Don Sanders 2005-07-13 10:28:03 UTC
In KDE 3.4+ please consider using the Insert File and Insert File 
Recent menu items in the composer to insert template text from 
predefined files.
Comment 26 J. Albers 2005-07-13 11:18:48 UTC
Hi!

>In KDE 3.4+ please consider using the Insert File and Insert File 
>Recent menu items in the composer to insert template text from 
>predefined files.

That's ok if you write only one email a day, but I'm using kmail at work and I have to write more than a dozen emails a day. All email must have a special form because of legal causes. Templates are an enterprise feature and I think kmail want to be an enterprise email client. The solution is very easy to implement (I think): It's basically a copy of the signature tab/functionality.

TIA
 Jens
Comment 27 Don Sanders 2005-07-15 04:33:53 UTC
>The solution is very easy to implement (I think): It's
> basically a copy of the signature tab/functionality.


Ok, it would be great if you could send a patch then.
Comment 28 Jonathan Marten 2005-08-20 15:03:23 UTC
Patch posted to list
http://lists.kde.org/?l=kmail-devel&m=112454256600012&w=2
Comment 29 Jonathan Marten 2005-08-21 13:47:31 UTC
Created attachment 12299 [details]
Template patch for KDE 3.4.2

Attached here, as suggested by Ingo Klöcker
Comment 30 Martin Fabian Hohenberg 2005-09-19 16:21:01 UTC
Will this patch be included in KDE 3.5? Just curious and not really keen of ruining my package configuration.
Comment 31 Rashid N. Achilov 2005-10-27 07:33:35 UTC
This is a very userful wish! I'd like to create similar wish, but won't do it, but vote for this wish. 'Drafts' is not similar - after succesful mailing, letter will deleted, but in "Templates" letter keep. Netscape has similar folder ant is was very comfortable.
Comment 32 Martin Fabian Hohenberg 2005-10-28 20:15:23 UTC
How about going the money lane? I have just pledged 120 € for the working implementation of this stuff at http://kontact.org/shopping ... If this is important to you, I recommend you follow this path...

... No, I do not like this way, also. It feels somehow like some kind of "Nötigung" (don't know the correct english word for that, maybe "constraint"). I am willing to contribute (but can't do any C++ unfortunately), I am willing to spend for the E.V., but this good-faith should not be dependant on withholding cruicial functionality. 
Comment 33 Ashar Iqbal 2006-02-11 08:26:51 UTC
There are a few posts referring to The Bat. Just wanted to add some details to help in why this is so.

The Bat! has excellent template support. This is really useful where you need to send very similar replies to many emails - for example technical support, sales...
I get an enquiry that asks where to buy our product in a certain city. Using The Bat I can just press the REPLY button to generate the correct and full response.
This involves setting up a filter to move the email to a specific folder. The folder has an Identity and Reply template associated with it.
The reply I generate uses the these two properties to produce the resultant email. I just have to click on the Send button.

http://www.silverstones.com/thebat/templates.html  (this is also the page referred to by the Rit Labs documentation.)
http://www.pcwize.com/thebat/tbudp/tiki-index.php?page=Templates

The Bat! is produced by http://www.ritlabs.com

Comment 34 Bartosz Malinowski 2006-06-16 19:29:18 UTC
Hello,

yes, I'd like Kmail to have this feature. Writting 10.000 times a day the horrible "Dear Sir,"   "Kind Regards, X.Y, Z Inc." formulas, whereas you have quite a lot of other things to do precludes me from ever thinking of using Kmail in my company office. So I am forced to use Thunderbird, which is all too simplified in many respects. 

Standard signatures are only a partial solution, especially whereas my Kmail version (1.9.1) does not accept html signture files - plain text only!

I've seen a patch sent by Jonathan Marten on 2005-08-21 13:47. What's happening with it?

BTW, I strongly invite everybody to vote for this wishlist item:
Bug 128986: Can't Paste HTML-formatted text into Kmail mail editor window

Kind Regards,
Bartosz Malinowski
Comment 35 Jonathan Marten 2006-07-05 16:07:55 UTC
Created attachment 16894 [details]
Updated patch for KDE 3.5.3, part 1

Patch updated for current KDE, and incorporating review comments and
suggestions from Ingo Klöcker on kmail-devel mailing list.  This means that
the facility to insert template text into the composer is no longer present; 
I'm currently thinking about an alternative way of doing this.

It would be nice if this facility could be considered for inclusion in the next
release in the KDE 3.5.x series, if the release criteria allows it; this is a
major new functionality and ought to be user tested before KDE 4.

The next patch (update of kmail libraries for template support, some of which
is already present) is also required.
Comment 36 Jonathan Marten 2006-07-05 16:11:18 UTC
Created attachment 16895 [details]
Updated patch for KDE 3.5.3, part 2

This patch can be incorporated into the libraries before the corresponding
changes to the application; they are source compatible (but BIC).
Comment 37 Martin Fabian Hohenberg 2006-07-06 10:41:20 UTC
I don't get the "obsolete" stuff ... does this mean templates are really comming to town?

Can anyone give a newbie adwive how to apply patches?
Comment 38 Jan de Visser 2006-09-03 17:26:09 UTC
*** Bug 133508 has been marked as a duplicate of this bug. ***
Comment 39 BJ Blanchard 2006-09-05 18:13:20 UTC
Wouldn't the simplist solution for the whole template debate be to just modify the Draft send logic to not delete the message from the Drafts folder??

It then acts as a template folder.. simple.

You could create a config option "DeleteDraftonSend=false" so that its configurable by user.

BJ.
Comment 40 Dmitry Golubev 2006-09-05 18:27:22 UTC
heh, well, drafts do NOT fill up some fields by themselves and neither they position a cursor where it is supposed to be. note that variables (aka macros) are the most important feature here... the ability to customize message fully, and to position the cursor...
Comment 41 Bernd Wurst 2006-09-05 20:58:48 UTC
The most simple but sufficient solution to this would be to implement a function that passes the *complete* message to an external program and gets a *complete* message back from the external app which gets loaded into the compose window.
So the user or administrator can freely decide what should happen. An external app would then be able to look at headers, subject an so on and could compose a custom reply message.

This would move the main work (message parsing, template management, ...) to the users, administrators or third party goodie-writers. The functionality could be extended later, but that would be the most important step.
Sylpheed-claws is a very good example for a mail app that can launch external shell-scripts or programs for lots of things. Fully customizable and fits all needs (though it's little more work for the end user).
Comment 42 Dmitry Morozhnikov 2006-10-16 11:26:39 UTC
Created attachment 18135 [details]
Thebat-like template engine for kmail

Thebat-like template engine for kmail. In sync with svn revision 595956 (kde3.5
branch). Replacement for 'Phrases' functionality.

Introduces separate configuration for new message/reply/reply all/forward
templates for each folder with simple macro language.
Comment 43 Dmitry Morozhnikov 2006-10-16 11:32:57 UTC
Glad to introduce one another patch to kmail which provide thebat-like template functionality :-)

No, it is not a complete thebat templates language emulation (yet), only a very small subset, but it can serve most of everyday needs, especially because of per-folder configuration. It intended to be current 'Phrases' configuration replacement. 

Motivation is simple. I`m also think what thebat have superior template language and kmail need to have something like this. Personally i`m just tired to type "Hello, <friend name>" ten times a day in the beginning of each message. At least, with this patch it is possible now avoid this with per-folder reply template.

Peoples used thebat will found what language is well known. I was tried to reproduce it as much as possible.

Also there is some additions to thebat template language related to external programs processing. Commands added:

%SYSTEM="<command>" -- insert result of external command
%QUOTEPIPE="<command>" -- insert original message body processed with external command and quoted
%TEXTPIPE="<command>" -- the same, but not quoted
%MSGPIPE="<command>" -- the same, but whole message, including headers processed
%BODYPIPE="<command>" -- current message body processed
%CLEARPIPE="<command>" -- the same, but replace whole body with result

Also new:

%DEBUG -- turn on debug on pipe commands
%DEBUGOFF -- turn it off
%NOP -- synonym for %BLANK

Supported thebat commands:

%-, %REM="<comment>", %INSERT="<file>", %QUOTE, %QHEADERS, %HEADERS,             %TEXT, %TOADDR, %TONAME, %FROMADDR, %FROMNAME, %FULLSUBJECT, %MSGID, %OHEADER="<header>", %HEADER="<header>", %OTOADDR, %OTONAME, %OFROMADDR, %OFROMNAME, %OFULLSUBJECT, %OMSGID, %DATEEN, %DATESHORT, %DATE, %DOW, %TIMELONGEN, %TIMELONG, %TIME,  %ODATEEN, %ODATESHORT, %ODATE, %ODOW, %OTIMELONGEN, %OTIMELONG, %OTIME, %BLANK, %CLEAR

Sorry, much appreciated %CURSOR command not supported yet :-(

This patch are in synk with today KDE3.5 branch: http://websvn.kde.org/branches/KDE/3.5/kdepim

And i have a little hope what it will be added to KDE 3.5.6 :-) Because KDE 4 seems to be too far away yet.. 
Comment 44 Dmitry Morozhnikov 2006-10-16 12:32:03 UTC
Created attachment 18137 [details]
Thebat-like template engine for kmail

oops fix..
Comment 45 Dmitry Morozhnikov 2006-10-18 09:07:31 UTC
Created attachment 18158 [details]
Thebat-like template engine for kmail

Sync with revision 596679.

Now with %CURSOR!

Also added: %TOFNAME, %TOLNAME, %FROMFNAME, %FROMLNAME, %OTOFNAME, %OTOLNAME,
%OFROMFNAME, %OFROMLNAME -- because it is difficult to live without them.
Comment 46 Dmitry Morozhnikov 2006-10-18 10:12:02 UTC
Created attachment 18160 [details]
Thebat-like template engine for kmail

Oops.. Yesterday changes to kmail/kmcomposewin.cpp was reverted back with
previous patch. This is a correct one. Sorry :-(
Comment 47 Dmitry Morozhnikov 2006-10-18 13:01:26 UTC
Created attachment 18171 [details]
templates for kmail -- patch for KDE4 trunk

Synk with revision 596725.
Comment 48 BJ Blanchard 2006-10-18 22:20:11 UTC
Thanks dmiceman - excellent patch.. works against 3.5.5.

Unfortunately the "template folder" patch by Jonathan Marten causes Compose window to crash everytime when applied against 3.5.5.  (with or without dmiceman's patch applied)

NOTE: There was small change to patch of kmmainwin.rc (version mismatch) required for patch to apply successfully against 3.5.5.

-<kpartgui version="89" name="kmmainwin" >
+<kpartgui version="90" name="kmmainwin" >

instead of 

-<kpartgui version="88" name="kmmainwin" >
+<kpartgui version="89" name="kmmainwin" >

I was unable to determine what changes are required to bring this patch under 3.5.5 successfully.

Below is my backtrace.

BJ.

Program terminated with signal 11, Segmentation fault.
#0  0x4a7797b1 in QString::QString () from /usr/qt/3/lib/libqt-mt.so.3


Thread 1 (process 19947):
#0  0x4a7797b1 in QString::QString () from /usr/qt/3/lib/libqt-mt.so.3
No symbol table info available.
#1  0xb6481d46 in KMComposeWin::setMsg (this=0x86693e8, newMsg=0x868bc88,
    mayAutoSign=true, allowDecryption=false, isModified=false)
    at identity.h:282
        n = (partNode *) 0x8404c04
        root = (partNode *) 0x0
        otp = {_vptr.ObjectTreeParser = 0x8bc0cb0, mReader = 0xea60,
  mRawReplyString = <incomplete type>,
  mTextualContentCharset = <incomplete type>, mTextualContent = {
    static null = {
      static null = <same as static member of an already seen type>,
      d = 0x806d070, static shared_null = 0x806d070}, d = 0x834ace8,
    static shared_null = 0x806d070}, mCryptPlugWrapper = 0xb62e03a7,
  mShowOnlyOneMimePart = 176, mKeepEncryptions = 12, mIncludeSignatures = 188,
  mAttachmentStrategy = 0xea60, mHtmlWriter = 0x0, mCSSHelper = 0xb67147f7,
  mCollapseIcon = {static null = {
      static null = <same as static member of an already seen type>,
      d = 0x806d070, static shared_null = 0x806d070}, d = 0xb6293988,
    static shared_null = 0x806d070}, mExpandIcon = {static null = {
      static null = <same as static member of an already seen type>,
      d = 0x806d070, static shared_null = 0x806d070}, d = 0x834ace8,
    static shared_null = 0x806d070}}
        ac = {
  mAttachments = {<std::_Vector_base<partNode*,std::allocator<partNode*> >> = {
      _M_impl = {<std::allocator<partNode*>> = {<__gnu_cxx::new_allocator<partNode*>> = {<No data fields>}, <No data fields>}, _M_start = 0xbf998c80,
        _M_finish = 0x4a8ebe80, _M_end_of_storage = 0x0}}, <No data fields>},
  mDiveIntoEncryptions = false, mDiveIntoSignatures = false,
  mDiveIntoMessages = false}
#2  0xb6486301 in KMComposeWin (this=0x86693e8, aMsg=0x868bc88, id=0)
    at kmcomposewin.cpp:401
        tip = {static null = {
    static null = <same as static member of an already seen type>,
    d = 0x806d070, static shared_null = 0x806d070}, d = 0x8b4a278,
  static shared_null = 0x806d070}
        sticky = {static null = {
    static null = <same as static member of an already seen type>,
    d = 0x806d070, static shared_null = 0x806d070}, d = 0x8b4a278,
  static shared_null = 0x806d070}
        atmColType = -1234107154
#3  0xb64864e7 in KMComposeWin::create (msg=0x0, identitiy=0)
    at kmcomposewin.cpp:149
No locals.
#4  0xb6486518 in KMail::makeComposer (msg=0x0, identitiy=0)
    at kmcomposewin.cpp:145
No locals.
#5  0xb65f96b1 in KMMainWidget::slotCompose (this=0x846ad08)
    at kmmainwidget.cpp:891
        win = (class KMail::Composer *) 0xbf998cc0
#6  0xb660f27a in KMMainWidget::qt_invoke (this=0x846ad08, _id=80,
    _o=0xbf998ee0) at kmmainwidget.moc:516
No locals.
Comment 49 Jonathan Marten 2006-10-19 10:01:05 UTC
I'll investigate the crash (reported in comment #48).  At the moment I'm also updating my patch to apply against trunk (since it has to go there before being accepted for a 3.5.? release).

dmiceman, I assume that your "Thebat-like" templates with phrase insertion are completely separate to my template folder facility?  If not, then we will need to somehow combine our patches before commit...
Comment 50 Dmitry Morozhnikov 2006-10-19 15:56:00 UTC
Jonathan, yes, they are very different beasts :-) 
Comment 51 Jonathan Marten 2006-11-06 18:46:25 UTC
SVN commit 602738 by marten:

GUI for an identity-specific templates folder

CCBUG:1015
CCMAIL:kmail-devel@kde.org
GUI:


 M  +24 -2     branches/work/kdepim-3.5.5+/kmail/identitydialog.cpp  
 M  +1 -0      branches/work/kdepim-3.5.5+/kmail/identitydialog.h  


--- branches/work/kdepim-3.5.5+/kmail/identitydialog.cpp #602737:602738
@@ -288,9 +288,9 @@
     row = -1;
     tab = new QWidget( tabWidget );
     tabWidget->addTab( tab, i18n("&Advanced") );
-    glay = new QGridLayout( tab, 7, 2, marginHint(), spacingHint() );
+    glay = new QGridLayout( tab, 8, 2, marginHint(), spacingHint() );
     // the last (empty) row takes all the remaining space
-    glay->setRowStretch( 7-1, 1 );
+    glay->setRowStretch( 8-1, 1 );
     glay->setColStretch( 1, 1 );
 
     // "Reply-To Address" line edit and label:
@@ -355,6 +355,15 @@
     glay->addWidget( new QLabel( mDraftsCombo, i18n("&Drafts folder:"), tab ),
                      row, 0 );
 
+    // "Templates Folder" combo box and label:
+    ++row;
+    mTemplatesCombo = new FolderRequester( tab,
+        kmkernel->getKMMainWidget()->folderTree() );
+    mTemplatesCombo->setShowOutbox( false );
+    glay->addWidget( mTemplatesCombo, row, 1 );
+    glay->addWidget( new QLabel( mTemplatesCombo, i18n("&Templates folder:"), tab ),
+                     row, 0 );
+
     // "Special transport" combobox and label:
     ++row;
     mTransportCheck = new QCheckBox( i18n("Special &transport:"), tab );
@@ -614,6 +623,17 @@
     else
       mDraftsCombo->setFolder( ident.drafts() );
     
+    if ( ident.templates().isEmpty() ||
+         !checkFolderExists( ident.templates(),
+                             i18n("The custom templates folder for identity "
+                                  "\"%1\" does not exist (anymore); "
+                                  "therefore, the default templates folder "
+                                  "will be used.")
+                             .arg( ident.identityName() ) ) )
+      mTemplatesCombo->setFolder( kmkernel->templatesFolder() );
+    else
+      mTemplatesCombo->setFolder( ident.templates() );
+    
     // "Templates" tab:
     uint identity = ident.uoid();
 		QString iid = QString("IDENTITY_%1").arg( identity );
@@ -649,6 +669,8 @@
                   mFccCombo->folder()->idString() : QString::null );
     ident.setDrafts( mDraftsCombo->folder() ?
                      mDraftsCombo->folder()->idString() : QString::null );
+    ident.setTemplates( mTemplatesCombo->folder() ?
+                     mTemplatesCombo->folder()->idString() : QString::null );
     // "Templates" tab:
     uint identity = ident.uoid();
     QString iid = QString("IDENTITY_%1").arg( identity );
--- branches/work/kdepim-3.5.5+/kmail/identitydialog.h #602737:602738
@@ -100,6 +100,7 @@
     KMail::DictionaryComboBox    *mDictionaryCombo;
     FolderRequester              *mFccCombo;
     FolderRequester              *mDraftsCombo;
+    FolderRequester              *mTemplatesCombo;
     QCheckBox                    *mTransportCheck;
     QComboBox                    *mTransportCombo; // should be a KMTransportCombo...
     // "templates" tab:
Comment 52 Dmitry Morozhnikov 2006-11-07 02:34:09 UTC
SVN commit 602871 by dmiceman:

Keyboard shortcuts for custom templates with corresponding gui. 
Some refactoring of kmmailwidget related to custom templates handling 
(proper KAction`s).
Very little beautification of custom templates interface.

CCBUG:1015
GUI


 M  +140 -12   branches/work/kdepim-3.5.5+/kmail/customtemplates.cpp  
 M  +9 -1      branches/work/kdepim-3.5.5+/kmail/customtemplates.h  
 M  +32 -22    branches/work/kdepim-3.5.5+/kmail/customtemplates_base.ui  
 M  +5 -0      branches/work/kdepim-3.5.5+/kmail/customtemplates_kfg.kcfg  
 M  +157 -110  branches/work/kdepim-3.5.5+/kmail/kmmainwidget.cpp  
 M  +7 -4      branches/work/kdepim-3.5.5+/kmail/kmmainwidget.h  
Comment 53 Jonathan Marten 2006-11-23 21:56:21 UTC
*** Bug 137002 has been marked as a duplicate of this bug. ***
Comment 54 Allen Winter 2006-12-18 21:27:19 UTC
The KMail to be released as part of KDE 3.5.6 will have template capabilities.

You will be able to build templates for new messages, replies, or forwards. The templates can be universal or identity-specific or folder-specific. The template language is very customizable (similar to The Bat! mailer).

There will also be a templates folder from which you can store whatever emplates you like and new messages can be created from these.

So, we probably went overboard with the templates.  I'd like to thank Dmitry nd Jonathan for all their hard work doing the code to make this happen.
Future releases will fine-tune how templates work, but please open new bug reports for usability and other issues with templates.


Comment 55 Tristan Miller 2007-07-22 12:56:45 UTC
This feature has been implemented but the most intuitive way to access it (i.e., via the Message pull-down menu) is missing.  See Bug 148102.