~ubuntu-branches/ubuntu/natty/mimetic/natty

« back to all changes in this revision

Viewing changes to mimetic/message.cxx

  • Committer: Bazaar Package Importer
  • Author(s): gregor herrmann
  • Date: 2006-06-16 13:16:07 UTC
  • Revision ID: james.westby@ubuntu.com-20060616131607-245mqjypkjuahq6b
Tags: upstream-0.9.1
ImportĀ upstreamĀ versionĀ 0.9.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
    copyright            : (C) 2002-2005 by Stefano Barbato
 
3
    email                : stefano@codesink.org
 
4
 
 
5
    $Id: message.cxx,v 1.2 2005/02/23 10:26:14 tat Exp $
 
6
 ***************************************************************************/
 
7
 
 
8
/***************************************************************************
 
9
 *                                                                         *
 
10
 *   This program is free software; you can redistribute it and/or modify  *
 
11
 *   it under the terms of the GNU General Public License as published by  *
 
12
 *   the Free Software Foundation; either version 2 of the License, or     *
 
13
 *   (at your option) any later version.                                   *
 
14
 *                                                                         *
 
15
 ***************************************************************************/
 
16
#include <fstream>
 
17
#include <cstdlib>
 
18
#include <mimetic/message.h>
 
19
#include <mimetic/contenttype.h>
 
20
#include <mimetic/utils.h>
 
21
 
 
22
namespace mimetic
 
23
{
 
24
 
 
25
using namespace std;
 
26
Attachment::Attachment(const std::string& fqn)
 
27
{
 
28
    set(fqn, ContentType("application","octect-stream"),Base64::Encoder());
 
29
}
 
30
 
 
31
Attachment::Attachment(const std::string& fqn, const ContentType& ct)
 
32
{
 
33
    set(fqn, ct, Base64::Encoder());
 
34
}
 
35
 
 
36
 
 
37
TextEntity::TextEntity()
 
38
{
 
39
    header().contentType("text/unknown");
 
40
}
 
41
 
 
42
TextEntity::TextEntity(const string& text)
 
43
{
 
44
    m_header.contentType("text/unknown");
 
45
    m_body.assign(text);
 
46
}
 
47
 
 
48
TextEntity::TextEntity(const string& text, const string& charset)
 
49
{
 
50
    ContentType ct("text", "unknown");
 
51
    ct.paramList().push_back(ContentType::Param("charset", charset));
 
52
    m_header.contentType(ct);
 
53
    m_body.assign(text);
 
54
}
 
55
 
 
56
TextPlain::TextPlain(const string& text)
 
57
: TextEntity(text)
 
58
{
 
59
    m_header.contentType("text/plain");
 
60
}
 
61
 
 
62
TextPlain::TextPlain(const string& text, const string& charset)
 
63
: TextEntity(text,charset)
 
64
{
 
65
    m_header.contentType("text/plain");
 
66
}
 
67
 
 
68
 
 
69
TextEnriched::TextEnriched(const string& text)
 
70
: TextEntity(text)
 
71
{
 
72
    m_header.contentType("text/enriched");
 
73
}
 
74
TextEnriched::TextEnriched(const string& text, const string& charset)
 
75
: TextEntity(text,charset)
 
76
{
 
77
    m_header.contentType("text/enriched");
 
78
}
 
79
 
 
80
 
 
81
MultipartEntity::MultipartEntity()
 
82
{
 
83
    ContentType::Boundary boundary;
 
84
    ContentType ct("multipart", "unknown");
 
85
    ct.paramList().push_back(ContentType::Param("boundary", boundary));
 
86
    m_header.contentType(ct);
 
87
}
 
88
 
 
89
MultipartMixed::MultipartMixed()
 
90
{
 
91
    ContentType::Boundary boundary;
 
92
    ContentType ct("multipart", "mixed");
 
93
    ct.paramList().push_back(ContentType::Param("boundary", boundary));
 
94
    m_header.contentType(ct);
 
95
}
 
96
 
 
97
MultipartParallel::MultipartParallel()
 
98
{
 
99
    ContentType::Boundary boundary;
 
100
    ContentType ct("multipart", "parallel");
 
101
    ct.paramList().push_back(ContentType::Param("boundary", boundary));
 
102
    m_header.contentType(ct);
 
103
}
 
104
 
 
105
MultipartAlternative::MultipartAlternative()
 
106
{
 
107
    ContentType::Boundary boundary;
 
108
    ContentType ct("multipart", "alternative");
 
109
    ct.paramList().push_back(ContentType::Param("boundary", boundary));
 
110
    m_header.contentType(ct);
 
111
}
 
112
 
 
113
MultipartDigest::MultipartDigest()
 
114
{
 
115
    ContentType::Boundary boundary;
 
116
    ContentType ct("multipart", "digest");
 
117
    ct.paramList().push_back(ContentType::Param("boundary", boundary));
 
118
    m_header.contentType(ct);
 
119
}
 
120
 
 
121
ApplicationOctStream::ApplicationOctStream()
 
122
{
 
123
    m_header.contentType("application/octet-stream");
 
124
}
 
125
 
 
126
MessageRfc822::MessageRfc822(const MimeEntity& me)
 
127
: m_me(me)
 
128
{
 
129
    m_header.contentType("message/rfc822");
 
130
}
 
131
 
 
132
ostream& MessageRfc822::write(ostream& os,const char* eol) const
 
133
{
 
134
    MimeEntity::write(os);
 
135
    return os << m_me;
 
136
}
 
137
 
 
138
string ApplicationOctStream::type() const
 
139
{
 
140
    return m_header.contentType().param("type");
 
141
}
 
142
 
 
143
void ApplicationOctStream::type(const string& type)
 
144
{
 
145
    ContentType ct = m_header.contentType();
 
146
    ct.param("type",type);
 
147
    m_header.contentType(ct);
 
148
}
 
149
 
 
150
uint ApplicationOctStream::padding() const
 
151
{
 
152
    return utils::str2int(m_header.contentType().param("padding"));
 
153
}
 
154
 
 
155
void ApplicationOctStream::padding(unsigned int n)
 
156
{
 
157
    ContentType ct = m_header.contentType();
 
158
    ct.param("padding", utils::int2str(n));
 
159
    m_header.contentType(ct);
 
160
}
 
161
 
 
162
 
 
163
}