TemplateParser::TemplateParserJob
#include <templateparserjob.h>
Public Types | |
enum | AllowSelection { SelectionAllowed , NoSelectionAllowed } |
enum | Mode { NewMessage , Reply , ReplyAll , Forward } |
enum | Quotes { ReplyAsOriginalMessage , ReplyAsPlain , ReplyAsHtml } |
Public Types inherited from QObject | |
typedef | QObjectList |
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 | setIdentityManager (KIdentityManagementCore::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) | |
QBindable< QString > | bindableObjectName () |
bool | blockSignals (bool block) |
const QObjectList & | children () 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 () const const |
void | dumpObjectTree () const const |
QList< QByteArray > | dynamicPropertyNames () const const |
virtual bool | event (QEvent *e) |
virtual bool | eventFilter (QObject *watched, QEvent *event) |
T | findChild (const QString &name, Qt::FindChildOptions options) const const |
QList< T > | findChildren (const QRegularExpression &re, Qt::FindChildOptions options) const const |
QList< T > | findChildren (const QString &name, Qt::FindChildOptions options) const const |
QList< T > | findChildren (Qt::FindChildOptions options) const const |
bool | inherits (const char *className) const const |
void | installEventFilter (QObject *filterObj) |
bool | isQuickItemType () const const |
bool | isWidgetType () const const |
bool | isWindowType () const const |
void | killTimer (int id) |
virtual const QMetaObject * | metaObject () const const |
void | moveToThread (QThread *targetThread) |
QString | objectName () const const |
void | objectNameChanged (const QString &objectName) |
QObject * | parent () const const |
QVariant | property (const char *name) const const |
Q_CLASSINFO (Name, Value) | |
Q_EMIT Q_EMIT | |
Q_ENUM (...) | |
Q_ENUM_NS (...) | |
Q_ENUMS (...) | |
Q_FLAG (...) | |
Q_FLAG_NS (...) | |
Q_FLAGS (...) | |
Q_GADGET Q_GADGET | |
Q_GADGET_EXPORT (EXPORT_MACRO) | |
Q_INTERFACES (...) | |
Q_INVOKABLE Q_INVOKABLE | |
Q_MOC_INCLUDE Q_MOC_INCLUDE | |
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 | |
T | qobject_cast (const QObject *object) |
T | qobject_cast (QObject *object) |
QT_NO_NARROWING_CONVERSIONS_IN_CONNECT QT_NO_NARROWING_CONVERSIONS_IN_CONNECT | |
void | removeEventFilter (QObject *obj) |
void | setObjectName (const QString &name) |
void | setObjectName (QAnyStringView name) |
void | setParent (QObject *parent) |
bool | setProperty (const char *name, const QVariant &value) |
bool | setProperty (const char *name, QVariant &&value) |
bool | signalsBlocked () const const |
int | startTimer (int interval, Qt::TimerType timerType) |
int | startTimer (std::chrono::milliseconds interval, Qt::TimerType timerType) |
QThread * | thread () 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 *context, Functor functor, 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) |
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, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method) |
bool | disconnect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method) |
QString | tr (const char *sourceText, const char *disambiguation, int n) |
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 |
QObject * | sender () 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 don't prefer 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 do prefer 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.
@NOTE 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.
- 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 128 of file templateparserjob.h.
Member Enumeration Documentation
◆ AllowSelection
enum TemplateParser::TemplateParserJob::AllowSelection |
Definition at line 141 of file templateparserjob.h.
◆ Mode
enum TemplateParser::TemplateParserJob::Mode |
Definition at line 134 of file templateparserjob.h.
◆ Quotes
enum TemplateParser::TemplateParserJob::Quotes |
Definition at line 146 of file templateparserjob.h.
Constructor & Destructor Documentation
◆ TemplateParserJob()
|
explicit |
Definition at line 73 of file templateparserjob.cpp.
Member Function Documentation
◆ process() [1/2]
void TemplateParserJob::process | ( | const KMime::Message::Ptr & | aorig_msg, |
qint64 | afolder = -1 ) |
Definition at line 140 of file templateparserjob.cpp.
◆ process() [2/2]
void TemplateParserJob::process | ( | const QString & | tmplName, |
const KMime::Message::Ptr & | aorig_msg, | ||
qint64 | afolder = -1 ) |
Definition at line 160 of file templateparserjob.cpp.
◆ processWithIdentity()
void TemplateParserJob::processWithIdentity | ( | uint | uoid, |
const KMime::Message::Ptr & | aorig_msg, | ||
qint64 | afolder = -1 ) |
Definition at line 169 of file templateparserjob.cpp.
◆ processWithTemplate()
void TemplateParserJob::processWithTemplate | ( | const QString & | tmpl | ) |
Definition at line 204 of file templateparserjob.cpp.
◆ setAllowDecryption()
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 86 of file templateparserjob.cpp.
◆ setIdentityManager()
void TemplateParserJob::setIdentityManager | ( | KIdentityManagementCore::IdentityManager * | ident | ) |
Set the identity manager to be used when creating the template.
Definition at line 97 of file templateparserjob.cpp.
◆ setReplyAsHtml()
void TemplateParserJob::setReplyAsHtml | ( | bool | replyAsHtml | ) |
Definition at line 239 of file templateparserjob.cpp.
◆ setSelection()
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 81 of file templateparserjob.cpp.
◆ setWordWrap()
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 1368 of file templateparserjob.cpp.
The documentation for this class was generated from the following files:
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:33:27 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.