TemplateParser::TemplateParserJob

TemplateParser::TemplateParserJob Class Reference

#include <templateparserjob.h>

Inheritance diagram for TemplateParser::TemplateParserJob:

Public Types

enum  AllowSelection { SelectionAllowed, NoSelectionAllowed }
 
enum  Mode { NewMessage, Reply, ReplyAll, Forward }
 
enum  Quotes { ReplyAsOriginalMessage, ReplyAsPlain, ReplyAsHtml }
 

Signals

void parsingDone (bool cursorPositionWasSet)
 
void parsingFailed ()
 

Public Member Functions

 TemplateParserJob (const KMime::Message::Ptr &amsg, const Mode amode, QObject *parent=nullptr)
 
void process (const KMime::Message::Ptr &aorig_msg, qint64 afolder=-1)
 
void process (const QString &tmplName, const KMime::Message::Ptr &aorig_msg, qint64 afolder=-1)
 
void processWithIdentity (uint uoid, const KMime::Message::Ptr &aorig_msg, qint64 afolder=-1)
 
void processWithTemplate (const QString &tmpl)
 
void setAllowDecryption (const bool allowDecryption)
 
void setCharsets (const QStringList &charsets)
 
void setIdentityManager (KIdentityManagement::IdentityManager *ident)
 
void setReplyAsHtml (bool replyAsHtml)
 
void setSelection (const QString &selection)
 
void setWordWrap (bool wrap, int wrapColWidth=80)
 
- Public Member Functions inherited from QObject
 QObject (QObject *parent)
 
bool blockSignals (bool block)
 
const QObjectListchildren () const const
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const const
 
void deleteLater ()
 
void destroyed (QObject *obj)
 
bool disconnect (const char *signal, const QObject *receiver, const char *method) const const
 
bool disconnect (const QObject *receiver, const char *method) const const
 
void dumpObjectInfo ()
 
void dumpObjectInfo () const const
 
void dumpObjectTree ()
 
void dumpObjectTree () const const
 
QList< QByteArraydynamicPropertyNames () const const
 
virtual bool event (QEvent *e)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
findChild (const QString &name, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QString &name, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QRegExp &regExp, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QRegularExpression &re, Qt::FindChildOptions options) const const
 
bool inherits (const char *className) const const
 
void installEventFilter (QObject *filterObj)
 
bool isWidgetType () const const
 
bool isWindowType () const const
 
void killTimer (int id)
 
virtual const QMetaObjectmetaObject () const const
 
void moveToThread (QThread *targetThread)
 
QString objectName () const const
 
void objectNameChanged (const QString &objectName)
 
QObjectparent () const const
 
QVariant property (const char *name) const const
 
 Q_CLASSINFO (Name, Value)
 
 Q_DISABLE_COPY (Class)
 
 Q_DISABLE_COPY_MOVE (Class)
 
 Q_DISABLE_MOVE (Class)
 
 Q_EMIT Q_EMIT
 
 Q_ENUM (...)
 
 Q_ENUM_NS (...)
 
 Q_ENUMS (...)
 
 Q_FLAG (...)
 
 Q_FLAG_NS (...)
 
 Q_FLAGS (...)
 
 Q_GADGET Q_GADGET
 
 Q_INTERFACES (...)
 
 Q_INVOKABLE Q_INVOKABLE
 
 Q_NAMESPACE Q_NAMESPACE
 
 Q_NAMESPACE_EXPORT (EXPORT_MACRO)
 
 Q_OBJECT Q_OBJECT
 
 Q_PROPERTY (...)
 
 Q_REVISION Q_REVISION
 
 Q_SET_OBJECT_NAME (Object)
 
 Q_SIGNAL Q_SIGNAL
 
 Q_SIGNALS Q_SIGNALS
 
 Q_SLOT Q_SLOT
 
 Q_SLOTS Q_SLOTS
 
qFindChild (const QObject *obj, const QString &name)
 
QList< T > qFindChildren (const QObject *obj, const QRegExp &regExp)
 
QList< T > qFindChildren (const QObject *obj, const QString &name)
 
qobject_cast (QObject *object)
 
qobject_cast (const QObject *object)
 
 QT_NO_NARROWING_CONVERSIONS_IN_CONNECT QT_NO_NARROWING_CONVERSIONS_IN_CONNECT
 
void removeEventFilter (QObject *obj)
 
void setObjectName (const QString &name)
 
void setParent (QObject *parent)
 
bool setProperty (const char *name, const QVariant &value)
 
bool signalsBlocked () const const
 
int startTimer (int interval, Qt::TimerType timerType)
 
int startTimer (std::chrono::milliseconds time, Qt::TimerType timerType)
 
QThreadthread () const const
 

Additional Inherited Members

- Properties inherited from QObject
 objectName
 
- Static Public Member Functions inherited from QObject
QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, Functor functor)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type)
 
bool disconnect (const QMetaObject::Connection &connection)
 
bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method)
 
bool disconnect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method)
 
bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method)
 
QString tr (const char *sourceText, const char *disambiguation, int n)
 
QString trUtf8 (const char *sourceText, const char *disambiguation, int n)
 
- Public Attributes inherited from QObject
typedef QObjectList
 
- Protected Member Functions inherited from QObject
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const QMetaMethod &signal)
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const QMetaMethod &signal)
 
bool isSignalConnected (const QMetaMethod &signal) const const
 
int receivers (const char *signal) const const
 
QObjectsender () const const
 
int senderSignalIndex () const const
 
virtual void timerEvent (QTimerEvent *event)
 

Detailed Description

The TemplateParser transforms a message with a given template.

Introduction
The TemplateParser transforms a message with a given template. A template contains text and commands, such as QUOTE or ODATE, which will be replaced with the real values in process().
Basics
The message given in the templateparser constructor amsg, is the message that is being transformed. aorig_msg is the original message to which actions are performed. The message text in amsg will be replaced by the processed text of the template, but other properties, such as the attachments or the subject, are preserved.

There are two different kind of commands: Those that work on the message that is to be transformed and those that work on an 'original message'. Those that work on the message that is to be transformed have no special prefix, e.g. 'DATE'. Those that work on the original message have an 'O' prefix, for example 'ODATE'. This means that the DATE command will take the date of the message passed in the constructor, the message which is to be transformed, whereas the ODATE command will take the date of the message that is being passed in process(), the original message.

The process()
The process() function takes aorig_msg as parameter. This aorig_msg is the original message from which various commands in templates with prefix 'O' extract the data and adds to the processed message. This function finds the template and passes them to processWithTemplate(), where templates are processed and its value is added to the processed message.
Reply To/Forward Plain Text Mails
Plain Text mails are the mails with only text part and no html part. While creating reply/forward to mails, processWithTemplate() processes all the commands and then appends its values to plainBody and htmlBody. This function then on the basis of whether the user wants to use plain mails or HTML mails, clears the htmlBody, or just passes both the plainBody and htmlBody unaltered.
Reply To/Forward HTML Mails
By HTML mails here, we mean multipart/alternative mails. As mentioned above, all commands in the TemplateParser appends text, i.e. plain text to plainBody and html text to htmlBody in the function processWithTemplate(). This function also takes a decision of clearing the htmlBody on the basis of fact whether the user wants to reply/forward using plain mails or multipart/alternative mails.
When "TO" and when "NOT TO" make multipart/alternative Mails
User is the master to decide when to and when not to make multipart/alternative mails. For user who <u>don't prefer</u> using HTML mails There is a TemplateParserSettings::self()->replyUsingHtml() (in GUI as Settings->Configure KMail-> Composer->General->"Reply using HTML if present"), which when not true (checkbox disabled in UI), will clear the htmlBody. An another option within the standard templates, FORCEDPLAIN command raises the flag, ReplyAsPlain. This flag when raised in processWithTemplate() takes care that the processed message will contain text/plain part by clearing the htmlBody.

Once the htmlBody is cleared, plainBody and an empty htmlBody is passed to addProcessedBodyToMessage(). Here since the htmlBody is empty, text/plain messages are assembled and thus user is not dealing with any kind of HTML part.

For user who <u>do prefer</u> using HTML mails The setting discussed above as "Reply using HTML if present" (when checked to true), passes the htmlBody to addProcessedBodyToMessage() without doing any changes. An another option FORCEDHTML within standard templates command raises the flag ReplyAsHtml. This flag when raised in processWithTemplate() takes care that the htmlBody is passed to addProcessedBodyToMessage() unaltered.

Since htmlBody received by addProcessedBodyToMessage() is not empty, multipart/alternative messages are assembled.

Resolving conflict between TemplateParserSettings "replyUsingHtml" and FORCEDXXXX command. The conflict is resolved by simply giving preference to the commands over TemplateParserSettings.

Make plain part
mMsg is the reply message in which the message text will be replaced by the processed value from templates.

In case of no attachments, the message will be a single-part message. A KMime::Content containing the plainBody from processWithTemplate() is created. Then the encodedBody(), contentType (text/plain) of this KMime::Content is set in the body and the header of mMsg. The addContent() method can be used for adding sub-content to content object in case of attachments. The addContent() method is not used for adding content of the above mentioned single-part, as addContent() will convert single-part to multipart-mixed before adding it to mMsg.

Make multipart/alternative mails
First of all a KMime::Content (content) is created with a content-type of multipart/alternative. Then in the same way as plain-part is created in above paragraph, a KMime::Content (sub-content) containing the plainBody is created and added as child to the content. Then a new KMime::Content (sub-content) with htmlBody as the body is created. The content-type is set as text/html. This new sub-content is then added to the parent content. Now, since the parent content (multipart/alternative) has two sub-content (text/plain and text/html) to it, it is added to the reply message (mMsg).

TODO: What is the usecase of the commands that work on the message to be transformed? In general you only use the commands that work on the original message...

Definition at line 129 of file templateparserjob.h.

Member Function Documentation

void TemplateParserJob::setAllowDecryption ( const bool  allowDecryption)

Sets whether the template parser is allowed to decrypt the original message when needing its message text, for example for the QUOTE command.

If true, it will tell the ObjectTreeParser it uses internally to decrypt the message, and that will possibly show a password request dialog to the user.

The default is false.

Definition at line 115 of file templateparserjob.cpp.

void TemplateParserJob::setCharsets ( const QStringList charsets)

Sets the list of charsets to try to use to encode the resulting text.

They are tried in order until one matches, or utf-8 as a fallback.

Definition at line 131 of file templateparserjob.cpp.

void TemplateParserJob::setIdentityManager ( KIdentityManagement::IdentityManager ident)

Set the identity manager to be used when creating the template.

Definition at line 126 of file templateparserjob.cpp.

void TemplateParserJob::setSelection ( const QString selection)

Sets the selection.

If this is set, only the selection will be added to commands such as QUOTE. Otherwise, the whole message is quoted. If this is not called at all, the whole message is quoted as well. Call this before calling process().

Definition at line 110 of file templateparserjob.cpp.

void TemplateParserJob::setWordWrap ( bool  wrap,
int  wrapColWidth = 80 
)

Tell template parser whether or not to wrap words, and at what column to wrap at.

Default is true, wrapping at 80chars.

Definition at line 1426 of file templateparserjob.cpp.


The documentation for this class was generated from the following files:
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat Aug 8 2020 23:11:31 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.