/* Generated by GOB (v2.0.15)   (do not edit directly) */

/* End world hunger, donate to the World Food Programme, http://www.wfp.org */

#define GOB_VERSION_MAJOR 2
#define GOB_VERSION_MINOR 0
#define GOB_VERSION_PATCHLEVEL 15

#define selfp (self->_priv)

#include <string.h> /* memset() */

#include "mn-mozilla-mailbox-backend.h"

#include "mn-mozilla-mailbox-backend-private.h"

#ifdef G_LIKELY
#define ___GOB_LIKELY(expr) G_LIKELY(expr)
#define ___GOB_UNLIKELY(expr) G_UNLIKELY(expr)
#else /* ! G_LIKELY */
#define ___GOB_LIKELY(expr) (expr)
#define ___GOB_UNLIKELY(expr) (expr)
#endif /* G_LIKELY */

#line 24 "src/mn-mozilla-mailbox-backend.gob"

#include <stdlib.h>
#include <limits.h>
#include "mn-base-mbox-mailbox-backend-private.h"
#include "mn-message-mime.h"
#include "mn-util.h"

/* taken from base/public/nsMsgMessageFlags.h in the Mozilla Mail&News sources */
/* in X-Mozilla-Status */
#define MOZILLA_MSG_FLAG_READ		0x0001
#define MOZILLA_MSG_FLAG_EXPUNGED	0x0008
/* in X-Mozilla-Status2 */
#define MOZILLA_MSG_FLAG_NEW		0x10000

#line 41 "mn-mozilla-mailbox-backend.c"
/* self casting macros */
#define SELF(x) MN_MOZILLA_MAILBOX_BACKEND(x)
#define SELF_CONST(x) MN_MOZILLA_MAILBOX_BACKEND_CONST(x)
#define IS_SELF(x) MN_IS_MOZILLA_MAILBOX_BACKEND(x)
#define TYPE_SELF MN_TYPE_MOZILLA_MAILBOX_BACKEND
#define SELF_CLASS(x) MN_MOZILLA_MAILBOX_BACKEND_CLASS(x)

#define SELF_GET_CLASS(x) MN_MOZILLA_MAILBOX_BACKEND_GET_CLASS(x)

/* self typedefs */
typedef MNMozillaMailboxBackend Self;
typedef MNMozillaMailboxBackendClass SelfClass;

/* here are local prototypes */
#line 0 "src/mn-mozilla-mailbox-backend.gob"
static void mn_mozilla_mailbox_backend_init (MNMozillaMailboxBackend * o);
#line 58 "mn-mozilla-mailbox-backend.c"
#line 41 "src/mn-mozilla-mailbox-backend.gob"
static void mn_mozilla_mailbox_backend_class_init (MNMozillaMailboxBackendClass * class);
#line 61 "mn-mozilla-mailbox-backend.c"
#line 46 "src/mn-mozilla-mailbox-backend.gob"
static MNMessage * ___2_mn_mozilla_mailbox_backend_get_new_message (MNBaseMboxMailboxBackend * backend, GMimeMessage * mime_message);
#line 64 "mn-mozilla-mailbox-backend.c"
#line 66 "src/mn-mozilla-mailbox-backend.gob"
static int mn_mozilla_mailbox_backend_get_status_flags (GMimeMessage * mime_message, const char * header_name);
#line 67 "mn-mozilla-mailbox-backend.c"

/* pointer to the class of our parent */
static MNBaseMboxMailboxBackendClass *parent_class = NULL;

/* Short form macros */
#define self_get_status_flags mn_mozilla_mailbox_backend_get_status_flags
GType
mn_mozilla_mailbox_backend_get_type (void)
{
	static GType type = 0;

	if ___GOB_UNLIKELY(type == 0) {
		static const GTypeInfo info = {
			sizeof (MNMozillaMailboxBackendClass),
			(GBaseInitFunc) NULL,
			(GBaseFinalizeFunc) NULL,
			(GClassInitFunc) mn_mozilla_mailbox_backend_class_init,
			(GClassFinalizeFunc) NULL,
			NULL /* class_data */,
			sizeof (MNMozillaMailboxBackend),
			0 /* n_preallocs */,
			(GInstanceInitFunc) mn_mozilla_mailbox_backend_init,
			NULL
		};

		type = g_type_register_static (MN_TYPE_BASE_MBOX_MAILBOX_BACKEND, "MNMozillaMailboxBackend", &info, (GTypeFlags)0);
	}

	return type;
}

/* a macro for creating a new object of our type */
#define GET_NEW ((MNMozillaMailboxBackend *)g_object_new(mn_mozilla_mailbox_backend_get_type(), NULL))

/* a function for creating a new object of our type */
#include <stdarg.h>
static MNMozillaMailboxBackend * GET_NEW_VARG (const char *first, ...) G_GNUC_UNUSED;
static MNMozillaMailboxBackend *
GET_NEW_VARG (const char *first, ...)
{
	MNMozillaMailboxBackend *ret;
	va_list ap;
	va_start (ap, first);
	ret = (MNMozillaMailboxBackend *)g_object_new_valist (mn_mozilla_mailbox_backend_get_type (), first, ap);
	va_end (ap);
	return ret;
}

static void 
mn_mozilla_mailbox_backend_init (MNMozillaMailboxBackend * o G_GNUC_UNUSED)
{
#define __GOB_FUNCTION__ "MN:Mozilla:Mailbox:Backend::init"
}
#undef __GOB_FUNCTION__
#line 41 "src/mn-mozilla-mailbox-backend.gob"
static void 
mn_mozilla_mailbox_backend_class_init (MNMozillaMailboxBackendClass * class G_GNUC_UNUSED)
{
#line 126 "mn-mozilla-mailbox-backend.c"
#define __GOB_FUNCTION__ "MN:Mozilla:Mailbox:Backend::class_init"
	MNBaseMboxMailboxBackendClass *mn_base_mbox_mailbox_backend_class = (MNBaseMboxMailboxBackendClass *)class;

	parent_class = g_type_class_ref (MN_TYPE_BASE_MBOX_MAILBOX_BACKEND);

#line 46 "src/mn-mozilla-mailbox-backend.gob"
	mn_base_mbox_mailbox_backend_class->get_new_message = ___2_mn_mozilla_mailbox_backend_get_new_message;
#line 134 "mn-mozilla-mailbox-backend.c"
 {
#line 42 "src/mn-mozilla-mailbox-backend.gob"

    MN_VFS_MAILBOX_BACKEND_CLASS(class)->format = "Mozilla";
  
#line 140 "mn-mozilla-mailbox-backend.c"
 }
}
#undef __GOB_FUNCTION__



#line 46 "src/mn-mozilla-mailbox-backend.gob"
static MNMessage * 
___2_mn_mozilla_mailbox_backend_get_new_message (MNBaseMboxMailboxBackend * backend G_GNUC_UNUSED, GMimeMessage * mime_message)
#line 150 "mn-mozilla-mailbox-backend.c"
#define PARENT_HANDLER(___backend,___mime_message) \
	((MN_BASE_MBOX_MAILBOX_BACKEND_CLASS(parent_class)->get_new_message)? \
		(* MN_BASE_MBOX_MAILBOX_BACKEND_CLASS(parent_class)->get_new_message)(___backend,___mime_message): \
		((MNMessage * )0))
{
#define __GOB_FUNCTION__ "MN:Mozilla:Mailbox:Backend::get_new_message"
{
#line 48 "src/mn-mozilla-mailbox-backend.gob"
	
    int flags;

    flags = self_get_status_flags(mime_message, "X-Mozilla-Status");
    if ((flags & MOZILLA_MSG_FLAG_READ) == 0
	&& (flags & MOZILLA_MSG_FLAG_EXPUNGED) == 0)
      {
	int mn_flags = 0;

	if ((self_get_status_flags(mime_message, "X-Mozilla-Status2") & MOZILLA_MSG_FLAG_NEW) != 0)
	  mn_flags |= MN_MESSAGE_NEW;

	return mn_message_new_from_mime_message(MN_MAILBOX(MN_VFS_MAILBOX_BACKEND(backend)->mailbox), mime_message, NULL, mn_flags, FALSE);
      }
    else
      return NULL;
  }}
#line 176 "mn-mozilla-mailbox-backend.c"
#undef __GOB_FUNCTION__
#undef PARENT_HANDLER

#line 66 "src/mn-mozilla-mailbox-backend.gob"
static int 
mn_mozilla_mailbox_backend_get_status_flags (GMimeMessage * mime_message, const char * header_name)
{
#line 184 "mn-mozilla-mailbox-backend.c"
#define __GOB_FUNCTION__ "MN:Mozilla:Mailbox:Backend::get_status_flags"
#line 66 "src/mn-mozilla-mailbox-backend.gob"
	g_return_val_if_fail (mime_message != NULL, (int )0);
#line 66 "src/mn-mozilla-mailbox-backend.gob"
	g_return_val_if_fail (GMIME_IS_MESSAGE (mime_message), (int )0);
#line 66 "src/mn-mozilla-mailbox-backend.gob"
	g_return_val_if_fail (header_name != NULL, (int )0);
#line 192 "mn-mozilla-mailbox-backend.c"
{
#line 69 "src/mn-mozilla-mailbox-backend.gob"
	
    const char *header;

    header = g_mime_message_get_header(mime_message, header_name);
    if (header && mn_str_ishex(header))
      return strtol(header, NULL, 16);
    else
      return 0;
  }}
#line 204 "mn-mozilla-mailbox-backend.c"
#undef __GOB_FUNCTION__
