Switch to unified view

a b/src/bincimapmime/mime-printdoc.cc
1
/* -*- Mode: c++; -*- */
2
/*  --------------------------------------------------------------------
3
 *  Filename:
4
 *    mime-printdoc.cc
5
 *  
6
 *  Description:
7
 *    Implementation 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
#include "mime.h"
31
#include "mime-utils.h"
32
#include "mime-inputsource.h"
33
#include "convert.h"
34
#include "iodevice.h"
35
#include "iofactory.h"
36
37
#include <string>
38
#include <vector>
39
#include <map>
40
#include <exception>
41
#include <iostream>
42
43
#include <string.h>
44
#include <ctype.h>
45
#include <stdio.h>
46
#include <errno.h>
47
48
using namespace ::std;
49
50
//------------------------------------------------------------------------
51
void Binc::MimePart::printDoc(int fd, IODevice &output,
52
                unsigned int startoffset,
53
                unsigned int length) const
54
{
55
  if (!mimeSource || mimeSource->getFileDescriptor() != fd) {
56
    delete mimeSource;
57
    mimeSource = new MimeInputSource(fd);
58
  }
59
60
  mimeSource->reset();
61
  mimeSource->seek(headerstartoffsetcrlf);
62
63
  char c;
64
  for (unsigned int i = 0; i < length; ++i) {
65
    if (!mimeSource->getChar(&c))
66
      break;
67
68
    output << (char)c;
69
  }
70
}