MessageCore::StringUtil Namespace

namespace MessageCore::StringUtil
Header: #include <stringutil.h>
CMake: find_package(KPim6MessageCore REQUIRED)
target_link_libraries(mytarget PRIVATE KPim6::MessageCore)

Types

enum AddressMode { ExpandableAddresses, FullAddresses }
enum Display { DisplayNameOnly, DisplayFullAddress }
enum Link { ShowLink, HideLink }

Functions

bool addressIsInAddressList(const QString &address, const QStringList &addresses)
QByteArray asSendableString(const std::shared_ptr<KMime::Message> &message)
QString cleanFileName(const QString &fileName)
QString cleanSubject(KMime::Message *msg)
QString cleanSubject(KMime::Message *msg, const QStringList &prefixRegExps, bool replace, const QString &newPrefix)
QString emailAddrAsAnchor(const KMime::Headers::Generics::AddressList *addressList, MessageCore::StringUtil::Display display = DisplayNameOnly, const QString &cssStyle = QString(), MessageCore::StringUtil::Link link = ShowLink, MessageCore::StringUtil::AddressMode expandable = FullAddresses, const QString &fieldName = QString(), int collapseNumber = 4)
QString emailAddrAsAnchor(const KMime::Headers::Generics::MailboxList *mailboxList, MessageCore::StringUtil::Display display = DisplayNameOnly, const QString &cssStyle = QString(), MessageCore::StringUtil::Link link = ShowLink, MessageCore::StringUtil::AddressMode expandable = FullAddresses, const QString &fieldName = QString(), int collapseNumber = 4)
QString emailAddrAsAnchor(const QList<KMime::Types::Mailbox> &mailboxList, MessageCore::StringUtil::Display display = DisplayNameOnly, const QString &cssStyle = QString(), MessageCore::StringUtil::Link link = ShowLink, MessageCore::StringUtil::AddressMode expandable = FullAddresses, const QString &fieldName = QString(), int collapseNumber = 4)
QString formatQuotePrefix(const QString &wildString, const QString &fromDisplayString)
QString forwardSubject(KMime::Message *msg)
QString guessEmailAddressFromLoginName(const QString &userName)
QByteArray headerAsSendableString(const std::shared_ptr<KMime::Message> &message)
QList<std::pair<QString, QString>> parseMailtoUrl(const QUrl &url)
QString quoteHtmlChars(const QString &text, bool removeLineBreaks = false)
void removePrivateHeaderFields(const std::shared_ptr<KMime::Message> &message, bool cleanUpHeader = true)
QString replacePrefixes(const QString &str, const QStringList &prefixRegExps, bool replace, const QString &newPrefix)
QString replySubject(KMime::Message *msg)
QString smartQuote(const QString &message, int maxLineLength)
QList<KMime::Types::Address> splitAddressField(const QByteArray &text)
QString stripOffPrefixes(const QString &subject)
QString stripSignature(const QString &message)

Detailed Description

This namespace contain helper functions for string manipulation

Type Documentation

enum StringUtil::AddressMode

Used to determine if the address field should be expandable/collapsible.

enum StringUtil::Display

Used to determine if the visible part of the anchor contains only the name part and not the given emailAddr or the full address.

Used to determine if the address should be a link or not.

Function Documentation

bool StringUtil::addressIsInAddressList(const QString &address, const QStringList &addresses)

Returns true if the given address is contained in the given address list.

QByteArray StringUtil::asSendableString(const std::shared_ptr<KMime::Message> &message)

Returns the message contents with the headers that should not be sent stripped off.

QString StringUtil::cleanFileName(const QString &fileName)

Cleans a filename by replacing characters not allowed or wanted on the filesystem e.g. ':', '/', '' with '_'

QString StringUtil::cleanSubject(KMime::Message *msg)

Return this mails subject, with all "forward" and "reply" prefixes removed

QString StringUtil::cleanSubject(KMime::Message *msg, const QStringList &prefixRegExps, bool replace, const QString &newPrefix)

Check for prefixes prefixRegExps in #subject(). If none is found, newPrefix + ' ' is prepended to the subject and the resulting string is returned. If replace is true, any sequence of whitespace-delimited prefixes at the beginning of #subject() is replaced by newPrefix *

QString StringUtil::emailAddrAsAnchor(const KMime::Headers::Generics::AddressList *addressList, MessageCore::StringUtil::Display display = DisplayNameOnly, const QString &cssStyle = QString(), MessageCore::StringUtil::Link link = ShowLink, MessageCore::StringUtil::AddressMode expandable = FullAddresses, const QString &fieldName = QString(), int collapseNumber = 4)

Same as above method, only for AddressList headers.

QString StringUtil::emailAddrAsAnchor(const KMime::Headers::Generics::MailboxList *mailboxList, MessageCore::StringUtil::Display display = DisplayNameOnly, const QString &cssStyle = QString(), MessageCore::StringUtil::Link link = ShowLink, MessageCore::StringUtil::AddressMode expandable = FullAddresses, const QString &fieldName = QString(), int collapseNumber = 4)

Converts the email address(es) to (a) nice HTML mailto: anchor(s). display determines if only the name part or the entire address should be returned. cssStyle a custom css template. link determines if the result should be a html link or not. expandable determines if a long list of addresses should be expandable or shown in full. fieldName the name that the divs should be based on if expandable is set to ExpanableAddesses. The number of addresses to show before collapsing the rest, if expandable is set to ExpandableAddresses.

QString StringUtil::emailAddrAsAnchor(const QList<KMime::Types::Mailbox> &mailboxList, MessageCore::StringUtil::Display display = DisplayNameOnly, const QString &cssStyle = QString(), MessageCore::StringUtil::Link link = ShowLink, MessageCore::StringUtil::AddressMode expandable = FullAddresses, const QString &fieldName = QString(), int collapseNumber = 4)

Same as the above, only for Mailbox::List types.

QString StringUtil::formatQuotePrefix(const QString &wildString, const QString &fromDisplayString)

Convert quote wildcards into the final quote prefix. wildString the string to be converted fromDisplayString displayable string of the from email address

QString StringUtil::forwardSubject(KMime::Message *msg)

Return this mails subject, formatted for "forward" mails

QString StringUtil::guessEmailAddressFromLoginName(const QString &userName)

Uses the hostname as domain part and tries to determine the real name from the entries in the password file.

QByteArray StringUtil::headerAsSendableString(const std::shared_ptr<KMime::Message> &message)

Return the message header with the headers that should not be sent stripped off.

QList<std::pair<QString, QString>> StringUtil::parseMailtoUrl(const QUrl &url)

Parses a mailto: url and extracts the information in the QMap (field name as key).

QString StringUtil::quoteHtmlChars(const QString &text, bool removeLineBreaks = false)

Quotes the following characters which have a special meaning in HTML: '<' '>' '&' '"'. Additionally '\n' is converted to "<br />" if removeLineBreaks is false. If removeLineBreaks is true, then '\n' is removed. Last but not least '\r' is removed.

void StringUtil::removePrivateHeaderFields(const std::shared_ptr<KMime::Message> &message, bool cleanUpHeader = true)

Removes all private header fields (e.g. *Status: and X-KMail-*) from the given message. if cleanUpHeader is false don't remove X-KMail-Identity and X-KMail-Dictionary which is useful when we want restore mail.

QString StringUtil::replacePrefixes(const QString &str, const QStringList &prefixRegExps, bool replace, const QString &newPrefix)

Check for prefixes prefixRegExps in str. If none is found, newPrefix + ' ' is prepended to str and the resulting string is returned. If replace is true, any sequence of whitespace-delimited prefixes at the beginning of str is replaced by newPrefix. *

QString StringUtil::replySubject(KMime::Message *msg)

Return this mails subject, formatted for "reply" mails

QString StringUtil::smartQuote(const QString &message, int maxLineLength)

Relayouts the given string so that the individual lines don't exceed the given maximal length.

As the name of the function implies, it is smart, which means it deals with quoting correctly. This means if a line already starts with quote characters and needs to be broken, the same quote characters are prepended to the next line as well.

This does _not_ add new quote characters in front of every line, that is the responsibility of the caller.

message The string which it to be relayouted maxLineLength reformat text to be this amount of columns at maximum. Note that this also includes the trailing \n!

QList<KMime::Types::Address> StringUtil::splitAddressField(const QByteArray &text)

Splits the given address list text into separate addresses.

QString StringUtil::stripOffPrefixes(const QString &subject)

Removes the forward and reply marks (e.g. Re: or Fwd:) from a subject string. Additional markers to act on can be specified in the MessageCore::GlobalSettings object.

QString StringUtil::stripSignature(const QString &message)

Strips the signature blocks from a message text. "– " is considered as a signature block separator.

message The message to remove the signature block from.