Switch to unified view

a b/src/bincimapmime/mime.h
1
/* -*- Mode: c++; -*- */
2
/*  --------------------------------------------------------------------
3
 *  Filename:
4
 *    src/parsers/mime/mime.h
5
 *  
6
 *  Description:
7
 *    Declaration of main mime parser components
8
 *  --------------------------------------------------------------------
9
 *  Copyright 2002-2004 Andreas Aardal Hanssen
10
 *
11
 *  This program is free software; you can redistribute it and/or modify
12
 *  it under the terms of the GNU General Public License as published by
13
 *  the Free Software Foundation; either version 2 of the License, or
14
 *  (at your option) any later version.
15
 *
16
 *  This program is distributed in the hope that it will be useful,
17
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 *  GNU General Public License for more details.
20
 *
21
 *  You should have received a copy of the GNU General Public License
22
 *  along with this program; if not, write to the Free Software
23
 *  Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
24
 *  --------------------------------------------------------------------
25
 */
26
#ifdef HAVE_CONFIG_H
27
#include <config.h>
28
#endif
29
30
#ifndef mime_h_included
31
#define mime_h_included
32
#include <string>
33
#include <vector>
34
#include <map>
35
#include <stdio.h>
36
37
namespace Binc {
38
  //---------------------------------------------------------------------- 
39
  class HeaderItem {
40
  private:
41
    mutable std::string key;
42
    mutable std::string value;
43
44
  public:
45
    inline const std::string &getKey(void) const { return key; }
46
    inline const std::string &getValue(void) const { return value; }
47
48
    //--
49
    HeaderItem(void);
50
    HeaderItem(const std::string &key, const std::string &value);
51
  };
52
53
  //---------------------------------------------------------------------- 
54
  class Header {
55
  private:
56
    mutable std::vector<HeaderItem> content;
57
58
  public:
59
    bool getFirstHeader(const std::string &key, HeaderItem &dest) const;
60
    bool getAllHeaders(const std::string &key, std::vector<HeaderItem> &dest) const;
61
    void add(const std::string &name, const std::string &content);
62
    void clear(void) const;
63
64
    //--
65
    Header(void);
66
    ~Header(void);
67
  };
68
69
  //----------------------------------------------------------------------
70
  class IODevice;
71
  class MimeDocument;
72
  class MimePart {
73
  protected:
74
  public:
75
    mutable bool multipart;
76
    mutable bool messagerfc822;
77
    mutable std::string subtype;
78
    mutable std::string boundary;
79
80
    mutable unsigned int headerstartoffsetcrlf;
81
    mutable unsigned int headerlength;
82
83
    mutable unsigned int bodystartoffsetcrlf;
84
    mutable unsigned int bodylength;
85
    mutable unsigned int nlines;
86
    mutable unsigned int nbodylines;
87
    mutable unsigned int size;
88
89
  public:
90
    enum FetchType {
91
      FetchBody,
92
      FetchHeader,
93
      FetchMime
94
    };
95
96
    mutable Header h;
97
98
    mutable std::vector<MimePart> members;
99
100
    inline const std::string &getSubType(void) const { return subtype; }
101
    inline bool isMultipart(void) const { return multipart; }
102
    inline bool isMessageRFC822(void) const { return messagerfc822; }
103
    inline unsigned int getSize(void) const { return bodylength; }
104
    inline unsigned int getNofLines(void) const { return nlines; }
105
    inline unsigned int getNofBodyLines(void) const { return nbodylines; }
106
    inline unsigned int getBodyLength(void) const { return bodylength; }
107
    inline unsigned int getBodyStartOffset(void) const { return bodystartoffsetcrlf; }
108
109
    void printBody(int fd, Binc::IODevice &output, unsigned int startoffset, unsigned int length) const;
110
    void printHeader(int fd, Binc::IODevice &output, std::vector<std::string> headers, bool includeheaders, unsigned int startoffset, unsigned int length, std::string &storage) const;
111
    void printDoc(int fd, Binc::IODevice &output, unsigned int startoffset, unsigned int length) const;
112
    virtual void clear(void) const;
113
114
    const MimePart *getPart(const std::string &findpart, std::string genpart, FetchType fetchType = FetchBody) const;
115
    virtual int parseOnlyHeader(const std::string &toboundary) const;
116
    virtual int parseFull(const std::string &toboundary, int &boundarysize) const;
117
118
    MimePart(void);
119
    virtual ~MimePart(void);
120
  };
121
122
  //----------------------------------------------------------------------
123
  class MimeDocument : public MimePart {
124
  private:
125
    mutable bool headerIsParsed;
126
    mutable bool allIsParsed;
127
128
  public:
129
    void parseOnlyHeader(int fd) const;
130
    void parseFull(int fd) const;
131
    void clear(void) const;
132
    
133
    inline bool isHeaderParsed(void) { return headerIsParsed; }
134
    inline bool isAllParsed(void) { return allIsParsed; }
135
136
    //--
137
    MimeDocument(void);
138
    ~MimeDocument(void);
139
  };
140
141
};
142
143
#endif