summaryrefslogtreecommitdiff
path: root/contrib/carmel/c-client/bzk2cml.c
blob: fcff6438b95d75159de1a4638c53e663e1bd72ba (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <stdio.h>
#include <ctype.h>
#include <pwd.h>
#include <sys/dir.h>
#include "mail.h"
#include "osdep.h"
#include "carmel2.h"
#include "carmel.h"

char *last_path(), *cpystr();
void carmel2_bezerk_mail();
extern DRIVER carmeldriver;

extern char carmel_20k_buf[20000];


main(argc, argv)
     int argc;
     char **argv;
{
    char carmel_folder[500], *bezerk_folder;
    MAILSTREAM *stream;

    if(argc <= 1) {
        fprintf(stderr, "Usage: bzk2cml <folder>\n");
        exit(-1);
    }

    for(argv++; *argv != NULL; argv++) {
        bezerk_folder = last_path(*argv);  /* Only last component of path */
        sprintf(carmel_folder, "#carmel#%s", bezerk_folder);

        if(carmel_create(NULL, carmel_folder) == 0) {
            continue;
        }


        stream          = (MAILSTREAM *)fs_get(sizeof(MAILSTREAM));
        stream->dtb     = &carmeldriver;
        stream->mailbox = cpystr(carmel_folder);
	stream->local   = NULL;

        if(carmel_open(stream) == NULL) {
            continue;
        }

        if(carmel2_lock(stream, stream->mailbox, WRITE_LOCK) < 0) {
            fprintf(stderr, "Carmel folder %s locked\n", carmel_folder);
            carmel_close(stream);
            continue;
        }
          
        carmel2_spool_mail(stream, *argv, stream->mailbox, 0);
        carmel2_unlock(stream, stream->mailbox, WRITE_LOCK);
        fprintf(stderr, "Folder \"%s\" copied to \"%s\"\n", *argv,
                carmel_folder);
        carmel_close(stream);
    }
}
            

        
        
        

    

char *last_path(path)
     char *path;
{
    char *p;

    p = path + strlen(path) - 1;

    while(p > path && *p != '/')
      p--;

    if(*p == '/')
      p++;
    return(p);
}
     
void
mm_log(mess, code)
     char *mess;
     int code;
{
    fprintf(stderr, "%s\n", mess);
}

void
mm_fatal()
{
    abort();
}

void mm_mailbox() {}
void mm_critical() {}
void mm_nocritical() {}
void mm_searched() {}
void mm_exists() {}
void mm_expunged() {}