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> 
   51  class AnyTypeBodyPartFormatter
 
   52    : 
public KMail::BodyPartFormatter,
 
   53      public KMail::Interface::BodyPartFormatter {
 
   54    static const AnyTypeBodyPartFormatter * self;
 
   57      kdDebug(5006) << 
"AnyTypeBodyPartFormatter::format() acting as a KMail::Interface::BodyPartFormatter!" << endl;
 
   61    bool process( KMail::ObjectTreeParser *, partNode *, KMail::ProcessResult & result )
 const {
 
   62      result.setNeverDisplayInline( 
true );
 
   65    static const KMail::BodyPartFormatter * create() {
 
   67    self = 
new AnyTypeBodyPartFormatter();
 
   72  const AnyTypeBodyPartFormatter * AnyTypeBodyPartFormatter::self = 0;
 
   75  class ImageTypeBodyPartFormatter : 
public KMail::BodyPartFormatter {
 
   76    static const ImageTypeBodyPartFormatter * self;
 
   78    bool process( KMail::ObjectTreeParser *, partNode *, KMail::ProcessResult & result )
 const {
 
   79      result.setIsImage( 
true );
 
   82    static const KMail::BodyPartFormatter * create() {
 
   84    self = 
new ImageTypeBodyPartFormatter();
 
   89  const ImageTypeBodyPartFormatter * ImageTypeBodyPartFormatter::self = 0;
 
   91#define CREATE_BODY_PART_FORMATTER(subtype) \ 
   92  class subtype##BodyPartFormatter : public KMail::BodyPartFormatter { \ 
   93    static const subtype##BodyPartFormatter * self; \ 
   95    bool process( KMail::ObjectTreeParser *, partNode *, KMail::ProcessResult & ) const; \ 
   96    static const KMail::BodyPartFormatter * create() { \ 
   98    self = new subtype##BodyPartFormatter(); \ 
  103  const subtype##BodyPartFormatter * subtype##BodyPartFormatter::self; \ 
  105  bool subtype##BodyPartFormatter::process( KMail::ObjectTreeParser * otp, partNode * node, KMail::ProcessResult & result ) const { \ 
  106    return otp->process##subtype##Subtype( node, result ); \ 
  109  CREATE_BODY_PART_FORMATTER(TextPlain)
 
  110  CREATE_BODY_PART_FORMATTER(TextHtml)
 
  113  CREATE_BODY_PART_FORMATTER(ApplicationOctetStream)
 
  114  CREATE_BODY_PART_FORMATTER(ApplicationPkcs7Mime)
 
  115  CREATE_BODY_PART_FORMATTER(ApplicationChiasmusText)
 
  117  CREATE_BODY_PART_FORMATTER(ApplicationMsTnef)
 
  119  CREATE_BODY_PART_FORMATTER(MessageRfc822)
 
  121  CREATE_BODY_PART_FORMATTER(MultiPartMixed)
 
  122  CREATE_BODY_PART_FORMATTER(MultiPartAlternative)
 
  123  CREATE_BODY_PART_FORMATTER(MultiPartSigned)
 
  124  CREATE_BODY_PART_FORMATTER(MultiPartEncrypted)
 
  126  typedef TextPlainBodyPartFormatter ApplicationPgpBodyPartFormatter;
 
  129#undef CREATE_BODY_PART_FORMATTER 
  133void KMail::BodyPartFormatterFactoryPrivate::kmail_create_builtin_bodypart_formatters( KMail::BodyPartFormatterFactoryPrivate::TypeRegistry * reg ) {
 
  135  (*reg)[
"application"][
"octet-stream"] = 
new AnyTypeBodyPartFormatter();
 
  138typedef const KMail::BodyPartFormatter * (*BodyPartFormatterCreator)();
 
  140struct SubtypeBuiltin {
 
  141  const char * subtype;
 
  142  BodyPartFormatterCreator create;
 
  145static const SubtypeBuiltin applicationSubtypeBuiltins[] = {
 
  146  { 
"octet-stream", &ApplicationOctetStreamBodyPartFormatter::create },
 
  147  { 
"pkcs7-mime", &ApplicationPkcs7MimeBodyPartFormatter::create },
 
  148  { 
"x-pkcs7-mime", &ApplicationPkcs7MimeBodyPartFormatter::create },
 
  149  { 
"vnd.de.bund.bsi.chiasmus-text", &ApplicationChiasmusTextBodyPartFormatter::create },
 
  150  { 
"pgp", &ApplicationPgpBodyPartFormatter::create },
 
  151  { 
"ms-tnef", &ApplicationMsTnefBodyPartFormatter::create }
 
  154static const SubtypeBuiltin textSubtypeBuiltins[] = {
 
  155  { 
"html", &TextHtmlBodyPartFormatter::create },
 
  157  { 
"x-vcard", &AnyTypeBodyPartFormatter::create },
 
  158  { 
"vcard", &AnyTypeBodyPartFormatter::create },
 
  159  { 
"rtf", &AnyTypeBodyPartFormatter::create },
 
  160  { 
"*", &TextPlainBodyPartFormatter::create },
 
  163static const SubtypeBuiltin multipartSubtypeBuiltins[] = {
 
  164  { 
"mixed", &MultiPartMixedBodyPartFormatter::create },
 
  165  { 
"alternative", &MultiPartAlternativeBodyPartFormatter::create },
 
  169  { 
"signed", &MultiPartSignedBodyPartFormatter::create },
 
  170  { 
"encrypted", &MultiPartEncryptedBodyPartFormatter::create },
 
  174static const SubtypeBuiltin messageSubtypeBuiltins[] = {
 
  175  { 
"rfc822", &MessageRfc822BodyPartFormatter::create },
 
  178static const SubtypeBuiltin imageSubtypeBuiltins[] = {
 
  179  { 
"*", &ImageTypeBodyPartFormatter::create },
 
  182static const SubtypeBuiltin anySubtypeBuiltins[] = {
 
  183  { 
"*", &AnyTypeBodyPartFormatter::create },
 
  189#define DIM(x) sizeof(x) / sizeof(*x) 
  193  const SubtypeBuiltin * subtypes;
 
  194  unsigned int num_subtypes;
 
  196  { 
"application", applicationSubtypeBuiltins, DIM(applicationSubtypeBuiltins) },
 
  197  { 
"text", textSubtypeBuiltins, DIM(textSubtypeBuiltins) },
 
  198  { 
"multipart", multipartSubtypeBuiltins, DIM(multipartSubtypeBuiltins) },
 
  199  { 
"message", messageSubtypeBuiltins, DIM(messageSubtypeBuiltins) },
 
  200  { 
"image", imageSubtypeBuiltins, DIM(imageSubtypeBuiltins) },
 
  204  { 
"*", anySubtypeBuiltins, DIM(anySubtypeBuiltins) },
 
  209const KMail::BodyPartFormatter * KMail::BodyPartFormatter::createFor( 
int type, 
int subtype ) {
 
  211  DwTypeEnumToStr( type, t );
 
  212  DwSubtypeEnumToStr( subtype, st );
 
  213  return createFor( t.c_str(), st.c_str() );
 
  216static const KMail::BodyPartFormatter * createForText( 
const char * subtype ) {
 
  217  if ( subtype && *subtype )
 
  218    switch ( subtype[0] ) {
 
  221      if ( kasciistricmp( subtype, 
"html" ) == 0 )
 
  222    return TextHtmlBodyPartFormatter::create();
 
  226      if ( kasciistricmp( subtype, 
"rtf" ) == 0 )
 
  227    return AnyTypeBodyPartFormatter::create();
 
  233      if ( kasciistricmp( subtype, 
"x-vcard" ) == 0 ||
 
  234       kasciistricmp( subtype, 
"vcard" ) == 0 )
 
  235    return AnyTypeBodyPartFormatter::create();
 
  239  return TextPlainBodyPartFormatter::create();
 
  242static const KMail::BodyPartFormatter * createForImage( 
const char * ) {
 
  243  return ImageTypeBodyPartFormatter::create();
 
  246static const KMail::BodyPartFormatter * createForMessage( 
const char * subtype ) {
 
  247  if ( kasciistricmp( subtype, 
"rfc822" ) == 0 )
 
  248    return MessageRfc822BodyPartFormatter::create();
 
  249  return AnyTypeBodyPartFormatter::create();
 
  252static const KMail::BodyPartFormatter * createForMultiPart( 
const char * subtype ) {
 
  253  if ( subtype && *subtype )
 
  254    switch ( subtype[0] ) {
 
  257      if ( kasciistricmp( subtype, 
"alternative" ) == 0 )
 
  258    return MultiPartAlternativeBodyPartFormatter::create();
 
  262      if ( kasciistricmp( subtype, 
"encrypted" ) == 0 )
 
  263    return MultiPartEncryptedBodyPartFormatter::create();
 
  267      if ( kasciistricmp( subtype, 
"signed" ) == 0 )
 
  268    return MultiPartSignedBodyPartFormatter::create();
 
  272  return MultiPartMixedBodyPartFormatter::create();
 
  275static const KMail::BodyPartFormatter * createForApplication( 
const char * subtype ) {
 
  276  if ( subtype && *subtype )
 
  277    switch ( subtype[0] ) {
 
  280      if ( kasciistricmp( subtype, 
"pgp" ) == 0 )
 
  281    return ApplicationPgpBodyPartFormatter::create();
 
  285      if ( kasciistricmp( subtype, 
"pkcs7-mime" ) == 0 ||
 
  286       kasciistricmp( subtype, 
"x-pkcs7-mime" ) == 0 )
 
  287    return ApplicationPkcs7MimeBodyPartFormatter::create();
 
  291      if ( kasciistricmp( subtype, 
"ms-tnef" ) == 0 )
 
  292        return ApplicationMsTnefBodyPartFormatter::create();
 
  296      if ( kasciistricmp( subtype, 
"vnd.de.bund.bsi.chiasmus-text") == 0)
 
  297        return ApplicationChiasmusTextBodyPartFormatter::create();
 
  301  return AnyTypeBodyPartFormatter::create();
 
  305const KMail::BodyPartFormatter * KMail::BodyPartFormatter::createFor( 
const char * type, 
const char * subtype ) {
 
  310      if ( kasciistricmp( type, 
"application" ) == 0 )
 
  311    return createForApplication( subtype );
 
  315      if ( kasciistricmp( type, 
"image" ) == 0 )
 
  316    return createForImage( subtype );
 
  320      if ( kasciistricmp( type, 
"multipart" ) == 0 )
 
  321    return createForMultiPart( subtype );
 
  322      else if ( kasciistricmp( type, 
"message" ) == 0 )
 
  323    return createForMessage( subtype );
 
  327      if ( kasciistricmp( type, 
"text" ) == 0 )
 
  328    return createForText( subtype );
 
  332  return AnyTypeBodyPartFormatter::create();
 
This class is used for callback hooks needed by bodypart formatter plugins.
 
An interface to HTML sinks.
 
interface of message body parts.