~ubuntu-branches/ubuntu/karmic/libtinymail/karmic

« back to all changes in this revision

Viewing changes to libtinymail-camel/camel-lite/camel/camel-multipart-encrypted.c

  • Committer: Bazaar Package Importer
  • Author(s): Steve Kowalik
  • Date: 2007-10-12 11:21:12 UTC
  • Revision ID: james.westby@ubuntu.com-20071012112112-fod9fs7yrooxjr7i
Tags: upstream-0.0.2
ImportĀ upstreamĀ versionĀ 0.0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
 
2
/*
 
3
 *  Authors: Jeffrey Stedfast <fejj@ximian.com>
 
4
 *
 
5
 *  Copyright 2002 Ximian, Inc. (www.ximian.com)
 
6
 *
 
7
 *  This program is free software; you can redistribute it and/or modify
 
8
 *  it under the terms of the GNU Lesser General Public License as published by
 
9
 *  the Free Software Foundation; either version 2 of the License, or
 
10
 *  (at your option) any later version.
 
11
 *
 
12
 *  This program is distributed in the hope that it will be useful,
 
13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
 *  GNU Lesser General Public License for more details.
 
16
 *
 
17
 *  You should have received a copy of the GNU Lesser General Public License
 
18
 *  along with this program; if not, write to the Free Software
 
19
 *  Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
 
20
 *
 
21
 */
 
22
 
 
23
 
 
24
#ifdef HAVE_CONFIG_H
 
25
#include <config.h>
 
26
#endif
 
27
 
 
28
#include <stdio.h>
 
29
#include <string.h>
 
30
 
 
31
#include <glib.h>
 
32
#include <glib/gi18n-lib.h>
 
33
 
 
34
#include "camel-mime-filter-crlf.h"
 
35
#include "camel-mime-part.h"
 
36
#include "camel-mime-utils.h"
 
37
#include "camel-multipart-encrypted.h"
 
38
#include "camel-stream-filter.h"
 
39
#include "camel-stream-fs.h"
 
40
#include "camel-stream-mem.h"
 
41
 
 
42
static void camel_multipart_encrypted_class_init (CamelMultipartEncryptedClass *klass);
 
43
static void camel_multipart_encrypted_init (gpointer object, gpointer klass);
 
44
static void camel_multipart_encrypted_finalize (CamelObject *object);
 
45
 
 
46
static void set_mime_type_field (CamelDataWrapper *data_wrapper, CamelContentType *mime_type);
 
47
 
 
48
 
 
49
static CamelMultipartClass *parent_class = NULL;
 
50
 
 
51
 
 
52
CamelType
 
53
camel_multipart_encrypted_get_type (void)
 
54
{
 
55
        static CamelType type = CAMEL_INVALID_TYPE;
 
56
        
 
57
        if (type == CAMEL_INVALID_TYPE) {
 
58
                type = camel_type_register (camel_multipart_get_type (),
 
59
                                            "CamelMultipartEncrypted",
 
60
                                            sizeof (CamelMultipartEncrypted),
 
61
                                            sizeof (CamelMultipartEncryptedClass),
 
62
                                            (CamelObjectClassInitFunc) camel_multipart_encrypted_class_init,
 
63
                                            NULL,
 
64
                                            (CamelObjectInitFunc) camel_multipart_encrypted_init,
 
65
                                            (CamelObjectFinalizeFunc) camel_multipart_encrypted_finalize);
 
66
        }
 
67
        
 
68
        return type;
 
69
}
 
70
 
 
71
 
 
72
static void
 
73
camel_multipart_encrypted_class_init (CamelMultipartEncryptedClass *klass)
 
74
{
 
75
        CamelDataWrapperClass *camel_data_wrapper_class = CAMEL_DATA_WRAPPER_CLASS (klass);
 
76
        
 
77
        parent_class = (CamelMultipartClass *) camel_multipart_get_type ();
 
78
        
 
79
        /* virtual method overload */
 
80
        camel_data_wrapper_class->set_mime_type_field = set_mime_type_field;
 
81
}
 
82
 
 
83
static void
 
84
camel_multipart_encrypted_init (gpointer object, gpointer klass)
 
85
{
 
86
        CamelMultipartEncrypted *multipart = (CamelMultipartEncrypted *) object;
 
87
        
 
88
        camel_data_wrapper_set_mime_type (CAMEL_DATA_WRAPPER (multipart), "multipart/encrypted");
 
89
        
 
90
        multipart->decrypted = NULL;
 
91
}
 
92
 
 
93
static void
 
94
camel_multipart_encrypted_finalize (CamelObject *object)
 
95
{
 
96
        CamelMultipartEncrypted *mpe = (CamelMultipartEncrypted *) object;
 
97
        
 
98
        g_free (mpe->protocol);
 
99
        
 
100
        if (mpe->decrypted)
 
101
                camel_object_unref (mpe->decrypted);
 
102
}
 
103
 
 
104
/* we snoop the mime type to get the protocol */
 
105
static void
 
106
set_mime_type_field (CamelDataWrapper *data_wrapper, CamelContentType *mime_type)
 
107
{
 
108
        CamelMultipartEncrypted *mpe = (CamelMultipartEncrypted *) data_wrapper;
 
109
        
 
110
        if (mime_type) {
 
111
                const char *protocol;
 
112
                
 
113
                protocol = camel_content_type_param (mime_type, "protocol");
 
114
                g_free (mpe->protocol);
 
115
                mpe->protocol = g_strdup (protocol);
 
116
        }
 
117
        
 
118
        ((CamelDataWrapperClass *) parent_class)->set_mime_type_field (data_wrapper, mime_type);
 
119
}
 
120
 
 
121
 
 
122
/**
 
123
 * camel_multipart_encrypted_new:
 
124
 *
 
125
 * Create a new #CamelMultipartEncrypted object.
 
126
 *
 
127
 * A MultipartEncrypted should be used to store and create parts of
 
128
 * type "multipart/encrypted".
 
129
 *
 
130
 * Returns a new #CamelMultipartEncrypted object
 
131
 **/
 
132
CamelMultipartEncrypted *
 
133
camel_multipart_encrypted_new (void)
 
134
{
 
135
        CamelMultipartEncrypted *multipart;
 
136
        
 
137
        multipart = (CamelMultipartEncrypted *) camel_object_new (CAMEL_MULTIPART_ENCRYPTED_TYPE);
 
138
        
 
139
        return multipart;
 
140
}