KMime

content.h
Go to the documentation of this file.
1/*
2 KMime, the KDE Internet mail/usenet news message library.
3 SPDX-FileCopyrightText: 2001 the KMime authors.
4 See file AUTHORS for details
5 SPDX-FileCopyrightText: 2006 Volker Krause <vkrause@kde.org>
6 SPDX-FileCopyrightText: 2009 Constantin Berzan <exit3219@gmail.com>
7
8 SPDX-License-Identifier: LGPL-2.0-or-later
9*/
10/**
11 @file
12 This file is part of the API for handling @ref MIME data and
13 defines the Content class.
14
15 @brief
16 Defines the Content class.
17
18 @authors the KMime authors (see AUTHORS file),
19 Volker Krause <vkrause@kde.org>
20
21TODO: possible glossary terms:
22 content
23 encoding, transfer type, disposition, description
24 header
25 body
26 attachment
27 charset
28 article
29 string representation
30 broken-down object representation
31*/
32
33#pragma once
34
35#include "kmime_export.h"
36#include "contentindex.h"
37#include "util.h"
38#include "headers.h"
39
40#include <QByteArray>
41#include <QList>
42#include <QMetaType>
43#include <QSharedPointer>
44
45#include <ranges>
46
47namespace KMime
48{
49
50class ContentPrivate;
51class Message;
52
53/**
54 @brief
55 A class that encapsulates @ref MIME encoded Content.
56
57 A Content object holds two representations of a content:
58 - the string representation: This is the content encoded as a string ready
59 for transport. Accessible through the encodedContent() method.
60 - the broken-down representation: This is the tree of objects (headers,
61 sub-Contents and (if present) the encapsulated message) that this Content is made of.
62 Accessible through methods like header(), contents() and bodyAsMessage().
63
64 The parse() function updates the broken-down representation of the Content
65 from its string representation. Calling it is necessary to access the
66 headers, sub-Contents or the encapsulated message of this Content.
67
68 The assemble() function updates the string representation of the Content
69 from its broken-down representation. Calling it is necessary for
70 encodedContent() to reflect any changes made to the broken-down representation of the Content.
71
72 There are two basic types of a Content:
73 - A leaf Content: This is a content that is neither a multipart content nor an encapsulated
74 message. Because of this, it will not have any children, it has no sub-contents
75 and is therefore a leaf content.
76 Only leaf contents have a body that is not empty, i.e. functions that operate
77 on the body, such as body(), size() and decodedContent(), will work only on
78 leaf contents.
79 - A non-leaf Content: This is a content that itself doesn't have any body, but that does have
80 sub-contents.
81 This is the case for contents that are of mimetype multipart/ or of mimetype
82 message/rfc822. In case of a multipart content, contents() will return the
83 multipart child contents. In case of an encapsulated message, the message
84 can be accessed with bodyAsMessage(), and contents() will have one entry
85 that is the message as well.
86 On a non-leaf content, body() will have an empty return value and other
87 functions working on the body will not work.
88 A call to parse() is required before the child multipart contents or the
89 encapsulated message is created.
90*/
91class KMIME_EXPORT Content
92{
93public:
94
95 /**
96 Describes a list of Content objects.
97 */
99
100 /**
101 Creates an empty Content object with a specified parent.
102 @param parent the parent Content object
103 @since 4.3
104 */
105 explicit Content(Content *parent = nullptr);
106
107 /**
108 Destroys this Content object.
109 */
110 virtual ~Content();
111
112 /**
113 Returns true if this Content object is not empty.
114 */
115 [[nodiscard]] bool hasContent() const;
116
117 /**
118 Sets the Content to the given raw data, containing the Content head and
119 body separated by two linefeeds.
120
121 This method operates on the string representation of the Content. Call
122 parse() if you want to access individual headers, sub-Contents or the
123 encapsulated message.
124
125 @note The passed data must not contain any CRLF sequences, only LF.
126 Use CRLFtoLF for conversion before passing in the data.
127
128 @param s is a QByteArray containing the raw Content data.
129 */
130 void setContent(const QByteArray &s);
131
132 /**
133 * Parses the Content.
134 *
135 * This means the broken-down object representation of the Content is
136 * updated from the string representation of the Content.
137 *
138 * Call this if you want to access or change headers, sub-Contents or the
139 * encapsulated message.
140 *
141 * @note Calling parse() twice will not work for multipart contents or for
142 * contents of which the body is an encapsulated message. The reason is that
143 * the first parse() will delete the body, so there is no body to work on for
144 * the second call of parse().
145 *
146 * @note Calling this will reset the message returned by bodyAsMessage(), as
147 * the message is re-parsed as well.
148 * Also, all old sub-contents will be deleted, so any old Content
149 * pointer will become invalid.
150 */
151 void parse();
152
153 /**
154 Returns whether this Content is frozen.
155 A frozen content is immutable, i.e. calling assemble() will never modify
156 its head or body, and encodedContent() will return the same data before
157 and after parsing.
158
159 @since 4.4.
160 @see setFrozen().
161 */
162 [[nodiscard]] bool isFrozen() const;
163
164 /**
165 Freezes this Content if @p frozen is true; otherwise unfreezes it.
166 @param frozen freeze content if @c true, otherwise unfreeze
167 @since 4.4
168 @see isFrozen().
169 */
170 void setFrozen(bool frozen = true);
171
172 /**
173 Generates the MIME content.
174 This means the string representation of this Content is updated from the
175 broken-down object representation.
176 Call this if you have made changes to the content, and want
177 encodedContent() to reflect those changes.
178
179 @note assemble() has no effect if the Content isFrozen(). You may want
180 to freeze, for instance, signed sub-Contents, to make sure they are kept
181 unmodified.
182
183 @note If this content is an encapsulated message, i.e. bodyIsMessage()
184 returns true, then calling assemble() will also assemble the message
185 returned by bodyAsMessage().
186
187 @warning assemble() may change the order of the headers, and other
188 details such as where folding occurs. This may break things like
189 signature verification, so you should *ONLY* call assemble() when you
190 have actually modified the content.
191 */
192 void assemble();
193
194 /**
195 Clears the content, deleting all headers and sub-Contents.
196 */
197 void clear();
198
199 /**
200 Removes all sub-Contents from this content. Deletes them if @p del is true.
201 This is different from calling removeContent() on each sub-Content, because
202 removeContent() will convert this to a single-part Content if only one
203 sub-Content is left. Calling clearContents() does NOT make this Content
204 single-part.
205
206 @param del Whether to delete the sub-Contents.
207 @see removeContent()
208 @since 4.4
209 */
210 void clearContents(bool del = true);
211
212 /**
213 Returns the Content header raw data.
214
215 @see setHead().
216 */
217 [[nodiscard]] QByteArray head() const;
218
219 /**
220 Sets the Content header raw data.
221
222 This method operates on the string representation of the Content. Call
223 parse() if you want to access individual headers.
224
225 @param head is a QByteArray containing the header data.
226
227 @see head().
228 */
229 void setHead(const QByteArray &head);
230
231 /**
232 * Returns all headers.
233 * @since 5.7
234 */
235 [[nodiscard]] QList<Headers::Base *> headers();
236 [[nodiscard]] inline auto headers() const -> auto
237 {
238#ifdef __cpp_lib_ranges_as_const
239 return const_cast<Content*>(this)->headers() | std::views::transform([](auto c) -> const Headers::Base* { return c; }) | std::views::as_const;
240#else
241 return const_cast<Content*>(this)->headers() | std::views::transform([](auto c) -> const Headers::Base* { return c; });
242#endif
243 }
244
245 /**
246 Returns the first header of type @p type, if it exists. Otherwise returns
247 0. Note that the returned header may be empty.
248 @param type the header type to find
249 @since 4.2
250 */
251 [[nodiscard]] Headers::Base *headerByType(QByteArrayView type) const;
252
253 /**
254 Returns the first header of type T, if it exists.
255 If the header does not exist and @p create is true, creates an empty header
256 and returns it. Otherwise returns 0.
257 Note that the returned header may be empty.
258 @param create Whether to create the header if it does not exist.
259 @since 4.4.
260
261 KDE5: BIC: FIXME: Why is the default argument false here? That is
262 inconsistent with the methods in KMime::Message!
263 */
264 template <typename T> T *header(bool create = false);
265 /**
266 Returns the first header of type @tparam T.
267
268 Can be @c nullptr if such a header doesn't exist.
269 @since 24.08
270 */
271 template <typename T> [[nodiscard]] T *header() const;
272
273 /**
274 Returns all @p type headers in the Content.
275 Take care that this result is not cached, so could be slow.
276 @param type the header type to find
277 @since 4.2
278 */
279 [[nodiscard]] QList<Headers::Base *> headersByType(QByteArrayView type) const;
280
281 /**
282 Sets the specified header to this Content.
283 Any previous header of the same type is removed.
284 If you need multiple headers of the same type, use appendHeader() or
285 prependHeader().
286
287 @param h The header to set.
288 @see appendHeader()
289 @see removeHeader()
290 @since 4.4
291 */
292 void setHeader(Headers::Base *h);
293
294 /**
295 Appends the specified header to the headers of this Content.
296 @param h The header to append.
297 @since 4.4
298 */
299 void appendHeader(Headers::Base *h);
300
301 /**
302 Searches for the first header of type @p type, and deletes it, removing
303 it from this Content.
304 @param type The type of the header to look for.
305 @return true if a header was found and removed.
306 */
307 bool removeHeader(QByteArrayView type);
308
309 /**
310 Searches for the first header of type @p T, and deletes it, removing
311 it from this Content.
312 @tparam T The type of the header to look for.
313 @return true if a header was found and removed.
314 */
315 template <typename T> bool removeHeader();
316
317 /**
318 @return true if this Content has a header of type @p type.
319 @param type The type of the header to look for.
320 */
321 // TODO probably provide hasHeader<T>() too.
322 [[nodiscard]] bool hasHeader(QByteArrayView type) const;
323
324 /**
325 Returns the Content-Type header.
326
327 @param create If true, create the header if it doesn't exist yet.
328 */
329 Headers::ContentType *contentType(bool create = true);
330 /**
331 Returns the Content-Type header.
332
333 Can be @c nullptr if the header doesn't exist.
334 @since 24.08
335 */
336 [[nodiscard]] const Headers::ContentType *contentType() const;
337
338 /**
339 Returns the Content-Transfer-Encoding header.
340
341 @param create If true, create the header if it doesn't exist yet.
342 */
344 /**
345 Returns the Content-Transfer-Encoding header.
346
347 Can be @c nullptr if the header doesn't exist.
348 @since 24.08
349 */
351
352 /**
353 Returns the Content-Disposition header.
354
355 @param create If true, create the header if it doesn't exist yet.
356 */
358 /**
359 Returns the Content-Disposition header.
360
361 Can be @c nullptr if the header doesn't exist.
362 @since 24.08
363 */
365
366 /**
367 Returns the Content-Description header.
368
369 @param create If true, create the header if it doesn't exist yet.
370 */
372 /**
373 Returns the Content-Description header.
374
375 Can be @c nullptr if the header doesn't exist.
376 @since 24.08
377 */
379
380 /**
381 Returns the Content-Location header.
382
383 @param create If true, create the header if it doesn't exist yet.
384 @since 4.2
385 */
387 /**
388 Returns the Content-Location header.
389
390 Can be @c nullptr if the header doesn't exist.
391 @since 24.08
392 */
393 [[nodiscard]] const Headers::ContentLocation *contentLocation() const;
394
395 /**
396 Returns the Content-ID header.
397 @param create if true, create the header if it does not exist yet.
398 @since 4.4
399 */
400 Headers::ContentID *contentID(bool create = true);
401 /**
402 Returns the Content-ID header.
403
404 Can be @c nullptr if the header doesn't exist.
405 @since 24.08
406 */
407 [[nodiscard]] const Headers::ContentID *contentID() const;
408
409 /**
410 Returns the size of the Content body after encoding.
411 (If the encoding is quoted-printable, this is only an approximate size.)
412 This will return 0 for multipart contents or for encapsulated messages.
413 */
414 [[nodiscard]] qsizetype size() const;
415
416 /**
417 Returns the size of this Content and all sub-Contents.
418 */
419 [[nodiscard]] qsizetype storageSize() const;
420
421 /**
422 Returns the Content body raw data.
423
424 Note that this will be empty for multipart contents or for encapsulated
425 messages, after parse() has been called.
426
427 @see setBody().
428 */
429 [[nodiscard]] QByteArray body() const;
430
431 /**
432 Sets the Content decoded body raw data.
433
434 This method operates on the string representation of the Content. Call
435 parse() if you want to access individual sub-Contents or the encapsulated
436 message.
437
438 @param body is a QByteArray containing the body data.
439
440 @note @p body is assumed to be decoded as far as the content transfer encoding
441 is concerned.
442
443 @see setEncodedBody()
444 */
445 void setBody(const QByteArray &body);
446
447 /**
448 Sets the Content body raw data encoded according to the content transfer encoding.
449
450 This method operates on the string representation of the Content. Call
451 parse() if you want to access individual sub-Contents or the encapsulated
452 message.
453
454 @param body is a QByteArray containing the body data.
455
456 @note @p body is assumed to be encoded as far as the content transfer encoding
457 is concerned.
458
459 @since 24.08
460
461 @see setBody()
462 */
463 void setEncodedBody(const QByteArray &body);
464
465 /**
466 Returns the MIME preamble.
467
468 @return a QByteArray containing the MIME preamble.
469
470 @since 4.9
471 */
472 [[nodiscard]] QByteArray preamble() const;
473
474 /**
475 Sets the MIME preamble.
476
477 @param preamble a QByteArray containing what will be used as the
478 MIME preamble.
479
480 @since 4.9
481 */
482
483 void setPreamble(const QByteArray &preamble);
484
485 /**
486 Returns the MIME preamble.
487
488 @return a QByteArray containing the MIME epilogue.
489
490 @since 4.9
491 */
492 [[nodiscard]] QByteArray epilogue() const;
493
494 /**
495 Sets the MIME preamble.
496
497 @param epilogue a QByteArray containing what will be used as the
498 MIME epilogue.
499
500 @since 4.9
501 */
502 void setEpilogue(const QByteArray &epilogue);
503
504 /**
505 Returns a QByteArray containing the encoded Content, including the
506 Content header and all sub-Contents.
507
508 If you make changes to the broken-down representation of the message, be
509 sure to first call assemble() before calling encodedContent(), otherwise
510 the result will not be up-to-date.
511
512 If this content is an encapsulated message, i.e. bodyIsMessage() returns
513 true, then encodedContent() will use the message returned by bodyAsMessage()
514 as the body of the result, calling encodedContent() on the message.
515
516 @param useCrLf If true, use @ref CRLF instead of @ref LF for linefeeds.
517 */
518 [[nodiscard]] QByteArray encodedContent(bool useCrLf = false) const;
519
520 /**
521 * Like encodedContent(), with the difference that only the body will be
522 * returned, i.e. the headers are excluded.
523 *
524 * @since 4.6
525 */
526 [[nodiscard]] QByteArray encodedBody() const;
527
528 /**
529 * Returns the decoded Content body.
530 *
531 * Note that this will be empty for multipart contents or for encapsulated
532 * messages, after parse() has been called.
533 */
534 // TODO: KDE5: BIC: Rename this to decodedBody(), since only the body is
535 // returned. In contrast, setContent() sets the head and the body! Also, try
536 // to make this const.
537 [[nodiscard]] QByteArray decodedContent() const;
538
539 /** Options for Content::decodedText().
540 * @since 24.12
541 */
543 NoTrim, ///< do not trim text content.
544 TrimNewlines, ///< trim trailing newlines
545 TrimSpaces, ///< trim any trailing whitespaces
546 };
547
548 /**
549 Returns the decoded text. Additional to decodedContent(), this also
550 applies charset decoding. If this is not a text Content, decodedText()
551 returns an empty QString.
552
553 @param trimOption Control how to trim trailing white spaces.
554 The last trailing new line of the decoded text is always removed.
555
556 @since 24.12
557 */
558 [[nodiscard]] QString decodedText(DecodedTextTrimOption trimOption = NoTrim) const;
559
560 /**
561 Returns the decoded text. Additional to decodedContent(), this also
562 applies charset decoding. If this is not a text Content, decodedText()
563 returns an empty QString.
564
565 @param trimText If true, then the decoded text will have all trailing
566 whitespace removed.
567 @param removeTrailingNewlines If true, then the decoded text will have
568 all consecutive trailing newlines removed.
569
570 The last trailing new line of the decoded text is always removed.
571
572 @deprecated since 24.12, use decodedText(DecodedTextTrimOption) instead.
573 */
574 [[deprecated("use decodedText(DecodedTextTrimOption) instead")]]
575 [[nodiscard]] inline QString decodedText(bool trimText, bool removeTrailingNewlines = false) const
576 {
577 return decodedText(trimText ? TrimSpaces : removeTrailingNewlines ? TrimNewlines : NoTrim);
578 }
579
580 /**
581 Sets the Content body to the given string using charset of the content type.
582
583 If the charset can not be found, the system charset is taken and the content
584 type header is changed to that charset. The charset of the content type
585 header should be set to a charset that can encode the given string before
586 calling this method.
587
588 This method does not set the content transfer encoding automatically, it
589 needs to be set to a suitable value that can encode the given string before
590 calling this method.
591
592 This method only makes sense for single-part contents, do not try to pass a
593 multipart body or an encapsulated message here, that wouldn't work.
594
595 @param s Unicode-encoded string.
596 */
597 void fromUnicodeString(const QString &s);
598
599 /**
600 Returns the first Content with mimetype text/.
601 */
602 [[nodiscard]] Content *textContent();
603 /**
604 Returns the first Content with MIME type text/.
605 Const overload of the above, the returned Content cannot be modified.
606 @since 24.08
607 */
608 [[nodiscard]] const Content *textContent() const;
609
610 /**
611 * Returns all attachments below this node, recursively.
612 * This does not include crypto parts, nodes of alternative or related
613 * multipart nodes, or the primary body part (see textContent()).
614 * @see KMime::isAttachment(), KMime::hasAttachment()
615 */
616 [[nodiscard]] QList<Content *> attachments();
617 [[nodiscard]] inline auto attachments() const -> auto {
618#ifdef __cpp_lib_ranges_as_const
619 return const_cast<Content*>(this)->attachments() | std::views::transform([](auto c) -> const Content* { return c; }) | std::views::as_const;
620#else
621 return const_cast<Content*>(this)->attachments() | std::views::transform([](auto c) -> const Content* { return c; });
622#endif
623 }
624
625 /**
626 * For multipart contents, this will return a list of all multipart child
627 * contents. For contents that are of mimetype message/rfc822, this will
628 * return a list with one entry, and that entry is the encapsulated message,
629 * as it would be returned by bodyAsMessage().
630 */
631 [[nodiscard]] QList<Content *> contents();
632 [[nodiscard]] inline auto contents() const -> auto {
633#ifdef __cpp_lib_ranges_as_const
634 return const_cast<Content*>(this)->contents() | std::views::transform([](auto c) -> const Content* { return c; }) | std::views::as_const;
635#else
636 return const_cast<Content*>(this)->contents() | std::views::transform([](auto c) -> const Content* { return c; });
637#endif
638 }
639
640 /**
641 Appends a new sub-Content. If the sub-Content is already part of another
642 Content object, it is removed from there and its parent is updated.
643
644 @param content The new sub-Content.
645 @see prependContent()
646 @see takeContent()
647 @since 6.0
648 */
649 void appendContent(Content *content);
650 /**
651 Prepends a new sub-Content. If the sub-Content is already part of another
652 Content object, it is removed from there and its parent is updated.
653
654 @param content The new sub-Content.
655 @see appendContent()
656 @see takeContent()
657 @since 6.0
658 */
659 void prependContent(Content *content);
660
661 void replaceContent(Content *oldContent, Content *newContent);
662 /**
663 Removes the given sub-Content and, if that actually was a sub-content
664 returns that.
665
666 @param content The Content to remove. It is not deleted, ownership goes
667 back to the caller.
668
669 @see appendContent()
670 @see prependContent()
671 @see clearContents()
672 @since 6.0
673 */
674 Content *takeContent(Content *content);
675
676 /**
677 Changes the encoding of this Content to @p e. If the Content is binary,
678 this actually re-encodes the data to use the new encoding.
679
680 @param e The new encoding to use.
681 */
682 void changeEncoding(Headers::contentEncoding e);
683
684 /**
685 Returns the Content specified by the given index.
686 If the index does not point to a Content, 0 is returned. If the index
687 is invalid (empty), this Content is returned.
688
689 @param index The Content index.
690 */
691 [[nodiscard]] Content *content(const ContentIndex &index) const;
692
693 /**
694 Returns the ContentIndex for the given Content, or an invalid index
695 if the Content is not found within the hierarchy.
696 @param content the Content object to search.
697 */
698 [[nodiscard]] ContentIndex indexForContent(Content *content) const;
699
700 /**
701 Returns true if this is the top-level node in the MIME tree. The top-level
702 node is always a Message or NewsArticle. However, a node can be a Message
703 without being a top-level node when it is an encapsulated message.
704 */
705 [[nodiscard]] bool isTopLevel() const;
706
707 /**
708 * Sets a new parent to the Content and add to its contents list. If it
709 * already had a parent, it is removed from the old parents contents list.
710 * @param parent the new parent
711 * @since 4.3
712 */
713 void setParent(Content *parent);
714
715 /**
716 * Returns the parent content object, or 0 if the content doesn't have a
717 * parent.
718 * @since 4.3
719 */
720 [[nodiscard]] Content *parent();
721 [[nodiscard]] const Content *parent() const;
722
723 /**
724 * Returns the toplevel content object, 0 if there is no such object.
725 * @since 4.3
726 */
727 [[nodiscard]] Content *topLevel();
728 [[nodiscard]] const Content *topLevel() const;
729
730
731 /**
732 * Returns the index of this Content based on the topLevel() object.
733 * @since 4.3
734 */
735 [[nodiscard]] ContentIndex index() const;
736
737 /**
738 * @return true if this content is an encapsulated message, i.e. if it has the
739 * mimetype message/rfc822.
740 *
741 * @since 4.5
742 */
743 // AK_REVIEW: move to MessageViewer/ObjectTreeParser
744 [[nodiscard]] bool bodyIsMessage() const;
745
746 /**
747 * If this content is an encapsulated message, in which case bodyIsMessage()
748 * will return true, the message represented by the body of this content will
749 * be returned. The returned message is already fully parsed. Calling this
750 * method is the aquivalent of calling contents().first() and casting the
751 * result to a KMime::Message*. bodyAsMessage() has the advantage that it will
752 * return a shared pointer that will not be destroyed when the container
753 * message is destroyed or re-parsed.
754 *
755 * The message that is returned here is created when calling parse(), so make
756 * sure to call parse() first. Since each parse() creates a new message
757 * object, a different message object will be returned each time you call
758 * parse().
759 *
760 * If you make changes to the returned message, you need to call assemble() on
761 * this content or on the message if you want that encodedContent() reflects
762 * these changes. This also means that calling assemble() on this content will
763 * assemble the returned message.
764 *
765 * @since 4.5
766 */
767 [[nodiscard]] QSharedPointer<Message> bodyAsMessage();
768 [[nodiscard]] inline QSharedPointer<const Message> bodyAsMessage() const
769 {
770 return qSharedPointerCast<const Message>(const_cast<Content*>(this)->bodyAsMessage());
771 }
772
773protected:
774 /**
775 Reimplement this method if you need to assemble additional headers in a
776 derived class. Don't forget to call the implementation of the base class.
777 @return The raw, assembled headers.
778 */
779 virtual QByteArray assembleHeaders();
780
781 //@cond PRIVATE
782 ContentPrivate *d_ptr;
783 //@endcond
784
785private:
786 Q_DECLARE_PRIVATE(Content)
787 Q_DISABLE_COPY(Content)
788};
789
790template <typename T> T *Content::header(bool create)
791{
792 Headers::Base *h = headerByType(T::staticType());
793 if (h) {
794 // Make sure the header is actually of the right type.
795 Q_ASSERT(dynamic_cast<T *>(h));
796 } else if (create) {
797 h = new T;
798 appendHeader(h); // we already know the header doesn't exist yet
799 }
800 return static_cast<T *>(h);
801}
802
803template <typename T> T *Content::header() const
804{
805 Headers::Base *h = headerByType(T::staticType());
806 if (h) {
807 // Make sure the header is actually of the right type.
808 Q_ASSERT(dynamic_cast<T *>(h));
809 }
810 return static_cast<T *>(h);
811}
812
813template <typename T> bool Content::removeHeader()
814{
815 return removeHeader(T::staticType());
816}
817
818} // namespace KMime
819
820Q_DECLARE_METATYPE(KMime::Content*)
821
A class that encapsulates MIME encoded Content.
Definition content.h:92
Headers::ContentDescription * contentDescription(bool create=true)
Returns the Content-Description header.
bool removeHeader()
Searches for the first header of type T, and deletes it, removing it from this Content.
Definition content.h:813
Headers::ContentType * contentType(bool create=true)
Returns the Content-Type header.
QString decodedText(bool trimText, bool removeTrailingNewlines=false) const
Returns the decoded text.
Definition content.h:575
const Headers::ContentType * contentType() const
Returns the Content-Type header.
const Headers::ContentLocation * contentLocation() const
Returns the Content-Location header.
T * header() const
Returns the first header of type.
Definition content.h:803
QList< KMime::Content * > List
Describes a list of Content objects.
Definition content.h:98
Headers::Base * headerByType(QByteArrayView type) const
Returns the first header of type type, if it exists.
Definition content.cpp:568
Headers::ContentTransferEncoding * contentTransferEncoding(bool create=true)
Returns the Content-Transfer-Encoding header.
Headers::ContentDisposition * contentDisposition(bool create=true)
Returns the Content-Disposition header.
const Headers::ContentID * contentID() const
Returns the Content-ID header.
const Headers::ContentTransferEncoding * contentTransferEncoding() const
Returns the Content-Transfer-Encoding header.
Headers::ContentID * contentID(bool create=true)
Returns the Content-ID header.
const Headers::ContentDisposition * contentDisposition() const
Returns the Content-Disposition header.
DecodedTextTrimOption
Options for Content::decodedText().
Definition content.h:542
@ TrimSpaces
trim any trailing whitespaces
Definition content.h:545
@ NoTrim
do not trim text content.
Definition content.h:543
@ TrimNewlines
trim trailing newlines
Definition content.h:544
Headers::ContentLocation * contentLocation(bool create=true)
Returns the Content-Location header.
void appendHeader(Headers::Base *h)
Appends the specified header to the headers of this Content.
Definition content.cpp:599
const Headers::ContentDescription * contentDescription() const
Returns the Content-Description header.
Baseclass of all header-classes.
Definition headers.h:97
Represents a "Content-Description" header.
Definition headers.h:1235
Represents a "Content-Disposition" header.
Definition headers.h:1140
Represents a "Content-ID" header.
Definition headers.h:936
Represents a "Content-Location" header.
Definition headers.h:1244
Represents a "Content-Transfer-Encoding" header.
Definition headers.h:863
Represents a "Content-Type" header.
Definition headers.h:984
This file is part of the API for handling MIME data and defines the ContentIndex class.
This file is part of the API for handling MIME data and defines the various header classes:
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:30:05 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.