36 #include "bodypartformatter.h" 37 #include "bodypartformatterfactory_p.h" 38 #include "interfaces/bodypartformatter.h" 40 #include "objecttreeparser.h" 44 #include <mimelib/enum.h> 45 #include <mimelib/string.h> 46 #include <mimelib/utility.h> 49 #include <kasciistricmp.h> 52 class AnyTypeBodyPartFormatter
53 :
public KMail::BodyPartFormatter,
54 public KMail::Interface::BodyPartFormatter {
55 static const AnyTypeBodyPartFormatter *
self;
58 kdDebug(5006) <<
"AnyTypeBodyPartFormatter::format() acting as a KMail::Interface::BodyPartFormatter!" << endl;
62 bool process( KMail::ObjectTreeParser *, partNode *, KMail::ProcessResult & result )
const {
63 result.setNeverDisplayInline(
true );
66 static const KMail::BodyPartFormatter * create() {
68 self =
new AnyTypeBodyPartFormatter();
73 const AnyTypeBodyPartFormatter * AnyTypeBodyPartFormatter::self = 0;
76 class ImageTypeBodyPartFormatter :
public KMail::BodyPartFormatter {
77 static const ImageTypeBodyPartFormatter *
self;
79 bool process( KMail::ObjectTreeParser *, partNode *, KMail::ProcessResult & result )
const {
80 result.setIsImage(
true );
83 static const KMail::BodyPartFormatter * create() {
85 self =
new ImageTypeBodyPartFormatter();
90 const ImageTypeBodyPartFormatter * ImageTypeBodyPartFormatter::self = 0;
92 #define CREATE_BODY_PART_FORMATTER(subtype) \ 93 class subtype##BodyPartFormatter : public KMail::BodyPartFormatter { \ 94 static const subtype##BodyPartFormatter * self; \ 96 bool process( KMail::ObjectTreeParser *, partNode *, KMail::ProcessResult & ) const; \ 97 static const KMail::BodyPartFormatter * create() { \ 99 self = new subtype##BodyPartFormatter(); \ 104 const subtype##BodyPartFormatter * subtype##BodyPartFormatter::self; \ 106 bool subtype##BodyPartFormatter::process( KMail::ObjectTreeParser * otp, partNode * node, KMail::ProcessResult & result ) const { \ 107 return otp->process##subtype##Subtype( node, result ); \ 110 CREATE_BODY_PART_FORMATTER(TextPlain)
111 CREATE_BODY_PART_FORMATTER(TextHtml)
114 CREATE_BODY_PART_FORMATTER(ApplicationOctetStream)
115 CREATE_BODY_PART_FORMATTER(ApplicationPkcs7Mime)
116 CREATE_BODY_PART_FORMATTER(ApplicationChiasmusText)
118 CREATE_BODY_PART_FORMATTER(ApplicationMsTnef)
120 CREATE_BODY_PART_FORMATTER(MessageRfc822)
122 CREATE_BODY_PART_FORMATTER(MultiPartMixed)
123 CREATE_BODY_PART_FORMATTER(MultiPartAlternative)
124 CREATE_BODY_PART_FORMATTER(MultiPartSigned)
125 CREATE_BODY_PART_FORMATTER(MultiPartEncrypted)
127 typedef TextPlainBodyPartFormatter ApplicationPgpBodyPartFormatter;
130 #undef CREATE_BODY_PART_FORMATTER 134 void KMail::BodyPartFormatterFactoryPrivate::kmail_create_builtin_bodypart_formatters( KMail::BodyPartFormatterFactoryPrivate::TypeRegistry * reg ) {
136 (*reg)[
"application"][
"octet-stream"] =
new AnyTypeBodyPartFormatter();
139 typedef const KMail::BodyPartFormatter * (*BodyPartFormatterCreator)();
141 struct SubtypeBuiltin {
142 const char * subtype;
143 BodyPartFormatterCreator create;
146 static const SubtypeBuiltin applicationSubtypeBuiltins[] = {
147 {
"octet-stream", &ApplicationOctetStreamBodyPartFormatter::create },
148 {
"pkcs7-mime", &ApplicationPkcs7MimeBodyPartFormatter::create },
149 {
"x-pkcs7-mime", &ApplicationPkcs7MimeBodyPartFormatter::create },
150 {
"vnd.de.bund.bsi.chiasmus-text", &ApplicationChiasmusTextBodyPartFormatter::create },
151 {
"pgp", &ApplicationPgpBodyPartFormatter::create },
152 {
"ms-tnef", &ApplicationMsTnefBodyPartFormatter::create }
155 static const SubtypeBuiltin textSubtypeBuiltins[] = {
156 {
"html", &TextHtmlBodyPartFormatter::create },
158 {
"x-vcard", &AnyTypeBodyPartFormatter::create },
159 {
"vcard", &AnyTypeBodyPartFormatter::create },
160 {
"rtf", &AnyTypeBodyPartFormatter::create },
161 {
"*", &TextPlainBodyPartFormatter::create },
164 static const SubtypeBuiltin multipartSubtypeBuiltins[] = {
165 {
"mixed", &MultiPartMixedBodyPartFormatter::create },
166 {
"alternative", &MultiPartAlternativeBodyPartFormatter::create },
170 {
"signed", &MultiPartSignedBodyPartFormatter::create },
171 {
"encrypted", &MultiPartEncryptedBodyPartFormatter::create },
175 static const SubtypeBuiltin messageSubtypeBuiltins[] = {
176 {
"rfc822", &MessageRfc822BodyPartFormatter::create },
179 static const SubtypeBuiltin imageSubtypeBuiltins[] = {
180 {
"*", &ImageTypeBodyPartFormatter::create },
183 static const SubtypeBuiltin anySubtypeBuiltins[] = {
184 {
"*", &AnyTypeBodyPartFormatter::create },
190 #define DIM(x) sizeof(x) / sizeof(*x) 192 static const struct {
194 const SubtypeBuiltin * subtypes;
195 unsigned int num_subtypes;
197 {
"application", applicationSubtypeBuiltins, DIM(applicationSubtypeBuiltins) },
198 {
"text", textSubtypeBuiltins, DIM(textSubtypeBuiltins) },
199 {
"multipart", multipartSubtypeBuiltins, DIM(multipartSubtypeBuiltins) },
200 {
"message", messageSubtypeBuiltins, DIM(messageSubtypeBuiltins) },
201 {
"image", imageSubtypeBuiltins, DIM(imageSubtypeBuiltins) },
205 {
"*", anySubtypeBuiltins, DIM(anySubtypeBuiltins) },
210 const KMail::BodyPartFormatter * KMail::BodyPartFormatter::createFor(
int type,
int subtype ) {
212 DwTypeEnumToStr( type, t );
213 DwSubtypeEnumToStr( subtype, st );
214 return createFor( t.c_str(), st.c_str() );
217 static const KMail::BodyPartFormatter * createForText(
const char * subtype ) {
218 if ( subtype && *subtype )
219 switch ( subtype[0] ) {
222 if ( kasciistricmp( subtype,
"html" ) == 0 )
223 return TextHtmlBodyPartFormatter::create();
227 if ( kasciistricmp( subtype,
"rtf" ) == 0 )
228 return AnyTypeBodyPartFormatter::create();
234 if ( kasciistricmp( subtype,
"x-vcard" ) == 0 ||
235 kasciistricmp( subtype,
"vcard" ) == 0 )
236 return AnyTypeBodyPartFormatter::create();
240 return TextPlainBodyPartFormatter::create();
243 static const KMail::BodyPartFormatter * createForImage(
const char * ) {
244 return ImageTypeBodyPartFormatter::create();
247 static const KMail::BodyPartFormatter * createForMessage(
const char * subtype ) {
248 if ( kasciistricmp( subtype,
"rfc822" ) == 0 )
249 return MessageRfc822BodyPartFormatter::create();
250 return AnyTypeBodyPartFormatter::create();
253 static const KMail::BodyPartFormatter * createForMultiPart(
const char * subtype ) {
254 if ( subtype && *subtype )
255 switch ( subtype[0] ) {
258 if ( kasciistricmp( subtype,
"alternative" ) == 0 )
259 return MultiPartAlternativeBodyPartFormatter::create();
263 if ( kasciistricmp( subtype,
"encrypted" ) == 0 )
264 return MultiPartEncryptedBodyPartFormatter::create();
268 if ( kasciistricmp( subtype,
"signed" ) == 0 )
269 return MultiPartSignedBodyPartFormatter::create();
273 return MultiPartMixedBodyPartFormatter::create();
276 static const KMail::BodyPartFormatter * createForApplication(
const char * subtype ) {
277 if ( subtype && *subtype )
278 switch ( subtype[0] ) {
281 if ( kasciistricmp( subtype,
"pgp" ) == 0 )
282 return ApplicationPgpBodyPartFormatter::create();
286 if ( kasciistricmp( subtype,
"pkcs7-mime" ) == 0 ||
287 kasciistricmp( subtype,
"x-pkcs7-mime" ) == 0 )
288 return ApplicationPkcs7MimeBodyPartFormatter::create();
292 if ( kasciistricmp( subtype,
"ms-tnef" ) == 0 )
293 return ApplicationMsTnefBodyPartFormatter::create();
297 if ( kasciistricmp( subtype,
"vnd.de.bund.bsi.chiasmus-text") == 0)
298 return ApplicationChiasmusTextBodyPartFormatter::create();
302 return AnyTypeBodyPartFormatter::create();
306 const KMail::BodyPartFormatter * KMail::BodyPartFormatter::createFor(
const char * type,
const char * subtype ) {
311 if ( kasciistricmp( type,
"application" ) == 0 )
312 return createForApplication( subtype );
316 if ( kasciistricmp( type,
"image" ) == 0 )
317 return createForImage( subtype );
321 if ( kasciistricmp( type,
"multipart" ) == 0 )
322 return createForMultiPart( subtype );
323 else if ( kasciistricmp( type,
"message" ) == 0 )
324 return createForMessage( subtype );
328 if ( kasciistricmp( type,
"text" ) == 0 )
329 return createForText( subtype );
333 return AnyTypeBodyPartFormatter::create();
An interface to HTML sinks.
This class is used for callback hooks needed by bodypart formatter plugins.
interface of message body parts.