File indexing completed on 2025-01-19 04:46:54
0001 /* 0002 SPDX-FileCopyrightText: 2013-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "enterpriseheaderstyle.h" 0008 #include <MessageViewer/MessageViewerSettings> 0009 0010 #include <MessageViewer/HeaderStrategy> 0011 0012 #include <MessageCore/StringUtil> 0013 0014 #include <KColorScheme> 0015 #include <KLocalizedString> 0016 0017 #include <QStandardPaths> 0018 0019 using namespace MessageCore; 0020 using namespace MessageViewer; 0021 0022 QString EnterpriseHeaderStyle::format(KMime::Message *message) const 0023 { 0024 if (!message) { 0025 return {}; 0026 } 0027 const HeaderStrategy *strategy = headerStrategy(); 0028 // The direction of the header is determined according to the direction 0029 // of the application layout. 0030 // However, the direction of the message subject within the header is 0031 // determined according to the contents of the subject itself. Since 0032 // the "Re:" and "Fwd:" prefixes would always cause the subject to be 0033 // considered left-to-right, they are ignored when determining its 0034 // direction. 0035 0036 // colors depend on if it is encapsulated or not 0037 QColor fontColor(Qt::white); 0038 QString linkColor = QStringLiteral("class =\"white\""); 0039 if (!mActiveColor.isValid()) { 0040 mActiveColor = KColorScheme(QPalette::Active, KColorScheme::Selection).background().color(); 0041 } 0042 QColor activeColorDark = mActiveColor.darker(130); 0043 // reverse colors for encapsulated 0044 if (!isTopLevel()) { 0045 activeColorDark = mActiveColor.darker(50); 0046 fontColor = QColor(Qt::black); 0047 linkColor = QStringLiteral("class =\"black\""); 0048 } 0049 0050 QString imgpath(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("libmessageviewer/pics/"), QStandardPaths::LocateDirectory)); 0051 imgpath.prepend(QLatin1StringView("file://")); 0052 imgpath.append(QLatin1StringView("enterprise_")); 0053 const QString borderSettings(QStringLiteral(" padding-top: 0px; padding-bottom: 0px; border-width: 0px ")); 0054 QString headerStr; 0055 0056 // 3D borders 0057 if (isTopLevel()) { 0058 headerStr += QLatin1StringView( 0059 "<div style=\"position: fixed; top: 0px; left: 0px; background-color: #606060; " 0060 "width: 10px; min-height: 100%;\"> </div>" 0061 "<div style=\"position: fixed; top: 0px; right: 0px; background-color: #606060; " 0062 "width: 10px; min-height: 100%;\"> </div>"); 0063 } 0064 0065 headerStr += QStringLiteral("<div style=\"margin-left: 10px; top: 0px;\"><span style=\"font-size: 0.8em; font-weight: bold;\">") 0066 + HeaderStyleUtil::dateString(message, /* shortDate */ MessageViewer::HeaderStyleUtil::CustomDate) 0067 + QStringLiteral( 0068 "</span></div>" 0069 // #0057ae 0070 "<table style=\"background: ") 0071 + activeColorDark.name() 0072 + QStringLiteral( 0073 "; border-collapse:collapse; top: 14px; min-width: 200px; \" cellpadding='0'> \n" 0074 " <tr> \n" 0075 " <td style=\"min-width: 6px; background-image: url(") 0076 + imgpath 0077 + QStringLiteral( 0078 "top_left.png); \"></td> \n" 0079 " <td style=\"height: 6px; width: 100%; background: url(") 0080 + imgpath 0081 + QStringLiteral( 0082 "top.png); \"></td> \n" 0083 " <td style=\"min-width: 6px; background: url(") 0084 + imgpath 0085 + QStringLiteral( 0086 "top_right.png); \"></td> </tr> \n" 0087 " <tr> \n" 0088 " <td style=\"min-width: 6px; max-width: 6px; background: url(") 0089 + imgpath 0090 + QStringLiteral( 0091 "left.png); \"></td> \n" 0092 " <td style=\"\"> \n"); 0093 headerStr += QStringLiteral( 0094 "<div class=\"noprint\" style=\"z-index: 1; float:right; position: relative; top: -35px; right: 20px ; max-height: 65px\">\n" 0095 "<img src=\"") 0096 + imgpath 0097 + QStringLiteral( 0098 "icon.png\"/>\n" 0099 "</div>\n"); 0100 headerStr += QLatin1StringView(" <table style=\"color: ") + fontColor.name() 0101 + QLatin1StringView(" ! important; margin: 1px; border-spacing: 0px;\" cellpadding='0'> \n"); 0102 0103 // subject 0104 if (strategy->showHeader(QStringLiteral("subject"))) { 0105 const KTextToHTML::Options flags = KTextToHTML::PreserveSpaces | KTextToHTML::ReplaceSmileys; 0106 0107 headerStr += QStringLiteral( 0108 " <tr> \n" 0109 " <td style=\"font-size: 0.5em; text-align: right; padding-left: 5px; padding-right: 24px; ") 0110 + borderSettings 0111 + QStringLiteral( 0112 "\"></td> \n" 0113 " <td style=\"font-weight: bolder; font-size: 120%; padding-right: 91px; ") 0114 + borderSettings + QStringLiteral("\">"); 0115 headerStr += mHeaderStyleUtil.subjectString(message, flags) 0116 + QStringLiteral( 0117 "</td> \n" 0118 " </tr> \n"); 0119 } 0120 0121 // from 0122 if (strategy->showHeader(QStringLiteral("from"))) { 0123 // We by design use the stripped mail address here, it is more enterprise-like. 0124 QString fromPart = StringUtil::emailAddrAsAnchor(message->from(), StringUtil::DisplayFullAddress, linkColor); 0125 if (!vCardName().isEmpty()) { 0126 fromPart += QLatin1StringView(" <a href=\"") + vCardName() + QLatin1StringView("\" ") + linkColor + QLatin1Char('>') + i18n("[vCard]") 0127 + QLatin1StringView("</a>"); 0128 } 0129 // TDDO strategy date 0130 // if ( strategy->showHeader( "date" ) ) 0131 headerStr += QStringLiteral( 0132 " <tr> \n" 0133 " <td style=\"font-size: 0.8em; padding-left: 5px; padding-right: 24px; text-align: right; vertical-align:top; ") 0134 + borderSettings + QLatin1StringView("\">") + i18n("From: ") 0135 + QStringLiteral( 0136 "</td> \n" 0137 " <td style=\"") 0138 + borderSettings + QStringLiteral("\">") + fromPart 0139 + QStringLiteral( 0140 "</td> " 0141 " </tr> "); 0142 } 0143 0144 // to line 0145 if (strategy->showHeader(QStringLiteral("to"))) { 0146 headerStr += QStringLiteral( 0147 " <tr> " 0148 " <td style=\"font-size: 0.8em; text-align: right; vertical-align:top; padding-left: 5px; padding-right: 24px; ") 0149 + borderSettings + QLatin1StringView("\">") + i18n("To: ") 0150 + QStringLiteral( 0151 "</td> " 0152 " <td style=\"") 0153 + borderSettings + QStringLiteral("\">") + StringUtil::emailAddrAsAnchor(message->to(), StringUtil::DisplayFullAddress, linkColor) 0154 + QStringLiteral( 0155 " </td> " 0156 " </tr>\n"); 0157 } 0158 0159 // cc line, if any 0160 if (strategy->showHeader(QStringLiteral("cc")) && message->cc(false)) { 0161 headerStr += QStringLiteral( 0162 " <tr> " 0163 " <td style=\"font-size: 0.8em; text-align: right; vertical-align:top; padding-left: 5px; padding-right: 24px; ") 0164 + borderSettings + QLatin1StringView("\">") + i18n("CC: ") 0165 + QStringLiteral( 0166 "</td> " 0167 " <td style=\"") 0168 + borderSettings + QStringLiteral("\">") + StringUtil::emailAddrAsAnchor(message->cc(), StringUtil::DisplayFullAddress, linkColor) 0169 + QStringLiteral( 0170 " </td> " 0171 " </tr>\n"); 0172 } 0173 0174 // bcc line, if any 0175 if (strategy->showHeader(QStringLiteral("bcc")) && message->bcc(false)) { 0176 headerStr += QStringLiteral( 0177 " <tr> " 0178 " <td style=\"font-size: 0.8em; text-align: right; vertical-align:top; padding-left: 5px; padding-right: 24px; ") 0179 + borderSettings + QLatin1StringView("\">") + i18n("BCC: ") 0180 + QStringLiteral( 0181 "</td> " 0182 " <td style=\"") 0183 + borderSettings + QStringLiteral("\">") + StringUtil::emailAddrAsAnchor(message->bcc(), StringUtil::DisplayFullAddress, linkColor) 0184 + QStringLiteral( 0185 " </td> " 0186 " </tr>\n"); 0187 } 0188 0189 // attachments 0190 QString attachment; 0191 if (isTopLevel()) { 0192 attachment = QStringLiteral( 0193 "<tr>" 0194 "<td style='min-width: 6px; max-width: 6px; background: url(") 0195 + imgpath 0196 + QStringLiteral( 0197 "left.png);'></td>" 0198 "<td style='padding-right:20px;'>" 0199 "<div class=\"noprint\" >" 0200 "<div>%1</div>" 0201 "</div>" 0202 "</td>" 0203 "<td style='min-width: 6px; max-width: 6px; background: url(") 0204 .arg(attachmentHtml()) 0205 + imgpath 0206 + QStringLiteral( 0207 "right.png);'></td>" 0208 "</tr>"); 0209 } 0210 0211 // header-bottom 0212 headerStr += QStringLiteral( 0213 " </table> \n" 0214 " </td> \n" 0215 " <td style=\"min-width: 6px; max-height: 15px; background: url(") 0216 + imgpath 0217 + QStringLiteral( 0218 "right.png); \"></td> \n" 0219 " </tr> \n") 0220 + attachment 0221 + QStringLiteral( 0222 " <tr> \n" 0223 " <td style=\"min-width: 6px; background: url(") 0224 + imgpath 0225 + QStringLiteral( 0226 "s_left.png); \"></td> \n" 0227 " <td style=\"height: 35px; width: 80%; background: url(") 0228 + imgpath 0229 + QStringLiteral( 0230 "sbar.png);\"> \n" 0231 " <img src=\"") 0232 + imgpath 0233 + QStringLiteral( 0234 "sw.png\" style=\"margin: 0px; height: 30px; overflow:hidden; \"/> \n" 0235 " <img src=\"") 0236 + imgpath 0237 + QStringLiteral( 0238 "sp_right.png\" style=\"float: right; \"/> </td> \n" 0239 " <td style=\"min-width: 6px; background: url(") 0240 + imgpath 0241 + QStringLiteral( 0242 "s_right.png); \"></td> \n" 0243 " </tr> \n" 0244 " </table> \n"); 0245 0246 if (isPrinting()) { 0247 // provide a bit more left padding when printing 0248 // kolab/issue3254 (printed mail cut at the left side) 0249 headerStr += QLatin1StringView("<div style=\"padding: 6px; padding-left: 10px;\">"); 0250 } else { 0251 headerStr += QLatin1StringView("<div style=\"padding: 6px;\">"); 0252 } 0253 0254 // TODO 0255 // spam status 0256 // ### iterate over the rest of strategy->headerToDisplay() (or 0257 // ### all headers if DefaultPolicy == Display) (elsewhere, too) 0258 return headerStr; 0259 } 0260 0261 const char *MessageViewer::EnterpriseHeaderStyle::name() const 0262 { 0263 return "enterprise"; 0264 }