Commit 089533ba 089533babd10164d66c5b225ace23f4a04b22515 by Sergey Poznyakoff

Auto-detection of maildir format.

1 parent 000ea85a
...@@ -21,20 +21,83 @@ ...@@ -21,20 +21,83 @@
21 21
22 #ifdef ENABLE_MAILDIR 22 #ifdef ENABLE_MAILDIR
23 23
24 #include <sys/types.h>
25 #include <sys/stat.h>
26 #include <stdlib.h>
27 #include <string.h>
24 #include <errno.h> 28 #include <errno.h>
25 29
26 #include <folder0.h> 30 #include <folder0.h>
27 #include <registrar0.h> 31 #include <registrar0.h>
28 32
33 #include <maildir.h>
34
35 static int
36 _maildir_folder_init (folder_t folder ARG_UNUSED)
37 {
38 return 0;
39 }
40
41 static int
42 dir_exists (const char *name, const char *suf)
43 {
44 struct stat st;
45 char *s = maildir_mkfilename (name, suf, NULL);
46
47 if (stat (s, &st) < 0)
48 return 0;
49
50 free (s);
51
52 return S_ISDIR (st.st_mode);
53 }
54
55 static int
56 _maildir_is_scheme (record_t record, const char *url)
57 {
58 if (!url || !record->scheme)
59 return 0;
60
61 if (strncmp (record->scheme, url, strlen (record->scheme)) == 0)
62 return 1;
63
64 if (strncmp (MU_PATH_SCHEME, url, MU_PATH_SCHEME_LEN) == 0)
65 {
66 /* Attemp auto-detection */
67 struct stat st;
68
69 if (stat (url, &st) < 0)
70 return 1; /* mailbox_open will complain */
71
72 if (!S_ISDIR (st.st_mode))
73 return 0;
74
75 return dir_exists (url, TMPSUF)
76 && dir_exists (url, CURSUF)
77 && dir_exists (url, NEWSUF);
78 }
79 return 0;
80 }
81
82 /*
83 MAILDIR url
84 maildir:path
85 */
86 int
87 _maildir_url_init (url_t url)
88 {
89 return amd_url_init (url, MU_MAILDIR_SCHEME);
90 }
91
29 static struct _record _maildir_record = 92 static struct _record _maildir_record =
30 { 93 {
31 MU_MAILDIR_SCHEME, 94 MU_MAILDIR_SCHEME,
32 _url_maildir_init, /* Url init. */ 95 _maildir_url_init, /* Url init. */
33 _mailbox_maildir_init, /* Mailbox init. */ 96 _mailbox_maildir_init, /* Mailbox init. */
34 NULL, /* Mailer init. */ 97 NULL, /* Mailer init. */
35 _folder_maildir_init, /* Folder init. */ 98 _maildir_folder_init, /* Folder init. */
36 NULL, /* back pointer. */ 99 NULL, /* back pointer. */
37 NULL, /* _is_scheme method. */ 100 _maildir_is_scheme, /* _is_scheme method. */
38 NULL, /* _get_url method. */ 101 NULL, /* _get_url method. */
39 NULL, /* _get_mailbox method. */ 102 NULL, /* _get_mailbox method. */
40 NULL, /* _get_mailer method. */ 103 NULL, /* _get_mailer method. */
...@@ -42,12 +105,6 @@ static struct _record _maildir_record = ...@@ -42,12 +105,6 @@ static struct _record _maildir_record =
42 }; 105 };
43 record_t maildir_record = &_maildir_record; 106 record_t maildir_record = &_maildir_record;
44 107
45 int
46 _folder_maildir_init (folder_t folder ARG_UNUSED)
47 {
48 return 0;
49 }
50
51 #else 108 #else
52 #include <stdio.h> 109 #include <stdio.h>
53 #include <registrar0.h> 110 #include <registrar0.h>
......