Switch to unified view

a/src/internfile/mimehandler.cpp b/src/internfile/mimehandler.cpp
1
#ifndef lint
1
#ifndef lint
2
static char rcsid[] = "@(#$Id: mimehandler.cpp,v 1.19 2006-12-13 09:13:18 dockes Exp $ (C) 2004 J.F.Dockes";
2
static char rcsid[] = "@(#$Id: mimehandler.cpp,v 1.20 2006-12-15 12:40:02 dockes Exp $ (C) 2004 J.F.Dockes";
3
#endif
3
#endif
4
/*
4
/*
5
 *   This program is free software; you can redistribute it and/or modify
5
 *   This program is free software; you can redistribute it and/or modify
6
 *   it under the terms of the GNU General Public License as published by
6
 *   it under the terms of the GNU General Public License as published by
7
 *   the Free Software Foundation; either version 2 of the License, or
7
 *   the Free Software Foundation; either version 2 of the License, or
...
...
18
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19
 */
19
 */
20
20
21
#include <iostream>
21
#include <iostream>
22
#include <string>
22
#include <string>
23
#ifndef NO_NAMESPACES
23
24
using namespace std;
24
using namespace std;
25
#endif /* NO_NAMESPACES */
26
25
27
#include "mimehandler.h"
26
#include "mimehandler.h"
28
#include "debuglog.h"
27
#include "debuglog.h"
28
#include "rclconfig.h"
29
#include "smallut.h"
29
#include "smallut.h"
30
31
#include "mh_exec.h"
30
#include "mh_html.h"
32
#include "mh_html.h"
31
#include "mh_mail.h"
33
#include "mh_mail.h"
34
#include "mh_mbox.h"
32
#include "mh_text.h"
35
#include "mh_text.h"
33
#include "mh_exec.h"
34
#include "mh_unknown.h"
36
#include "mh_unknown.h"
35
  
37
  
36
/** Create internal handler object appropriate for given mime type */
38
/** Create internal handler object appropriate for given mime type */
37
static MimeHandler *mhFactory(const string &mime)
39
static Dijon::Filter *mhFactory(const string &mime)
38
{
40
{
39
    if (!stringlowercmp("text/plain", mime))
41
    if (!stringlowercmp("text/plain", mime))
40
    return new MimeHandlerText;
42
    return new MimeHandlerText("text/plain");
41
    else if (!stringlowercmp("text/html", mime))
43
    else if (!stringlowercmp("text/html", mime))
42
    return new MimeHandlerHtml;
44
    return new MimeHandlerHtml("text/html");
43
    else if (!stringlowercmp("text/x-mail", mime))
45
    else if (!stringlowercmp("text/x-mail", mime))
44
    return new MimeHandlerMail;
46
    return new MimeHandlerMbox("text/x-mail");
45
    else if (!stringlowercmp("message/rfc822", mime))
47
    else if (!stringlowercmp("message/rfc822", mime))
46
    return new MimeHandlerMail;
48
    return new MimeHandlerMail("message/rfc822");
47
    return 0;
49
    else 
50
  return new MimeHandlerUnknown("application/octet-stream");
48
}
51
}
49
52
50
/**
53
/**
51
 * Return handler object for given mime type:
54
 * Return handler object for given mime type:
52
 */
55
 */
53
MimeHandler *getMimeHandler(const string &mtype, RclConfig *cfg)
56
Dijon::Filter *getMimeHandler(const string &mtype, RclConfig *cfg)
54
{
57
{
55
    // Get handler definition for mime type
58
    // Get handler definition for mime type
56
    string hs;
59
    string hs;
57
    if (!mtype.empty())
60
    if (!mtype.empty())
58
    hs = cfg->getMimeHandlerDef(mtype);
61
    hs = cfg->getMimeHandlerDef(mtype);
...
...
76
        if (toks.size() < 2) {
79
        if (toks.size() < 2) {
77
        LOGERR(("getMimeHandler: bad line for %s: %s\n", 
80
        LOGERR(("getMimeHandler: bad line for %s: %s\n", 
78
            mtype.c_str(), hs.c_str()));
81
            mtype.c_str(), hs.c_str()));
79
        return 0;
82
        return 0;
80
        }
83
        }
81
        MimeHandlerExec *h = new MimeHandlerExec;
84
        MimeHandlerExec *h = new MimeHandlerExec(mtype.c_str());
82
        it++;
85
        it++;
83
        h->params.push_back(cfg->findFilter(*it++));
86
        h->params.push_back(cfg->findFilter(*it++));
84
        h->params.insert(h->params.end(), it, toks.end());
87
        h->params.insert(h->params.end(), it, toks.end());
85
        return h;
88
        return h;
86
    }
89
    }
...
...
91
    // associated. These files are either ignored or their name is
94
    // associated. These files are either ignored or their name is
92
    // indexed, depending on configuration
95
    // indexed, depending on configuration
93
    bool indexunknown = false;
96
    bool indexunknown = false;
94
    cfg->getConfParam("indexallfilenames", &indexunknown);
97
    cfg->getConfParam("indexallfilenames", &indexunknown);
95
    if (indexunknown) {
98
    if (indexunknown) {
96
  return new MimeHandlerUnknown;
99
  LOGDEB(("getMimeHandler: returning MimeHandlerUnknown\n"));
100
  return new MimeHandlerUnknown("application/octet-stream");
97
    } else {
101
    } else {
98
    return 0;
102
    return 0;
99
    }
103
    }
100
}
104
}
101
105