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
|
/*
** Copyright (C) 2023 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
**
** This program is free software; you can redistribute it and/or modify it
** under the terms of the GNU General Public License as published by the
** Free Software Foundation; either version 3, or (at your option) any
** later version.
**
** 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.
**
*/
#ifndef MU_MESSAGE_PART_HH__
#define MU_MESSAGE_PART_HH__
#include <string>
#include <memory>
#include <utils/mu-option.hh>
#include <utils/mu-result.hh>
namespace Mu {
class MimeObject; // forward declaration; don't want to include for build-time
// reasons.
class MessagePart {
public:
/**
* Construct MessagePart from a MimeObject
*
* @param obj
*/
MessagePart(const MimeObject& obj);
/**
* Copy CTOR
*
* @param other
*/
MessagePart(const MessagePart& other);
/**
* DTOR
*
*/
~MessagePart();
/**
* Get the underlying MimeObject; you need to include mu-mime-object.hh
* to do anything useful with it.
*
* @return reference to the mime-object
*/
const MimeObject& mime_object() const noexcept;
/**
* Filename for the mime-part file. This is a "cooked" filename with
* unallowed characters removed. If there's no filename specified,
* construct one (such as in the case of a MimeMessagePart).
*
* @param minimal if true, only perform *minimal* cookiing, where we
* only remove forward-slashes.
*
* @see raw_filename()
*
* @return the name
*/
Option<std::string> cooked_filename(bool minimal=false) const noexcept;
/**
* Name for the mime-part file, i.e., MimePart::filename
*
* @return the filename or Nothing if there is none
*/
Option<std::string> raw_filename() const noexcept;
/**
* Mime-type for the mime-part (e.g. "text/plain")
*
* @return the mime-part or Nothing if there is none
*/
Option<std::string> mime_type() const noexcept;
/**
* Get the content description for this part, or Nothing
*
* @return the content description
*/
Option<std::string> content_description() const noexcept;
/**
* Get the length of the (unencoded) MIME-part.
*
* @return the size
*/
size_t size() const noexcept;
/**
* Does this part have an "attachment" disposition? Otherwise it is
* "inline". Note that does *not* map 1:1 to a message's HasAttachment
* flag (which uses looks_like_attachment())
*
* @return true or false.
*/
bool is_attachment() const noexcept;
/**
* Does this part appear to be an attachment from an end-users point of
* view? This uses some heuristics to guess. Some parts for which
* is_attachment() is true may not "really" be attachments, and
* vice-versa
*
* @return true or false.
*/
bool looks_like_attachment() const noexcept;
/**
* Is this part signed?
*
* @return true or false
*/
bool is_signed() const noexcept;
/**
* Is this part encrypted?
*
* @return true or false
*/
bool is_encrypted() const noexcept;
/**
* Write (decoded) mime-part contents to string
*
* @return a string or nothing if there is no contemt
*/
Option<std::string> to_string() const noexcept;
/**
* Write (decoded) mime part to a file
*
* @param path path to file
* @param overwrite whether to possibly overwrite
*
* @return size of file or or an error.
*/
Result<size_t> to_file(const std::string& path, bool overwrite) const noexcept;
struct Private;
private:
const std::unique_ptr<MimeObject> mime_obj;
};
} // namespace Mu
#endif /* MU_MESSAGE_PART_HH__ */
|