1 | /* |
2 | kmime_message.cpp |
3 | |
4 | KMime, the KDE Internet mail/usenet news message library. |
5 | Copyright (c) 2001 the KMime authors. |
6 | See file AUTHORS for details |
7 | |
8 | This library is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU Library General Public |
10 | License as published by the Free Software Foundation; either |
11 | version 2 of the License, or (at your option) any later version. |
12 | |
13 | This library is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16 | Library General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU Library General Public License |
19 | along with this library; see the file COPYING.LIB. If not, write to |
20 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
21 | Boston, MA 02110-1301, USA. |
22 | */ |
23 | |
24 | #include "kmime_message.h" |
25 | #include "kmime_message_p.h" |
26 | #include "kmime_util_p.h" |
27 | |
28 | #include <KGlobal> |
29 | |
30 | using namespace KMime; |
31 | |
32 | namespace KMime { |
33 | |
34 | Message::Message() |
35 | : Content( new MessagePrivate( this ) ) |
36 | { |
37 | } |
38 | |
39 | Message::Message(MessagePrivate * d) |
40 | : Content( d ) |
41 | { |
42 | } |
43 | |
44 | Message::~Message() |
45 | { |
46 | } |
47 | |
48 | void Message::parse() |
49 | { |
50 | // KDE5: remove this virtual reimplementation. |
51 | Content::parse(); |
52 | } |
53 | |
54 | QByteArray Message::() |
55 | { |
56 | // Create the mandatory fields (RFC5322) if they do not exist already. |
57 | date( true ); |
58 | from( true ); |
59 | |
60 | // Make sure the mandatory MIME-Version field (RFC2045) is present and valid. |
61 | Headers::MIMEVersion *mimeVersion = header<Headers::MIMEVersion>( true ); |
62 | mimeVersion->from7BitString( "1.0" ); |
63 | |
64 | // Assemble all header fields. |
65 | return Content::assembleHeaders(); |
66 | } |
67 | |
68 | void Message::clear() |
69 | { |
70 | // KDE5: remove this virtual reimplementation. |
71 | Content::clear(); |
72 | } |
73 | |
74 | Headers::Base *Message::( const char *type ) |
75 | { |
76 | // KDE5: remove this virtual reimplementation. |
77 | return headerByType( type ); |
78 | } |
79 | |
80 | Headers::Base *Message::( const char *type ) |
81 | { |
82 | // KDE5: remove this virtual reimplementation. |
83 | return Content::headerByType( type ); |
84 | } |
85 | |
86 | void Message::( Headers::Base *h ) |
87 | { |
88 | // KDE5: remove this virtual reimplementation. |
89 | Content::setHeader( h ); |
90 | } |
91 | |
92 | bool Message::( const char *type ) |
93 | { |
94 | // KDE5: remove this virtual reimplementation. |
95 | return Content::removeHeader( type ); |
96 | } |
97 | |
98 | bool Message::isTopLevel() const |
99 | { |
100 | return Content::isTopLevel(); |
101 | } |
102 | |
103 | Content *Message::mainBodyPart( const QByteArray &type ) |
104 | { |
105 | KMime::Content *c = this; |
106 | while ( c ) { |
107 | // not a multipart message |
108 | const KMime::Headers::ContentType * const contentType = c->contentType(); |
109 | if ( !contentType->isMultipart() ) { |
110 | if ( contentType->mimeType() == type || type.isEmpty() ) { |
111 | return c; |
112 | } |
113 | return 0; |
114 | } |
115 | |
116 | // empty multipart |
117 | if ( c->contents().count() == 0 ) { |
118 | return 0; |
119 | } |
120 | |
121 | // multipart/alternative |
122 | if ( contentType->subType() == "alternative" ) { |
123 | if ( type.isEmpty() ) { |
124 | return c->contents().first(); |
125 | } |
126 | foreach ( Content *c1, c->contents() ) { |
127 | if ( c1->contentType()->mimeType() == type ) { |
128 | return c1; |
129 | } |
130 | } |
131 | return 0; |
132 | } |
133 | |
134 | c = c->contents().first(); |
135 | } |
136 | |
137 | return 0; |
138 | } |
139 | |
140 | QString Message::mimeType() |
141 | { |
142 | static const QString &message_rfc822 = KGlobal::staticQString( QLatin1String( "message/rfc822" ) ); |
143 | return message_rfc822; |
144 | } |
145 | |
146 | |
147 | // @cond PRIVATE |
148 | #define kmime_mk_header_accessor( type, method ) \ |
149 | Headers::type *Message::method( bool create ) { \ |
150 | return header<Headers::type>( create ); \ |
151 | } |
152 | |
153 | kmime_mk_header_accessor( MessageID, messageID ) |
154 | kmime_mk_header_accessor( Subject, subject ) |
155 | kmime_mk_header_accessor( Date, date ) |
156 | kmime_mk_header_accessor( Organization, organization ) |
157 | kmime_mk_header_accessor( From, from ) |
158 | kmime_mk_header_accessor( ReplyTo, replyTo ) |
159 | kmime_mk_header_accessor( To, to ) |
160 | kmime_mk_header_accessor( Cc, cc ) |
161 | kmime_mk_header_accessor( Bcc, bcc ) |
162 | kmime_mk_header_accessor( References, references ) |
163 | kmime_mk_header_accessor( UserAgent, userAgent ) |
164 | kmime_mk_header_accessor( InReplyTo, inReplyTo ) |
165 | kmime_mk_header_accessor( Sender, sender ) |
166 | |
167 | #undef kmime_mk_header_accessor |
168 | // @endcond |
169 | |
170 | } |
171 | |
172 | |