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
|
/*
* qtmaildir - a Qt6 mail client for notmuch-indexed Maildirs
* Copyright (C) 2026 Danilo M. <danix@danix.xyz>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#pragma once
#include <QList>
#include <QUrl>
#include <QWidget>
#include "htmlbuilder.h"
#include "mimeparser.h"
class QLabel;
class QPushButton;
class QWebEngineView;
class QWebEngineProfile;
class CidSchemeHandler;
class TagColors;
class TagStrip;
class RequestInterceptor;
/// The message pane: thread header, body, attachment bar.
///
/// A whole thread renders into one web view. A newsletter thread can hold
/// dozens of messages, and one view per message would spawn one Chromium
/// render process per message.
class MessageView : public QWidget
{
Q_OBJECT
public:
explicit MessageView(QWidget *parent = nullptr);
~MessageView() override;
/// The base URL every document in this pane is loaded with, and the only
/// qtmaildir: URL the interceptor trusts. Defined once so setHtml() and
/// setDocumentUrl() cannot drift apart: if they ever disagree, the
/// interceptor fails closed and the pane renders nothing at all.
static QUrl documentUrl() { return QUrl(QStringLiteral("qtmaildir://message")); }
/// Renders a whole thread, oldest first. Items whose expanded flag is
/// false collapse to a one-line stub.
void showThread(const QList<ThreadRenderItem> &items);
void showError(const QString &text, const QString &filePath);
void clear();
/// Shows the branded pane used when no thread is displayed.
///
/// Separate from clear(), which still exists and still blanks: clear()
/// drops the previous thread's state, and a caller that wants the
/// placeholder asks for it afterwards. Keeping them apart is what stops
/// the pane flashing a logo between selecting a thread and rendering it,
/// which the item lists as a constraint.
///
/// helpers are already-translated lines; an empty query makes one plain
/// text rather than a link.
void showPlaceholder(const QList<HtmlBuilder::PlaceholderHelper> &helpers);
/// True while the placeholder is what the view is showing. Lets the window
/// re-render it with fresh counts without guessing what is on screen.
bool showingPlaceholder() const { return m_showingPlaceholder; }
/// Supplies the tag strip's colours. Not owned; must outlive the view.
void setTagColors(const TagColors *colours);
/// Tags of the thread on display, shown as chips along the bottom.
void setTags(const QStringList &tags);
/// The full headers of every message in the thread, read-only. Also
/// reachable from the button beside the header; public so the window's
/// message_details action can call it.
///
/// Plain text, not rich: header values are attacker-controlled and this
/// dialog exists to show them verbatim, so the format that cannot
/// interpret markup is the right one.
void showDetailsDialog();
/// The body zoom factor. Chromium's own range is roughly 0.25 to 5.0;
/// these are tighter, since a pane at either extreme is unusable and the
/// only visible way back is a menu entry the user cannot read.
static constexpr qreal kMinZoom = 0.5;
static constexpr qreal kMaxZoom = 3.0;
static constexpr qreal kDefaultZoom = 1.0;
/// Clamps to [kMinZoom, kMaxZoom]. A non-finite or non-positive value,
/// which is what a corrupt state file yields, falls back to kDefaultZoom.
static qreal clampZoom(qreal factor);
qreal zoomFactor() const;
void setZoomFactor(qreal factor);
public slots:
void toggleHtml();
void loadRemoteContent();
void zoomIn();
void zoomOut();
void zoomReset();
signals:
void statusMessage(const QString &text);
/// A helper line on the placeholder was clicked. The window runs the query;
/// the view has no business driving the query bar itself.
///
/// **Gated on the placeholder being what is displayed.** A message body is
/// attacker-controlled HTML and can carry a qtmaildir-query: link as easily
/// as any other; without the gate, clicking one would let a stranger's mail
/// drive the thread list. The consequence is mild (a query runs, nothing is
/// mutated or sent), but "a link in a message does something inside the
/// app" is a boundary worth keeping shut rather than arguing about.
void queryRequested(const QString &query);
protected:
/// Turns Ctrl+wheel over the body into zoom, and Ctrl+middle-click into a
/// reset. Both events are delivered to the web view's internal QQuickWidget
/// focus proxy, not to the view itself, so this filters the whole subtree
/// rather than one widget.
bool eventFilter(QObject *watched, QEvent *event) override;
/// Re-renders when the desktop theme changes.
///
/// The document's colours are baked into its stylesheet at build time, so
/// unlike a widget it does not restyle itself: switching the desktop from
/// light to dark would otherwise leave the open thread on the old palette
/// until the next selection.
void changeEvent(QEvent *event) override;
private:
void render();
void updateHeader();
void setDocument(const QString &html);
/// Rebuilds the attachment bar from m_items. Called from render(), so a
/// toggle between HTML and plain text keeps the bar in step with what is
/// on screen.
///
/// The bar holds ONE button however many attachments a thread carries. A
/// button per file resized the splitter and crushed the thread list on a
/// thread with fifteen of them.
void rebuildAttachmentBar();
/// The list of attachments, with a save button each and a "save all".
void showAttachmentDialog();
/// Saves one attachment, asking for the target directory. Writing goes
/// through Attachment::saveTo(), which is where the path-traversal guard
/// lives; the filename in a message is attacker-controlled.
void saveAttachment(const Attachment &attachment);
/// Saves every attachment into a new subdirectory of a directory the user
/// picks, so fifteen files do not land loose among hundreds of others and
/// cannot collide with what is already there.
void saveAllAttachments();
/// Every attachment in the thread, in the order the messages render.
QList<Attachment> allAttachments() const;
QList<ThreadRenderItem> m_items;
bool m_preferHtml = true;
/// Gates queryRequested(), so a link in a message body cannot run a query.
bool m_showingPlaceholder = false;
QWebEngineProfile *m_profile = nullptr;
QWebEngineView *m_view = nullptr;
RequestInterceptor *m_interceptor = nullptr;
CidSchemeHandler *m_cidHandler = nullptr;
QLabel *m_headerLabel = nullptr;
QLabel *m_blockedLabel = nullptr;
QPushButton *m_loadRemoteButton = nullptr;
QPushButton *m_detailsButton = nullptr;
QWidget *m_attachmentBar = nullptr;
TagStrip *m_tagStrip = nullptr;
};
|