summaryrefslogtreecommitdiff
path: root/libmu_cpp/mime.cc
blob: 97022cbd9c0f2c440b415c2d3d3b76228f042f4c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/* GNU Mailutils -- a suite of utilities for electronic mail
   Copyright (C) 2009-2019 Free Software Foundation, Inc.

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 3 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General
   Public License along with this library.  If not, see
   <http://www.gnu.org/licenses/>. */

#include <mailutils/cpp/mime.h>

using namespace mailutils;

//
// Mime
//

Mime :: Mime (const Message& msg, int flags)
{
  int status = mu_mime_create (&mime, msg.msg, flags);
  if (status)
    throw Exception ("Mime::Mime", status);
}

Mime :: Mime (const mu_mime_t mime)
{
  if (mime == 0)
    throw Exception ("Mime::Mime", EINVAL);

  this->mime = mime;
}

Mime :: ~Mime ()
{
  mu_mime_destroy (&mime);
}

bool
Mime :: is_multipart ()
{
  return (bool) mu_mime_is_multipart (mime);
}

size_t
Mime :: get_num_parts ()
{
  size_t nparts;

  int status = mu_mime_get_num_parts (mime, &nparts);
  if (status)
    throw Exception ("Mime::get_num_parts", status);
  return nparts;
}

Message&
Mime :: get_part (size_t part)
{
  mu_message_t c_msg;

  int status = mu_mime_get_part (mime, part, &c_msg);
  if (status)
    throw Exception ("Mime::get_part", status);

  return *new Message (c_msg);
}

void
Mime :: add_part (const Message& msg)
{
  int status = mu_mime_add_part (mime, msg.msg);
  if (status)
    throw Exception ("Mime::add_part", status);
}

Message&
Mime :: get_message ()
{
  mu_message_t c_msg;

  int status = mu_mime_get_message (mime, &c_msg);
  if (status)
    throw Exception ("Mime::get_message", status);

  return *new Message (c_msg);
}

inline int
rfc2047_decode (const char *tocode, const char *fromstr, char **ptostr)
{
  return mu_rfc2047_decode (tocode, fromstr, ptostr);
}

inline int
rfc2047_encode (const char *charset, const char *encoding, 
		const char *text, char **result)
{
  return mu_rfc2047_encode (charset, encoding, text, result);
}

Return to:

Send suggestions and report system problems to the System administrator.