vfs: check userland buffers before reading them.
[haiku.git] / headers / os / mail / MailComponent.h
blob4b08a33a2a7c8671fdfc3054261152f5b3b9ead2
1 /*
2 * Copyright 2001-2003 Dr. Zoidberg Enterprises. All rights reserved.
3 * Copyright 2004-2017, Haiku, Inc. All rights reserved.
4 * Distributed under the terms of the MIT License.
5 */
6 #ifndef _MAIL_COMPONENT_H
7 #define _MAIL_COMPONENT_H
10 #include <UTF8.h>
11 #include <Message.h>
12 #include <String.h>
14 #include <mail_encoding.h>
17 class BMimeType;
19 extern const char* kHeaderCharsetString;
20 extern const char* kHeaderEncodingString;
21 // Special field names in the headers which specify the character set (int32)
22 // and encoding (int8) to use when converting the headers from UTF-8 to the
23 // output e-mail format (rfc2047). For use with SetHeaderField when you pass
24 // it a structured header in a BMessage.
27 enum component_type {
28 B_MAIL_PLAIN_TEXT_BODY = 0,
29 B_MAIL_SIMPLE_ATTACHMENT,
30 B_MAIL_ATTRIBUTED_ATTACHMENT,
31 B_MAIL_MULTIPART_CONTAINER
35 class BMailComponent {
36 public:
37 BMailComponent(
38 uint32 defaultCharSet = B_MAIL_NULL_CONVERSION);
39 virtual ~BMailComponent();
41 uint32 ComponentType();
42 BMailComponent* WhatIsThis();
43 bool IsAttachment();
45 void SetHeaderField(const char *key,
46 const char *value,
47 uint32 charset = B_MAIL_NULL_CONVERSION,
48 mail_encoding encoding = null_encoding,
49 bool replace_existing = true);
50 void SetHeaderField(const char *key,
51 BMessage *structured_header,
52 bool replace_existing = true);
54 const char* HeaderAt(int32 index) const;
55 const char* HeaderField(const char *key,
56 int32 index = 0) const;
57 status_t HeaderField(const char *key,
58 BMessage *structured_header,
59 int32 index = 0) const;
61 status_t RemoveHeader(const char *key);
63 virtual status_t GetDecodedData(BPositionIO *data);
64 virtual status_t SetDecodedData(BPositionIO *data);
66 virtual status_t SetToRFC822(BPositionIO *data, size_t length,
67 bool parse_now = false);
68 virtual status_t RenderToRFC822(BPositionIO *render_to);
70 virtual status_t MIMEType(BMimeType *mime);
72 protected:
73 uint32 _charSetForTextDecoding;
74 // This is the character set to be used for decoding text
75 // components, or if it is B_MAIL_NULL_CONVERSION then the character
76 // set will be determined automatically. Since we can't use a
77 // global variable (different messages might have different values
78 // of this), and since sub-components can't find their parents,
79 // this is passed down during construction to some (just Component,
80 // Container, Message, MIME, Text) child components and ends up
81 // being used in the text components.
83 private:
84 virtual void _ReservedComponent1();
85 virtual void _ReservedComponent2();
86 virtual void _ReservedComponent3();
87 virtual void _ReservedComponent4();
88 virtual void _ReservedComponent5();
90 BMessage headers;
92 uint32 _reserved[5];
96 class BTextMailComponent : public BMailComponent {
97 public:
98 BTextMailComponent(const char *text = NULL, uint32 defaultCharSet = B_MAIL_NULL_CONVERSION);
99 virtual ~BTextMailComponent();
101 void SetEncoding(mail_encoding encoding, int32 charset);
102 // encoding: you should always use quoted_printable, base64 is strongly not
103 // recommended, see rfc 2047 for the reasons why
104 // charset: use Conversion flavor constants from UTF8.h
106 void SetText(const char *text);
107 void AppendText(const char *text);
109 const char *Text();
110 BString *BStringText();
112 void Quote(const char *message = NULL,
113 const char *quote_style = "> ");
115 virtual status_t GetDecodedData(BPositionIO *data);
116 virtual status_t SetDecodedData(BPositionIO *data);
118 virtual status_t SetToRFC822(BPositionIO *data, size_t length, bool parse_now = false);
119 virtual status_t RenderToRFC822(BPositionIO *render_to);
121 private:
122 virtual void _ReservedText1();
123 virtual void _ReservedText2();
125 BString text;
126 BString decoded;
128 mail_encoding encoding;
129 uint32 charset; // This character set is used for encoding, not decoding.
131 status_t ParseRaw();
132 BPositionIO *raw_data;
133 size_t raw_length;
134 off_t raw_offset;
136 uint32 _reserved[5];
139 #endif // _MAIL_COMPONENT_H