File: enterpriseheaderstyle.cpp

package info (click to toggle)
kdepim-addons 25.12.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 35,776 kB
  • sloc: cpp: 47,568; xml: 282; sh: 114; makefile: 19
file content (264 lines) | stat: -rw-r--r-- 11,217 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
/*
   SPDX-FileCopyrightText: 2013-2025 Laurent Montel <montel@kde.org>

   SPDX-License-Identifier: GPL-2.0-or-later
*/

#include "enterpriseheaderstyle.h"
#include <MessageViewer/MessageViewerSettings>

#include <MessageViewer/HeaderStrategy>

#include <MessageCore/StringUtil>

#include <KColorScheme>
#include <KLocalizedString>

#include <QStandardPaths>

using namespace MessageCore;
using namespace MessageViewer;

QString EnterpriseHeaderStyle::format(KMime::Message *message) const
{
    if (!message) {
        return {};
    }
    const HeaderStrategy *strategy = headerStrategy();
    // The direction of the header is determined according to the direction
    // of the application layout.
    // However, the direction of the message subject within the header is
    // determined according to the contents of the subject itself. Since
    // the "Re:" and "Fwd:" prefixes would always cause the subject to be
    // considered left-to-right, they are ignored when determining its
    // direction.

    // colors depend on if it is encapsulated or not
    QColor fontColor(Qt::white);
    QString linkColor = QStringLiteral("class =\"white\"");
    if (!mActiveColor.isValid()) {
        mActiveColor = KColorScheme(QPalette::Active, KColorScheme::Selection).background().color();
    }
    QColor activeColorDark = mActiveColor.darker(130);
    // reverse colors for encapsulated
    if (!isTopLevel()) {
        activeColorDark = mActiveColor.darker(50);
        fontColor = QColor(Qt::black);
        linkColor = QStringLiteral("class =\"black\"");
    }

    QString imgpath(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("libmessageviewer/pics/"), QStandardPaths::LocateDirectory));
    imgpath.prepend(QLatin1StringView("file://"));
    imgpath.append(QLatin1StringView("enterprise_"));
    const QString borderSettings(QStringLiteral(" padding-top: 0px; padding-bottom: 0px; border-width: 0px "));
    QString headerStr;

    // 3D borders
    if (isTopLevel()) {
        headerStr += QLatin1StringView(
            "<div style=\"position: fixed; top: 0px; left: 0px; background-color: #606060; "
            "width: 10px; min-height: 100%;\">&nbsp;</div>"
            "<div style=\"position: fixed; top: 0px; right: 0px;  background-color: #606060; "
            "width: 10px; min-height: 100%;\">&nbsp;</div>");
    }

    headerStr += QStringLiteral("<div style=\"margin-left: 10px; top: 0px;\"><span style=\"font-size: 0.8em; font-weight: bold;\">")
        + HeaderStyleUtil::dateString(message, /* shortDate */ MessageViewer::HeaderStyleUtil::CustomDate)
        + QStringLiteral(
                     "</span></div>"
                     // #0057ae
                     "<table style=\"background: ")
        + activeColorDark.name()
        + QStringLiteral(
                     "; border-collapse:collapse; top: 14px; min-width: 200px; \" cellpadding='0'> \n"
                     "  <tr> \n"
                     "   <td style=\"min-width: 6px; background-image: url(")
        + imgpath
        + QStringLiteral(
                     "top_left.png); \"></td> \n"
                     "   <td style=\"height: 6px; width: 100%; background: url(")
        + imgpath
        + QStringLiteral(
                     "top.png); \"></td> \n"
                     "   <td style=\"min-width: 6px; background: url(")
        + imgpath
        + QStringLiteral(
                     "top_right.png); \"></td> </tr> \n"
                     "   <tr> \n"
                     "   <td style=\"min-width: 6px; max-width: 6px; background: url(")
        + imgpath
        + QStringLiteral(
                     "left.png); \"></td> \n"
                     "   <td style=\"\"> \n");
    headerStr += QStringLiteral(
                     "<div class=\"noprint\" style=\"z-index: 1; float:right; position: relative; top: -35px; right: 20px ; max-height: 65px\">\n"
                     "<img src=\"")
        + imgpath
        + QStringLiteral(
                     "icon.png\"/>\n"
                     "</div>\n");
    headerStr += QLatin1StringView("    <table style=\"color: ") + fontColor.name()
        + QLatin1StringView(" ! important; margin: 1px; border-spacing: 0px;\" cellpadding='0'> \n");

    // subject
    if (strategy->showHeader(QStringLiteral("subject"))) {
        const KTextToHTML::Options flags = KTextToHTML::PreserveSpaces | KTextToHTML::ReplaceSmileys;

        headerStr += QStringLiteral(
                         "     <tr> \n"
                         "      <td style=\"font-size: 0.5em; text-align: right; padding-left: 5px; padding-right: 24px; ")
            + borderSettings
            + QStringLiteral(
                         "\"></td> \n"
                         "      <td style=\"font-weight: bolder; font-size: 120%; padding-right: 91px; ")
            + borderSettings + QStringLiteral("\">");
        headerStr += mHeaderStyleUtil.subjectString(message, flags)
            + QStringLiteral(
                         "</td> \n"
                         "     </tr> \n");
    }

    // from
    if (strategy->showHeader(QStringLiteral("from"))) {
        // We by design use the stripped mail address here, it is more enterprise-like.
        QString fromPart = StringUtil::emailAddrAsAnchor(message->from(), StringUtil::DisplayFullAddress, linkColor);
        if (!vCardName().isEmpty()) {
            fromPart += QLatin1StringView("&nbsp;&nbsp;<a href=\"") + vCardName() + QLatin1StringView("\" ") + linkColor + QLatin1Char('>') + i18n("[vCard]")
                + QLatin1StringView("</a>");
        }
        // TDDO strategy date
        // if ( strategy->showHeader( "date" ) )
        headerStr += QStringLiteral(
                         "     <tr> \n"
                         "      <td style=\"font-size: 0.8em; padding-left: 5px; padding-right: 24px; text-align: right; vertical-align:top; ")
            + borderSettings + QLatin1StringView("\">") + i18n("From: ")
            + QStringLiteral(
                         "</td> \n"
                         "      <td style=\"")
            + borderSettings + QStringLiteral("\">") + fromPart
            + QStringLiteral(
                         "</td> "
                         "     </tr> ");
    }

    // to line
    if (strategy->showHeader(QStringLiteral("to"))) {
        headerStr += QStringLiteral(
                         "     <tr> "
                         "      <td style=\"font-size: 0.8em; text-align: right; vertical-align:top; padding-left: 5px; padding-right: 24px; ")
            + borderSettings + QLatin1StringView("\">") + i18n("To: ")
            + QStringLiteral(
                         "</td> "
                         "      <td style=\"")
            + borderSettings + QStringLiteral("\">") + StringUtil::emailAddrAsAnchor(message->to(), StringUtil::DisplayFullAddress, linkColor)
            + QStringLiteral(
                         "      </td> "
                         "     </tr>\n");
    }

    // cc line, if any
    if (strategy->showHeader(QStringLiteral("cc")) && message->cc(false)) {
        headerStr += QStringLiteral(
                         "     <tr> "
                         "      <td style=\"font-size: 0.8em; text-align: right; vertical-align:top; padding-left: 5px; padding-right: 24px; ")
            + borderSettings + QLatin1StringView("\">") + i18n("CC: ")
            + QStringLiteral(
                         "</td> "
                         "      <td style=\"")
            + borderSettings + QStringLiteral("\">") + StringUtil::emailAddrAsAnchor(message->cc(), StringUtil::DisplayFullAddress, linkColor)
            + QStringLiteral(
                         "      </td> "
                         "     </tr>\n");
    }

    // bcc line, if any
    if (strategy->showHeader(QStringLiteral("bcc")) && message->bcc(false)) {
        headerStr += QStringLiteral(
                         "     <tr> "
                         "      <td style=\"font-size: 0.8em; text-align: right; vertical-align:top; padding-left: 5px; padding-right: 24px; ")
            + borderSettings + QLatin1StringView("\">") + i18n("BCC: ")
            + QStringLiteral(
                         "</td> "
                         "      <td style=\"")
            + borderSettings + QStringLiteral("\">") + StringUtil::emailAddrAsAnchor(message->bcc(), StringUtil::DisplayFullAddress, linkColor)
            + QStringLiteral(
                         "      </td> "
                         "     </tr>\n");
    }

    // attachments
    QString attachment;
    if (isTopLevel()) {
        attachment = QStringLiteral(
                         "<tr>"
                         "<td style='min-width: 6px; max-width: 6px; background: url(")
            + imgpath
            + QStringLiteral(
                  "left.png);'></td>"
                  "<td style='padding-right:20px;'>"
                  "<div class=\"noprint\" >"
                  "<div>%1</div>"
                  "</div>"
                  "</td>"
                  "<td style='min-width: 6px; max-width: 6px; background: url(")
                  .arg(attachmentHtml())
            + imgpath
            + QStringLiteral(
                         "right.png);'></td>"
                         "</tr>");
    }

    // header-bottom
    headerStr += QStringLiteral(
                     "    </table> \n"
                     "   </td> \n"
                     "   <td style=\"min-width: 6px; max-height: 15px; background: url(")
        + imgpath
        + QStringLiteral(
                     "right.png); \"></td> \n"
                     "  </tr> \n")
        + attachment
        + QStringLiteral(
                     "  <tr> \n"
                     "   <td style=\"min-width: 6px; background: url(")
        + imgpath
        + QStringLiteral(
                     "s_left.png); \"></td> \n"
                     "   <td style=\"height: 35px; width: 80%; background: url(")
        + imgpath
        + QStringLiteral(
                     "sbar.png);\"> \n"
                     "    <img src=\"")
        + imgpath
        + QStringLiteral(
                     "sw.png\" style=\"margin: 0px; height: 30px; overflow:hidden; \"/> \n"
                     "    <img src=\"")
        + imgpath
        + QStringLiteral(
                     "sp_right.png\" style=\"float: right; \"/> </td> \n"
                     "   <td style=\"min-width: 6px; background: url(")
        + imgpath
        + QStringLiteral(
                     "s_right.png); \"></td> \n"
                     "  </tr> \n"
                     " </table> \n");

    if (isPrinting()) {
        // provide a bit more left padding when printing
        // kolab/issue3254 (printed mail cut at the left side)
        headerStr += QLatin1StringView("<div style=\"padding: 6px; padding-left: 10px;\">");
    } else {
        headerStr += QLatin1StringView("<div style=\"padding: 6px;\">");
    }

    // TODO
    // spam status
    // ### iterate over the rest of strategy->headerToDisplay() (or
    // ### all headers if DefaultPolicy == Display) (elsewhere, too)
    return headerStr;
}

const char *MessageViewer::EnterpriseHeaderStyle::name() const
{
    return "enterprise";
}