1059{
1063
1064 struct Buffer *tempfile = NULL;
1065 char buf[32] = { 0 };
1066 int j;
1067 bool unlink_tempfile = false;
1068 bool need_sort = false;
1069 int first = -1;
1070 LOFF_T offset;
1071 struct stat st = { 0 };
1072 struct MUpdate *new_offset = NULL;
1073 struct MUpdate *old_offset = NULL;
1074 FILE *fp = NULL;
1075 struct Progress *progress = NULL;
1077
1078
1081 {
1083 need_sort = true;
1084 }
1085
1086
1087
1090 {
1092 mutt_error(
_(
"Fatal error! Could not reopen mailbox!"));
1093 goto fatal;
1094 }
1095
1097
1099 {
1102 goto bail;
1103 }
1104
1105
1108 {
1109
1110 rc = check;
1111 goto bail;
1112 }
1113 else if (check < 0)
1114 {
1115 goto fatal;
1116 }
1117
1118
1121 int fd = open(
buf_string(tempfile), O_WRONLY | O_EXCL | O_CREAT, 0600);
1122 if ((fd == -1) || !(fp = fdopen(fd, "w")))
1123 {
1124 if (fd != -1)
1125 {
1126 close(fd);
1127 unlink_tempfile = true;
1128 }
1130 goto bail;
1131 }
1132 unlink_tempfile = true;
1133
1134
1135
1136 int i = 0;
1139 i++)
1140 {
1141 }
1143 {
1144
1145
1146
1147 mutt_error(
_(
"sync: mbox modified, but no modified messages (report this bug)"));
1149 goto bail;
1150 }
1151
1152
1153 first = i;
1154
1156
1157
1158
1161
1162
1165
1167 {
1170 }
1171
1172 for (i = first, j = 0; i < m->
msg_count; i++)
1173 {
1175
1176
1177
1178 old_offset[i - first].
valid =
true;
1183
1185 {
1186 j++;
1187
1189 {
1191 {
1193 goto bail;
1194 }
1195 }
1196
1197
1198
1199
1200 new_offset[i - first].
hdr = ftello(fp) + offset;
1201
1206 if (rc2 != 0)
1207 {
1209 goto bail;
1210 }
1211
1212
1213
1214
1215
1216
1219
1221 {
1223 {
1225 goto bail;
1226 }
1227 }
1228 else
1229 {
1230 if (fputs(
"\n",
fp) == EOF)
1231 {
1233 goto bail;
1234 }
1235 }
1236 }
1237 }
1238
1240 {
1243 goto bail;
1244 }
1245
1246
1248 {
1250 goto bail;
1251 }
1252
1253 unlink_tempfile = false;
1254
1257 {
1264 goto fatal;
1265 }
1266
1268
1269 !fgets(buf,
sizeof(buf), adata->
fp) ||
1272 {
1275 i = -1;
1276 }
1277 else
1278 {
1280 {
1281 i = -1;
1282 }
1283 else
1284 {
1285
1286
1290
1291 if (ferror(adata->
fp))
1292 i = -1;
1293 }
1294 if (i >= 0)
1295 {
1296 m->
size = ftello(adata->
fp);
1297 if ((m->
size < 0) || (ftruncate(fileno(adata->
fp), m->
size) != 0))
1298 {
1299 i = -1;
1301 }
1302 }
1303 }
1304
1307
1309 {
1310
1311
1313
1325 goto fatal;
1326 }
1327
1328
1330
1331
1334 {
1336 }
1338 {
1342 mutt_error(
_(
"Fatal error! Could not reopen mailbox!"));
1345 goto fatal;
1346 }
1347
1348
1349 for (i = first, j = first; i < m->
msg_count; i++)
1350 {
1352 {
1357 }
1358 }
1364
1366 if (c_check_mbox_size)
1367 {
1371 }
1372
1374 return 0;
1375
1376bail:
1377
1379
1380 if (tempfile && unlink_tempfile)
1382
1383
1384 if ((first >= 0) && old_offset)
1385 {
1386 for (i = first; (i < m->
msg_count) && old_offset[i - first].
valid; i++)
1387 {
1393 }
1394 }
1395
1396
1398
1402
1405 {
1408 goto fatal;
1409 }
1410
1412 if (need_sort)
1413 {
1414
1415
1417 }
1418
1419fatal:
1422 return rc;
1423}
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
const char * cs_subset_path(const struct ConfigSubset *sub, const char *name)
Get a path config item by name.
short cs_subset_sort(const struct ConfigSubset *sub, const char *name)
Get a sort config item by name.
int mutt_copy_message(FILE *fp_out, struct Email *e, struct Message *msg, CopyMessageFlags cmflags, CopyHeaderFlags chflags, int wraplen)
Copy a message from a Mailbox.
#define MUTT_CM_UPDATE
Update structs on sync.
#define CH_UPDATE
Update the status and x-status fields?
#define CH_FROM
Retain the "From " message separator?
#define CH_UPDATE_LEN
Update Lines: and Content-Length:
void mailbox_update(struct Mailbox *m)
Get the mailbox's current size.
void mailbox_changed(struct Mailbox *m, enum NotifyMailbox action)
Notify observers of a change to a Mailbox.
struct Mailbox * mailbox_find(const char *path)
Find the mailbox with a given path.
@ NT_MAILBOX_RESORT
Email list needs resorting.
@ NT_MAILBOX_UPDATE
Update internal tables.
@ MUTT_MMDF
'mmdf' Mailbox type
@ MUTT_MBOX
'mbox' Mailbox type
void mutt_body_free(struct Body **ptr)
Free a Body.
void mutt_sort_unsorted(struct Mailbox *m)
Sort emails by their disk order.
EmailSortType
Methods for sorting Emails.
@ EMAIL_SORT_UNSORTED
Sort by the order the messages appear in the mailbox.
int mutt_file_copy_stream(FILE *fp_in, FILE *fp_out)
Copy the contents of one file into another.
bool mutt_file_seek(FILE *fp, LOFF_T offset, int whence)
Wrapper for fseeko with error handling.
#define mutt_file_fclose(FP)
#define mutt_file_fopen(PATH, MODE)
char * ShortHostname
Short version of the hostname.
#define mutt_message(...)
#define mutt_debug(LEVEL,...)
static enum MxStatus mbox_mbox_check(struct Mailbox *m)
Check for new mail - Implements MxOps::mbox_check() -.
@ LL_DEBUG1
Log at debug level 1.
static int mbox_lock_mailbox(struct Mailbox *m, bool excl, bool retry)
Lock a mailbox.
static struct MboxAccountData * mbox_adata_get(struct Mailbox *m)
Get the private data associated with a Mailbox.
static FILE * mbox_open_readwrite(struct Mailbox *m)
Open an mbox read-write.
static FILE * mbox_open_readonly(struct Mailbox *m)
Open an mbox read-only.
static void mbox_unlock_mailbox(struct Mailbox *m)
Unlock a mailbox.
void mbox_reset_atime(struct Mailbox *m, struct stat *st)
Reset the access time on the mailbox file.
#define FREE(x)
Free memory and set the pointer to NULL.
#define MUTT_MEM_CALLOC(n, type)
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
void pretty_mailbox(struct Buffer *buf)
Shorten a mailbox path using '~' or '='.
int mx_msg_close(struct Mailbox *m, struct Message **ptr)
Close a message.
void mx_fastclose_mailbox(struct Mailbox *m, bool keep_account)
Free up memory associated with the Mailbox.
struct Message * mx_msg_open(struct Mailbox *m, struct Email *e)
Return a stream pointer for a message.
@ MX_STATUS_REOPENED
Mailbox was reopened.
@ MX_STATUS_NEW_MAIL
New mail received in Mailbox.
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
void mutt_sig_block(void)
Block signals during critical operations.
void mutt_sig_unblock(void)
Restore previously blocked signals.
void * adata
Private data (for Mailbox backends)
struct Body * parts
parts of a multipart or message/rfc822
LOFF_T offset
offset where the actual data begins
LOFF_T length
length (in bytes) of attachment
long hdr_offset
Offset in stream where the headers begin.
String manipulation buffer.
int lines
How many lines in the body of this message?
struct Body * body
List of MIME parts.
bool changed
Email has been edited.
LOFF_T offset
Where in the stream does this message begin?
bool attach_del
Has an attachment marked for deletion.
Store of new offsets, used by mutt_sync_mailbox()
long lines
Number of lines.
LOFF_T length
Total length.
bool valid
Is this entry valid?
bool has_new
Mailbox has new mail.
enum MailboxType type
Mailbox type.
off_t size
Size of the Mailbox.
Mbox-specific Account data -.
A local copy of an email.
FILE * fp
pointer to the message data
char * username
User's login name.