Switch to unified view

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