annotate src/lib-storage/index/index-storage.c @ 939:24b64302f59c HEAD

index_storage_sync_and_lock() didn't set lock notify function.
author Timo Sirainen <tss@iki.fi>
date Fri, 10 Jan 2003 13:29:24 +0200
parents fd8888f6f037
children 8028c4dcf38f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1 /* Copyright (C) 2002 Timo Sirainen */
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
3 #include "lib.h"
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
4 #include "mail-index.h"
114
0c3ffb677ad1 Reset index error message after it's been moved to storage.
Timo Sirainen <tss@iki.fi>
parents: 106
diff changeset
5 #include "mail-index-util.h"
175
73bf05a1d862 Moved custom flags handling into lib-index.
Timo Sirainen <tss@iki.fi>
parents: 171
diff changeset
6 #include "mail-custom-flags.h"
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
7 #include "index-storage.h"
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
8
462
67d22b7b0918 Added mail_cache_fields and mail_never_cache_fields settings, plus settings
Timo Sirainen <tss@iki.fi>
parents: 457
diff changeset
9 #include <stdlib.h>
674
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
10 #include <time.h>
450
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
11 #include <unistd.h>
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
12 #include <sys/stat.h>
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
13
674
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
14 #define LOCK_NOTIFY_INTERVAL 30
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
15
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 847
diff changeset
16 struct index_list {
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 847
diff changeset
17 struct index_list *next;
450
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
18
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 847
diff changeset
19 struct mail_index *index;
450
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
20 int refcount;
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
21 };
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
22
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 847
diff changeset
23 static struct index_list *indexes = NULL;
450
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
24
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 847
diff changeset
25 void index_storage_add(struct mail_index *index)
450
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
26 {
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 847
diff changeset
27 struct index_list *list;
450
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
28
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 847
diff changeset
29 list = i_new(struct index_list, 1);
450
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
30 list->refcount = 1;
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
31 list->index = index;
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
32
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
33 list->next = indexes;
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
34 indexes = list;
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
35 }
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
36
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 847
diff changeset
37 struct mail_index *index_storage_lookup_ref(const char *path)
450
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
38 {
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 847
diff changeset
39 struct index_list *list;
450
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
40 struct stat st1, st2;
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
41
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
42 if (stat(path, &st1) < 0)
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
43 return NULL;
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
44
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
45 /* compare inodes so we don't break even with symlinks */
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
46 for (list = indexes; list != NULL; list = list->next) {
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
47 if (stat(list->index->dir, &st2) == 0) {
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
48 if (st1.st_ino == st2.st_ino &&
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
49 st1.st_dev == st2.st_dev) {
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
50 list->refcount++;
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
51 return list->index;
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
52 }
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
53 }
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
54 }
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
55
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
56 return NULL;
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
57 }
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
58
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 847
diff changeset
59 void index_storage_unref(struct mail_index *index)
450
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
60 {
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 847
diff changeset
61 struct index_list **list, *rec;
450
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
62
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
63 for (list = &indexes; *list != NULL; list = &(*list)->next) {
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
64 rec = *list;
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
65
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
66 if (rec->index == index) {
457
31cc41537495 Indexes were never closed because refcount wasn't updated.
Timo Sirainen <tss@iki.fi>
parents: 450
diff changeset
67 if (--rec->refcount == 0) {
450
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
68 index->free(index);
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
69 *list = rec->next;
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
70 i_free(rec);
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
71 }
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
72 return;
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
73 }
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
74 }
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
75
546
e1254b838e0b Added --enable-asserts (default) and fixed some warnings when building
Timo Sirainen <tss@iki.fi>
parents: 525
diff changeset
76 i_unreached();
450
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
77 }
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
78
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 847
diff changeset
79 static enum mail_data_field get_data_fields(const char *fields)
462
67d22b7b0918 Added mail_cache_fields and mail_never_cache_fields settings, plus settings
Timo Sirainen <tss@iki.fi>
parents: 457
diff changeset
80 {
67d22b7b0918 Added mail_cache_fields and mail_never_cache_fields settings, plus settings
Timo Sirainen <tss@iki.fi>
parents: 457
diff changeset
81 static const char *field_names[] = {
67d22b7b0918 Added mail_cache_fields and mail_never_cache_fields settings, plus settings
Timo Sirainen <tss@iki.fi>
parents: 457
diff changeset
82 "Location",
67d22b7b0918 Added mail_cache_fields and mail_never_cache_fields settings, plus settings
Timo Sirainen <tss@iki.fi>
parents: 457
diff changeset
83 "Envelope",
67d22b7b0918 Added mail_cache_fields and mail_never_cache_fields settings, plus settings
Timo Sirainen <tss@iki.fi>
parents: 457
diff changeset
84 "Body",
67d22b7b0918 Added mail_cache_fields and mail_never_cache_fields settings, plus settings
Timo Sirainen <tss@iki.fi>
parents: 457
diff changeset
85 "Bodystructure",
67d22b7b0918 Added mail_cache_fields and mail_never_cache_fields settings, plus settings
Timo Sirainen <tss@iki.fi>
parents: 457
diff changeset
86 "MD5",
67d22b7b0918 Added mail_cache_fields and mail_never_cache_fields settings, plus settings
Timo Sirainen <tss@iki.fi>
parents: 457
diff changeset
87 "MessagePart",
67d22b7b0918 Added mail_cache_fields and mail_never_cache_fields settings, plus settings
Timo Sirainen <tss@iki.fi>
parents: 457
diff changeset
88 NULL
67d22b7b0918 Added mail_cache_fields and mail_never_cache_fields settings, plus settings
Timo Sirainen <tss@iki.fi>
parents: 457
diff changeset
89 };
67d22b7b0918 Added mail_cache_fields and mail_never_cache_fields settings, plus settings
Timo Sirainen <tss@iki.fi>
parents: 457
diff changeset
90
847
7f41a4b33975 t_strsplit() returns now const char **, which removes a few nasty casts.
Timo Sirainen <tss@iki.fi>
parents: 835
diff changeset
91 const char *const *arr;
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 847
diff changeset
92 enum mail_data_field ret;
462
67d22b7b0918 Added mail_cache_fields and mail_never_cache_fields settings, plus settings
Timo Sirainen <tss@iki.fi>
parents: 457
diff changeset
93 int i;
67d22b7b0918 Added mail_cache_fields and mail_never_cache_fields settings, plus settings
Timo Sirainen <tss@iki.fi>
parents: 457
diff changeset
94
67d22b7b0918 Added mail_cache_fields and mail_never_cache_fields settings, plus settings
Timo Sirainen <tss@iki.fi>
parents: 457
diff changeset
95 if (fields == NULL || *fields == '\0')
67d22b7b0918 Added mail_cache_fields and mail_never_cache_fields settings, plus settings
Timo Sirainen <tss@iki.fi>
parents: 457
diff changeset
96 return 0;
67d22b7b0918 Added mail_cache_fields and mail_never_cache_fields settings, plus settings
Timo Sirainen <tss@iki.fi>
parents: 457
diff changeset
97
67d22b7b0918 Added mail_cache_fields and mail_never_cache_fields settings, plus settings
Timo Sirainen <tss@iki.fi>
parents: 457
diff changeset
98 ret = 0;
67d22b7b0918 Added mail_cache_fields and mail_never_cache_fields settings, plus settings
Timo Sirainen <tss@iki.fi>
parents: 457
diff changeset
99 for (arr = t_strsplit(fields, " ,"); *arr != NULL; arr++) {
67d22b7b0918 Added mail_cache_fields and mail_never_cache_fields settings, plus settings
Timo Sirainen <tss@iki.fi>
parents: 457
diff changeset
100 if (*arr == '\0')
67d22b7b0918 Added mail_cache_fields and mail_never_cache_fields settings, plus settings
Timo Sirainen <tss@iki.fi>
parents: 457
diff changeset
101 continue;
67d22b7b0918 Added mail_cache_fields and mail_never_cache_fields settings, plus settings
Timo Sirainen <tss@iki.fi>
parents: 457
diff changeset
102
67d22b7b0918 Added mail_cache_fields and mail_never_cache_fields settings, plus settings
Timo Sirainen <tss@iki.fi>
parents: 457
diff changeset
103 for (i = 0; field_names[i] != NULL; i++) {
67d22b7b0918 Added mail_cache_fields and mail_never_cache_fields settings, plus settings
Timo Sirainen <tss@iki.fi>
parents: 457
diff changeset
104 if (strcasecmp(field_names[i], *arr) == 0) {
67d22b7b0918 Added mail_cache_fields and mail_never_cache_fields settings, plus settings
Timo Sirainen <tss@iki.fi>
parents: 457
diff changeset
105 ret |= 1 << i;
67d22b7b0918 Added mail_cache_fields and mail_never_cache_fields settings, plus settings
Timo Sirainen <tss@iki.fi>
parents: 457
diff changeset
106 break;
67d22b7b0918 Added mail_cache_fields and mail_never_cache_fields settings, plus settings
Timo Sirainen <tss@iki.fi>
parents: 457
diff changeset
107 }
67d22b7b0918 Added mail_cache_fields and mail_never_cache_fields settings, plus settings
Timo Sirainen <tss@iki.fi>
parents: 457
diff changeset
108 }
67d22b7b0918 Added mail_cache_fields and mail_never_cache_fields settings, plus settings
Timo Sirainen <tss@iki.fi>
parents: 457
diff changeset
109 if (field_names[i] == NULL) {
67d22b7b0918 Added mail_cache_fields and mail_never_cache_fields settings, plus settings
Timo Sirainen <tss@iki.fi>
parents: 457
diff changeset
110 i_error("Invalid cache field name '%s', ignoring ",
67d22b7b0918 Added mail_cache_fields and mail_never_cache_fields settings, plus settings
Timo Sirainen <tss@iki.fi>
parents: 457
diff changeset
111 *arr);
67d22b7b0918 Added mail_cache_fields and mail_never_cache_fields settings, plus settings
Timo Sirainen <tss@iki.fi>
parents: 457
diff changeset
112 }
67d22b7b0918 Added mail_cache_fields and mail_never_cache_fields settings, plus settings
Timo Sirainen <tss@iki.fi>
parents: 457
diff changeset
113 }
67d22b7b0918 Added mail_cache_fields and mail_never_cache_fields settings, plus settings
Timo Sirainen <tss@iki.fi>
parents: 457
diff changeset
114
67d22b7b0918 Added mail_cache_fields and mail_never_cache_fields settings, plus settings
Timo Sirainen <tss@iki.fi>
parents: 457
diff changeset
115 return ret;
67d22b7b0918 Added mail_cache_fields and mail_never_cache_fields settings, plus settings
Timo Sirainen <tss@iki.fi>
parents: 457
diff changeset
116 }
67d22b7b0918 Added mail_cache_fields and mail_never_cache_fields settings, plus settings
Timo Sirainen <tss@iki.fi>
parents: 457
diff changeset
117
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 847
diff changeset
118 static enum mail_data_field get_default_cache_fields(void)
462
67d22b7b0918 Added mail_cache_fields and mail_never_cache_fields settings, plus settings
Timo Sirainen <tss@iki.fi>
parents: 457
diff changeset
119 {
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 847
diff changeset
120 static enum mail_data_field ret = 0;
462
67d22b7b0918 Added mail_cache_fields and mail_never_cache_fields settings, plus settings
Timo Sirainen <tss@iki.fi>
parents: 457
diff changeset
121 static int ret_set = FALSE;
67d22b7b0918 Added mail_cache_fields and mail_never_cache_fields settings, plus settings
Timo Sirainen <tss@iki.fi>
parents: 457
diff changeset
122
67d22b7b0918 Added mail_cache_fields and mail_never_cache_fields settings, plus settings
Timo Sirainen <tss@iki.fi>
parents: 457
diff changeset
123 if (ret_set)
67d22b7b0918 Added mail_cache_fields and mail_never_cache_fields settings, plus settings
Timo Sirainen <tss@iki.fi>
parents: 457
diff changeset
124 return ret;
67d22b7b0918 Added mail_cache_fields and mail_never_cache_fields settings, plus settings
Timo Sirainen <tss@iki.fi>
parents: 457
diff changeset
125
525
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 462
diff changeset
126 ret = get_data_fields(getenv("MAIL_CACHE_FIELDS"));
462
67d22b7b0918 Added mail_cache_fields and mail_never_cache_fields settings, plus settings
Timo Sirainen <tss@iki.fi>
parents: 457
diff changeset
127 ret_set = TRUE;
67d22b7b0918 Added mail_cache_fields and mail_never_cache_fields settings, plus settings
Timo Sirainen <tss@iki.fi>
parents: 457
diff changeset
128 return ret;
67d22b7b0918 Added mail_cache_fields and mail_never_cache_fields settings, plus settings
Timo Sirainen <tss@iki.fi>
parents: 457
diff changeset
129 }
67d22b7b0918 Added mail_cache_fields and mail_never_cache_fields settings, plus settings
Timo Sirainen <tss@iki.fi>
parents: 457
diff changeset
130
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 847
diff changeset
131 static enum mail_data_field get_never_cache_fields(void)
462
67d22b7b0918 Added mail_cache_fields and mail_never_cache_fields settings, plus settings
Timo Sirainen <tss@iki.fi>
parents: 457
diff changeset
132 {
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 847
diff changeset
133 static enum mail_data_field ret = 0;
462
67d22b7b0918 Added mail_cache_fields and mail_never_cache_fields settings, plus settings
Timo Sirainen <tss@iki.fi>
parents: 457
diff changeset
134 static int ret_set = FALSE;
67d22b7b0918 Added mail_cache_fields and mail_never_cache_fields settings, plus settings
Timo Sirainen <tss@iki.fi>
parents: 457
diff changeset
135
67d22b7b0918 Added mail_cache_fields and mail_never_cache_fields settings, plus settings
Timo Sirainen <tss@iki.fi>
parents: 457
diff changeset
136 if (ret_set)
67d22b7b0918 Added mail_cache_fields and mail_never_cache_fields settings, plus settings
Timo Sirainen <tss@iki.fi>
parents: 457
diff changeset
137 return ret;
67d22b7b0918 Added mail_cache_fields and mail_never_cache_fields settings, plus settings
Timo Sirainen <tss@iki.fi>
parents: 457
diff changeset
138
525
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 462
diff changeset
139 ret = get_data_fields(getenv("MAIL_NEVER_CACHE_FIELDS"));
462
67d22b7b0918 Added mail_cache_fields and mail_never_cache_fields settings, plus settings
Timo Sirainen <tss@iki.fi>
parents: 457
diff changeset
140 ret_set = TRUE;
67d22b7b0918 Added mail_cache_fields and mail_never_cache_fields settings, plus settings
Timo Sirainen <tss@iki.fi>
parents: 457
diff changeset
141 return ret;
67d22b7b0918 Added mail_cache_fields and mail_never_cache_fields settings, plus settings
Timo Sirainen <tss@iki.fi>
parents: 457
diff changeset
142 }
67d22b7b0918 Added mail_cache_fields and mail_never_cache_fields settings, plus settings
Timo Sirainen <tss@iki.fi>
parents: 457
diff changeset
143
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 847
diff changeset
144 static void lock_notify(enum mail_lock_notify_type notify_type,
674
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
145 unsigned int secs_left, void *context)
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
146 {
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 847
diff changeset
147 struct index_mailbox *ibox = context;
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 847
diff changeset
148 struct mail_storage *storage = ibox->box.storage;
674
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
149 const char *str;
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
150 time_t now;
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
151
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
152 if ((secs_left % 15) != 0) {
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
153 /* update alarm() so that we get back here around the same
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
154 time we want the next notify. also try to use somewhat
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
155 rounded times. this affects only fcntl() locking, dotlock
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
156 and flock() calls should be calling us constantly */
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
157 alarm(secs_left%15);
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
158 }
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
159
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
160 now = time(NULL);
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
161 if (now < ibox->next_lock_notify || secs_left < 15)
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
162 return;
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
163
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
164 ibox->next_lock_notify = now + LOCK_NOTIFY_INTERVAL;
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
165
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
166 switch (notify_type) {
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
167 case MAIL_LOCK_NOTIFY_MAILBOX_ABORT:
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
168 str = t_strdup_printf("Mailbox is locked, will abort in "
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
169 "%u seconds", secs_left);
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
170 storage->callbacks->notify_no(&ibox->box, str,
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
171 storage->callback_context);
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
172 break;
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
173 case MAIL_LOCK_NOTIFY_MAILBOX_OVERRIDE:
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
174 str = t_strdup_printf("Stale mailbox lock file detected, "
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
175 "will override in %u seconds", secs_left);
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
176 storage->callbacks->notify_ok(&ibox->box, str,
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
177 storage->callback_context);
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
178 break;
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
179 case MAIL_LOCK_NOTIFY_INDEX_ABORT:
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
180 str = t_strdup_printf("Mailbox index is locked, will abort in "
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
181 "%u seconds", secs_left);
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
182 storage->callbacks->notify_no(&ibox->box, str,
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
183 storage->callback_context);
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
184 break;
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
185 }
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
186 }
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
187
939
24b64302f59c index_storage_sync_and_lock() didn't set lock notify function.
Timo Sirainen <tss@iki.fi>
parents: 903
diff changeset
188 void index_storage_init_lock_notify(struct index_mailbox *ibox)
24b64302f59c index_storage_sync_and_lock() didn't set lock notify function.
Timo Sirainen <tss@iki.fi>
parents: 903
diff changeset
189 {
24b64302f59c index_storage_sync_and_lock() didn't set lock notify function.
Timo Sirainen <tss@iki.fi>
parents: 903
diff changeset
190 ibox->next_lock_notify = time(NULL) + LOCK_NOTIFY_INTERVAL;
24b64302f59c index_storage_sync_and_lock() didn't set lock notify function.
Timo Sirainen <tss@iki.fi>
parents: 903
diff changeset
191 ibox->index->set_lock_notify_callback(ibox->index, lock_notify, ibox);
24b64302f59c index_storage_sync_and_lock() didn't set lock notify function.
Timo Sirainen <tss@iki.fi>
parents: 903
diff changeset
192 }
24b64302f59c index_storage_sync_and_lock() didn't set lock notify function.
Timo Sirainen <tss@iki.fi>
parents: 903
diff changeset
193
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 847
diff changeset
194 int index_storage_lock(struct index_mailbox *ibox,
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 847
diff changeset
195 enum mail_lock_type lock_type)
674
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
196 {
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
197 int ret;
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
198
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
199 /* we have to set/reset this every time, because the same index
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
200 may be used by multiple IndexMailboxes. */
939
24b64302f59c index_storage_sync_and_lock() didn't set lock notify function.
Timo Sirainen <tss@iki.fi>
parents: 903
diff changeset
201 index_storage_init_lock_notify(ibox);
674
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
202 ret = ibox->index->set_lock(ibox->index, lock_type);
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
203 ibox->index->set_lock_notify_callback(ibox->index, NULL, NULL);
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
204
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
205 if (!ret)
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
206 return mail_storage_set_index_error(ibox);
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
207
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
208 return TRUE;
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
209 }
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
210
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 847
diff changeset
211 struct index_mailbox *
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 847
diff changeset
212 index_storage_init(struct mail_storage *storage, struct mailbox *box,
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 847
diff changeset
213 struct mail_index *index, const char *name,
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 847
diff changeset
214 int readonly, int fast)
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
215 {
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 847
diff changeset
216 struct index_mailbox *ibox;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
217
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
218 i_assert(name != NULL);
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
219
450
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
220 do {
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 847
diff changeset
221 ibox = i_new(struct index_mailbox, 1);
450
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
222 ibox->box = *box;
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
223
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
224 ibox->box.storage = storage;
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
225 ibox->box.name = i_strdup(name);
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
226 ibox->box.readonly = readonly;
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
227 ibox->box.allow_custom_flags = TRUE;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
228
450
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
229 ibox->index = index;
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
230 ibox->cache = imap_msgcache_alloc(&index_msgcache_iface);
674
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
231
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
232 ibox->next_lock_notify = time(NULL) + LOCK_NOTIFY_INTERVAL;
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
233 index->set_lock_notify_callback(index, lock_notify, ibox);
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
234
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
235 if (!index->opened) {
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
236 /* open the index first */
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
237 index->default_cache_fields =
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
238 get_default_cache_fields();
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
239 index->never_cache_fields =
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
240 get_never_cache_fields();
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
241 if (!index->open_or_create(index, !readonly, fast))
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
242 break;
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
243 }
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
244
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
245 if (!ibox->index->set_lock(ibox->index, MAIL_LOCK_SHARED))
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
246 break;
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
247
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
248 ibox->synced_messages_count =
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
249 mail_index_get_header(index)->messages_count;
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
250
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
251 if (!ibox->index->set_lock(ibox->index, MAIL_LOCK_UNLOCK))
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
252 break;
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
253
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
254 index->set_lock_notify_callback(index, NULL, NULL);
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
255
450
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
256 return ibox;
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
257 } while (0);
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
258
674
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
259 mail_storage_set_index_error(ibox);
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
260 index_storage_close(&ibox->box);
450
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
261 return NULL;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
262 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
263
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 847
diff changeset
264 int index_storage_close(struct mailbox *box)
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
265 {
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 847
diff changeset
266 struct index_mailbox *ibox = (struct index_mailbox *) box;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
267
600
3b44bc64afd4 mailbox_check_interval setting: Dovecot can notify client of new mail in
Timo Sirainen <tss@iki.fi>
parents: 559
diff changeset
268 index_mailbox_check_remove(ibox);
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
269 imap_msgcache_free(ibox->cache);
674
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
270 if (ibox->index != NULL)
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
271 index_storage_unref(ibox->index);
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
272
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
273 i_free(box->name);
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
274 i_free(box);
559
c834e77b624c Mostly mbox locking/syncing fixes. Still some problems though.
Timo Sirainen <tss@iki.fi>
parents: 546
diff changeset
275
c834e77b624c Mostly mbox locking/syncing fixes. Still some problems though.
Timo Sirainen <tss@iki.fi>
parents: 546
diff changeset
276 return TRUE;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
277 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
278
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 847
diff changeset
279 void index_storage_set_callbacks(struct mail_storage *storage,
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 847
diff changeset
280 struct mail_storage_callbacks *callbacks,
674
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
281 void *context)
450
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
282 {
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 847
diff changeset
283 memcpy(storage->callbacks, callbacks,
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 847
diff changeset
284 sizeof(struct mail_storage_callbacks));
674
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
285 storage->callback_context = context;
450
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
286 }
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 355
diff changeset
287
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 847
diff changeset
288 int mail_storage_set_index_error(struct index_mailbox *ibox)
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
289 {
674
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
290 switch (ibox->index->get_last_error(ibox->index)) {
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
291 case MAIL_INDEX_ERROR_NONE:
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
292 case MAIL_INDEX_ERROR_INTERNAL:
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
293 mail_storage_set_internal_error(ibox->box.storage);
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
294 break;
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
295 case MAIL_INDEX_ERROR_INCONSISTENT:
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
296 ibox->box.inconsistent = TRUE;
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
297 break;
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
298 case MAIL_INDEX_ERROR_DISKSPACE:
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
299 mail_storage_set_error(ibox->box.storage, "Out of disk space");
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
300 break;
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
301 case MAIL_INDEX_ERROR_INDEX_LOCK_TIMEOUT:
835
91d7ee63a0b5 Compile with -Wformat-nonliteral now. Found a format string bug with it :(
Timo Sirainen <tss@iki.fi>
parents: 674
diff changeset
302 mail_storage_set_error(ibox->box.storage,
91d7ee63a0b5 Compile with -Wformat-nonliteral now. Found a format string bug with it :(
Timo Sirainen <tss@iki.fi>
parents: 674
diff changeset
303 "Timeout while waiting for lock to index of mailbox %s",
91d7ee63a0b5 Compile with -Wformat-nonliteral now. Found a format string bug with it :(
Timo Sirainen <tss@iki.fi>
parents: 674
diff changeset
304 ibox->box.name);
674
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
305 break;
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
306 case MAIL_INDEX_ERROR_MAILBOX_LOCK_TIMEOUT:
835
91d7ee63a0b5 Compile with -Wformat-nonliteral now. Found a format string bug with it :(
Timo Sirainen <tss@iki.fi>
parents: 674
diff changeset
307 mail_storage_set_error(ibox->box.storage,
91d7ee63a0b5 Compile with -Wformat-nonliteral now. Found a format string bug with it :(
Timo Sirainen <tss@iki.fi>
parents: 674
diff changeset
308 "Timeout while waiting for lock to mailbox %s",
91d7ee63a0b5 Compile with -Wformat-nonliteral now. Found a format string bug with it :(
Timo Sirainen <tss@iki.fi>
parents: 674
diff changeset
309 ibox->box.name);
674
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
310 break;
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 600
diff changeset
311 }
222
cf4d065f2f85 lots of cleanups. also index/datafile is now capable of staying in memory,
Timo Sirainen <tss@iki.fi>
parents: 196
diff changeset
312
114
0c3ffb677ad1 Reset index error message after it's been moved to storage.
Timo Sirainen <tss@iki.fi>
parents: 106
diff changeset
313 index_reset_error(ibox->index);
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
314 return FALSE;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
315 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
316
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 847
diff changeset
317 int index_mailbox_fix_custom_flags(struct index_mailbox *ibox,
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 847
diff changeset
318 enum mail_flags *flags,
175
73bf05a1d862 Moved custom flags handling into lib-index.
Timo Sirainen <tss@iki.fi>
parents: 171
diff changeset
319 const char *custom_flags[])
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
320 {
175
73bf05a1d862 Moved custom flags handling into lib-index.
Timo Sirainen <tss@iki.fi>
parents: 171
diff changeset
321 int ret;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
322
175
73bf05a1d862 Moved custom flags handling into lib-index.
Timo Sirainen <tss@iki.fi>
parents: 171
diff changeset
323 ret = mail_custom_flags_fix_list(ibox->index->custom_flags,
196
95d21ab87eeb X-IMAPbase is now parsed correctly.
Timo Sirainen <tss@iki.fi>
parents: 175
diff changeset
324 flags, custom_flags,
95d21ab87eeb X-IMAPbase is now parsed correctly.
Timo Sirainen <tss@iki.fi>
parents: 175
diff changeset
325 MAIL_CUSTOM_FLAGS_COUNT);
175
73bf05a1d862 Moved custom flags handling into lib-index.
Timo Sirainen <tss@iki.fi>
parents: 171
diff changeset
326 switch (ret) {
73bf05a1d862 Moved custom flags handling into lib-index.
Timo Sirainen <tss@iki.fi>
parents: 171
diff changeset
327 case 1:
73bf05a1d862 Moved custom flags handling into lib-index.
Timo Sirainen <tss@iki.fi>
parents: 171
diff changeset
328 return TRUE;
73bf05a1d862 Moved custom flags handling into lib-index.
Timo Sirainen <tss@iki.fi>
parents: 171
diff changeset
329 case 0:
835
91d7ee63a0b5 Compile with -Wformat-nonliteral now. Found a format string bug with it :(
Timo Sirainen <tss@iki.fi>
parents: 674
diff changeset
330 mail_storage_set_error(ibox->box.storage,
91d7ee63a0b5 Compile with -Wformat-nonliteral now. Found a format string bug with it :(
Timo Sirainen <tss@iki.fi>
parents: 674
diff changeset
331 "Maximum number of different custom flags exceeded");
175
73bf05a1d862 Moved custom flags handling into lib-index.
Timo Sirainen <tss@iki.fi>
parents: 171
diff changeset
332 return FALSE;
73bf05a1d862 Moved custom flags handling into lib-index.
Timo Sirainen <tss@iki.fi>
parents: 171
diff changeset
333 default:
73bf05a1d862 Moved custom flags handling into lib-index.
Timo Sirainen <tss@iki.fi>
parents: 171
diff changeset
334 return mail_storage_set_index_error(ibox);
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
335 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
336 }
325
ba058497efa9 Send RECENT after all EXISTS replies. Check for new mail in mailbox after
Timo Sirainen <tss@iki.fi>
parents: 296
diff changeset
337
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 847
diff changeset
338 unsigned int index_storage_get_recent_count(struct mail_index *index)
325
ba058497efa9 Send RECENT after all EXISTS replies. Check for new mail in mailbox after
Timo Sirainen <tss@iki.fi>
parents: 296
diff changeset
339 {
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 847
diff changeset
340 struct mail_index_header *hdr;
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 847
diff changeset
341 struct mail_index_record *rec;
325
ba058497efa9 Send RECENT after all EXISTS replies. Check for new mail in mailbox after
Timo Sirainen <tss@iki.fi>
parents: 296
diff changeset
342 unsigned int seq;
ba058497efa9 Send RECENT after all EXISTS replies. Check for new mail in mailbox after
Timo Sirainen <tss@iki.fi>
parents: 296
diff changeset
343
ba058497efa9 Send RECENT after all EXISTS replies. Check for new mail in mailbox after
Timo Sirainen <tss@iki.fi>
parents: 296
diff changeset
344 hdr = mail_index_get_header(index);
ba058497efa9 Send RECENT after all EXISTS replies. Check for new mail in mailbox after
Timo Sirainen <tss@iki.fi>
parents: 296
diff changeset
345 if (index->first_recent_uid <= 1) {
ba058497efa9 Send RECENT after all EXISTS replies. Check for new mail in mailbox after
Timo Sirainen <tss@iki.fi>
parents: 296
diff changeset
346 /* all are recent */
ba058497efa9 Send RECENT after all EXISTS replies. Check for new mail in mailbox after
Timo Sirainen <tss@iki.fi>
parents: 296
diff changeset
347 return hdr->messages_count;
ba058497efa9 Send RECENT after all EXISTS replies. Check for new mail in mailbox after
Timo Sirainen <tss@iki.fi>
parents: 296
diff changeset
348 }
ba058497efa9 Send RECENT after all EXISTS replies. Check for new mail in mailbox after
Timo Sirainen <tss@iki.fi>
parents: 296
diff changeset
349
ba058497efa9 Send RECENT after all EXISTS replies. Check for new mail in mailbox after
Timo Sirainen <tss@iki.fi>
parents: 296
diff changeset
350 /* get the first recent message */
ba058497efa9 Send RECENT after all EXISTS replies. Check for new mail in mailbox after
Timo Sirainen <tss@iki.fi>
parents: 296
diff changeset
351 if (index->first_recent_uid >= hdr->next_uid)
ba058497efa9 Send RECENT after all EXISTS replies. Check for new mail in mailbox after
Timo Sirainen <tss@iki.fi>
parents: 296
diff changeset
352 return 0;
ba058497efa9 Send RECENT after all EXISTS replies. Check for new mail in mailbox after
Timo Sirainen <tss@iki.fi>
parents: 296
diff changeset
353
ba058497efa9 Send RECENT after all EXISTS replies. Check for new mail in mailbox after
Timo Sirainen <tss@iki.fi>
parents: 296
diff changeset
354 rec = index->lookup_uid_range(index, index->first_recent_uid,
355
0dc59fd3faed First version of binary tree file, still some locking issues while opening
Timo Sirainen <tss@iki.fi>
parents: 325
diff changeset
355 hdr->next_uid - 1, &seq);
0dc59fd3faed First version of binary tree file, still some locking issues while opening
Timo Sirainen <tss@iki.fi>
parents: 325
diff changeset
356 return rec == NULL ? 0 : hdr->messages_count+1 - seq;
325
ba058497efa9 Send RECENT after all EXISTS replies. Check for new mail in mailbox after
Timo Sirainen <tss@iki.fi>
parents: 296
diff changeset
357 }