summaryrefslogtreecommitdiff
path: root/src/mu-msg-data.c
blob: d57744bc04ae2e19efb84ac12b1f066e4ed65ab4 (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
/*
** Copyright (C) 2011 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
**
** This program is free software; you can redistribute it and/or modify it
** under the terms of the GNU General Public License as published by the
** Free Software Foundation; either version 3, or (at your option) any
** later version.
**
** This program 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 General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software Foundation,
** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**
*/

#include <string.h> /* for memcpy */
#include "mu-msg-data.h"


MuMsgData*
mu_msg_data_new (void)
{
	/* TODO: check if this is much slower than g_slice_new */
	return g_slice_new0 (MuMsgData);
}

MuMsgData*
mu_msg_data_copy (MuMsgData *mdata)
{
	MuMsgData *copy;
	
	if (!mdata)
		return NULL;
	
	copy = mu_msg_data_new ();

	/* shallow copy */
	memcpy (copy, mdata, sizeof(MuMsgData));

	/* now, deep copy ptr data */
	copy->cc      = g_strdup (mdata->cc);
	copy->from    = g_strdup (mdata->from);
	copy->maildir = g_strdup (mdata->maildir);
	copy->msgid   = g_strdup (mdata->msgid);
	copy->path    = g_strdup (mdata->path);
	copy->subject = g_strdup (mdata->subject);
	copy->to      = g_strdup (mdata->to);

	return copy;
}

void
mu_msg_data_destroy (MuMsgData *mdata)
{
	if (!mdata)
		return;

	g_free (mdata->cc);
	g_free (mdata->from);
	g_free (mdata->maildir);
	g_free (mdata->msgid);
	g_free (mdata->path);
	g_free (mdata->subject);
	g_free (mdata->to);

	g_slice_free (MuMsgData, mdata);
}