mirror of https://github.com/djcb/mu.git
* mu-msg-contact.[ch]: add _new, _destroy functions
This commit is contained in:
parent
7f3ac08ad0
commit
5f84cb5025
|
@ -30,6 +30,37 @@
|
|||
#include "mu-msg-contact.h"
|
||||
#include "mu-util.h"
|
||||
|
||||
|
||||
MuMsgContact *
|
||||
mu_msg_contact_new (const char *name, const char *address,
|
||||
MuMsgContactType type)
|
||||
{
|
||||
MuMsgContact *contact;
|
||||
|
||||
g_return_val_if_fail (name, NULL);
|
||||
g_return_val_if_fail (address, NULL);
|
||||
g_return_val_if_fail (!mu_msg_contact_type_is_valid(type),
|
||||
NULL);
|
||||
|
||||
contact = g_slice_new (MuMsgContact);
|
||||
|
||||
contact->name = g_strdup(name);
|
||||
contact->address = g_strdup(address);
|
||||
contact->type = type;
|
||||
|
||||
return contact;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
mu_msg_contact_destroy (MuMsgContact *contacts)
|
||||
{
|
||||
if (contacts) {
|
||||
g_free ((gchar*)contacts->name);
|
||||
g_free ((gchar*)contacts->address);
|
||||
g_slice_free (MuMsgContact, contacts);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static gboolean
|
||||
|
|
|
@ -26,21 +26,48 @@
|
|||
G_BEGIN_DECLS
|
||||
|
||||
enum _MuMsgContactType { /* Reply-To:? */
|
||||
MU_MSG_CONTACT_TYPE_TO,
|
||||
MU_MSG_CONTACT_TYPE_TO = 0,
|
||||
MU_MSG_CONTACT_TYPE_FROM,
|
||||
MU_MSG_CONTACT_TYPE_CC,
|
||||
MU_MSG_CONTACT_TYPE_BCC
|
||||
MU_MSG_CONTACT_TYPE_BCC,
|
||||
|
||||
MU_MSG_CONTACT_TYPE_NUM
|
||||
};
|
||||
typedef enum _MuMsgContactType MuMsgContactType;
|
||||
typedef guint MuMsgContactType;
|
||||
|
||||
#define mu_msg_contact_type_is_valid(MCT)\
|
||||
((MCT) < MU_MSG_CONTACT_TYPE_NUM)
|
||||
|
||||
struct _MuMsgContact {
|
||||
const char *name; /* Foo Bar */
|
||||
const char *address; /* foo@bar.cuux */
|
||||
MuMsgContactType type; /*MU_MSG_CONTACT_TYPE_{TO,CC,BCC,FROM}*/
|
||||
MuMsgContactType type; /*MU_MSG_CONTACT_TYPE_{ TO,
|
||||
* CC, BCC, FROM}*/
|
||||
};
|
||||
typedef struct _MuMsgContact MuMsgContact;
|
||||
|
||||
/**
|
||||
* create a new MuMsgContact object; note, in many case, this is not
|
||||
* needed, any a stack-allocated struct can be uses.
|
||||
*
|
||||
* @param name the name of the contact
|
||||
* @param address the e-mail address of the contact
|
||||
* @param type the type of contact: cc, bcc, from, to
|
||||
*
|
||||
* @return a newly allocated MuMsgConcact or NULL in case of
|
||||
* error. use mu_msg_contact_destroy to destroy it when it's no longer
|
||||
* needed.
|
||||
*/
|
||||
MuMsgContact *mu_msg_contact_new (const char *name, const char *address,
|
||||
MuMsgContactType type);
|
||||
|
||||
/**
|
||||
* destroy a MuMsgConcact object
|
||||
*
|
||||
* @param contact a contact object, or NULL
|
||||
*/
|
||||
void mu_msg_contact_destroy (MuMsgContact *contact);
|
||||
|
||||
/**
|
||||
* macro to get the name of a contact
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue