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.
6 #ifndef _MAIL_COMPONENT_H
7 #define _MAIL_COMPONENT_H
14 #include <mail_encoding.h>
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.
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
{
38 uint32 defaultCharSet
= B_MAIL_NULL_CONVERSION
);
39 virtual ~BMailComponent();
41 uint32
ComponentType();
42 BMailComponent
* WhatIsThis();
45 void SetHeaderField(const char *key
,
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
);
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.
84 virtual void _ReservedComponent1();
85 virtual void _ReservedComponent2();
86 virtual void _ReservedComponent3();
87 virtual void _ReservedComponent4();
88 virtual void _ReservedComponent5();
96 class BTextMailComponent
: public BMailComponent
{
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
);
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
);
122 virtual void _ReservedText1();
123 virtual void _ReservedText2();
128 mail_encoding encoding
;
129 uint32 charset
; // This character set is used for encoding, not decoding.
132 BPositionIO
*raw_data
;
139 #endif // _MAIL_COMPONENT_H