aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test9.c
blob: 36cf45ad2a455ebdf2d86dfce26cafb7522c4426 (plain) (blame)
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
72
73
74
75
76
77
78
79
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */


#include "camel-mbox-folder.h"
#include "camel-mbox-parser.h"
#include "camel-mbox-utils.h"
#include "camel-mbox-summary.h"
#include "camel-log.h"
#include "camel-exception.h"
#include "md5-utils.h"
#include <sys/types.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <glib.h>

int
main (int argc, char**argv)
{
    GArray *message_info_array;
    gint test_file_fd;
    CamelException *ex;
    CamelMboxSummary *sum1, *sum2;
    GArray *mbox_summary_info;
    CamelMboxSummaryInformation *msg_info;
    int i;
    guint32 next_uid;

    camel_debug_level = CAMEL_LOG_LEVEL_FULL_DEBUG;

    gtk_init (&argc, &argv);
    camel_init ();  
    
    ex = camel_exception_new ();
    test_file_fd = open (argv[1], O_RDONLY);
    message_info_array = camel_mbox_parse_file (test_file_fd, 
                            "From ", 
                            0,
                            &next_uid
                            TRUE,
                            NULL,
                            0,
                            ex); 
    
    close (test_file_fd);
    camel_mbox_write_xev (argv[1], message_info_array, 1, ex);
    if (camel_exception_get_id (ex)) { 
        printf ("Exception caught in camel_mbox_write_xev : %s\n", camel_exception_get_description (ex));
    }
    
    
    mbox_summary_info =
        parsed_information_to_mbox_summary (message_info_array);
    sum1 = g_new (CamelMboxSummary, 1);

    md5_get_digest_from_file (argv[1], sum1->md5_digest);
    sum1->nb_message = mbox_summary_info->len;

    sum1->message_info = mbox_summary_info;

    camel_mbox_save_summary (sum1, "ev-summary.mbox", ex);

    sum2 = camel_mbox_load_summary ("ev-summary.mbox", ex);

    for (i=0; i<sum1->nb_message; i++) {
        
        msg_info = (CamelMboxSummaryInformation *)(sum1->message_info->data) + i;
        printf ("Message %d :\n"
            "  From : %s\n", i, msg_info->sender);
    }

    return 1;
    
}