1157{
1161
1162 struct Buffer *tempfile = NULL;
1163 char buf[32] = { 0 };
1164 int j;
1165 bool unlink_tempfile = false;
1166 bool need_sort = false;
1167 int first = -1;
1168 LOFF_T offset;
1169 struct stat st = { 0 };
1170 struct MUpdate *new_offset = NULL;
1171 struct MUpdate *old_offset = NULL;
1172 FILE *fp = NULL;
1173 struct Progress *progress = NULL;
1175
1176
1180 {
1186 need_sort = true;
1187 }
1188
1189
1190
1193 {
1195 mutt_error(
_(
"Fatal error! Could not reopen mailbox!"));
1196 goto fatal;
1197 }
1198
1200
1202 {
1205 goto bail;
1206 }
1207
1208
1211 {
1212
1213 rc = check;
1214 goto bail;
1215 }
1216 else if (check < 0)
1217 {
1218 goto fatal;
1219 }
1220
1221
1225 if ((fd == -1) || !(fp = fdopen(fd, "w")))
1226 {
1227 if (fd != -1)
1228 {
1229 close(fd);
1230 unlink_tempfile = true;
1231 }
1233 goto bail;
1234 }
1235 unlink_tempfile = true;
1236
1237
1238
1239 int i = 0;
1242 i++)
1243 {
1244 }
1246 {
1247
1248
1249
1250 mutt_error(
_(
"sync: mbox modified, but no modified messages (report this bug)"));
1252 goto bail;
1253 }
1254
1255
1256 first = i;
1257
1259
1260
1261
1264
1265
1268
1270 {
1272 snprintf(msg,
sizeof(msg),
_(
"Writing %s..."),
mailbox_path(m));
1274 }
1275
1276 for (i = first, j = 0; i < m->
msg_count; i++)
1277 {
1280
1281
1282
1283 old_offset[i - first].
valid =
true;
1288
1290 {
1291 j++;
1292
1294 {
1296 {
1298 goto bail;
1299 }
1300 }
1301
1302
1303
1304
1305 new_offset[i - first].
hdr = ftello(fp) + offset;
1306
1311 if (rc2 != 0)
1312 {
1314 goto bail;
1315 }
1316
1317
1318
1319
1320
1321
1324
1326 {
1329 {
1331 goto bail;
1332 }
1333 break;
1334 default:
1335 if (fputs(
"\n",
fp) == EOF)
1336 {
1338 goto bail;
1339 }
1340 }
1341 }
1342 }
1343
1345 {
1348 goto bail;
1349 }
1350
1351
1353 {
1355 goto bail;
1356 }
1357
1358 unlink_tempfile = false;
1359
1362 {
1369 goto fatal;
1370 }
1371
1373
1374 !fgets(buf,
sizeof(buf), adata->
fp) ||
1377 {
1380 i = -1;
1381 }
1382 else
1383 {
1385 {
1386 i = -1;
1387 }
1388 else
1389 {
1390
1391
1395
1396 if (ferror(adata->
fp))
1397 i = -1;
1398 }
1399 if (i >= 0)
1400 {
1401 m->
size = ftello(adata->
fp);
1402 if ((m->
size < 0) || (ftruncate(fileno(adata->
fp), m->
size) != 0))
1403 {
1404 i = -1;
1406 }
1407 }
1408 }
1409
1413
1415 {
1416
1417
1419
1431 goto fatal;
1432 }
1433
1434
1436
1437
1440 {
1442 }
1444 {
1448 mutt_error(
_(
"Fatal error! Could not reopen mailbox!"));
1451 goto fatal;
1452 }
1453
1454
1455 for (i = first, j = first; i < m->
msg_count; i++)
1456 {
1458 {
1463 }
1464 }
1470
1472 if (c_check_mbox_size)
1473 {
1477 }
1478
1480 return 0;
1481
1482bail:
1483
1485
1486 if (tempfile && unlink_tempfile)
1488
1489
1490 if ((first >= 0) && old_offset)
1491 {
1492 for (i = first; (i < m->
msg_count) && old_offset[i - first].valid; i++)
1493 {
1499 }
1500 }
1501
1502
1504
1508
1511 {
1514 goto fatal;
1515 }
1516
1518 if (need_sort)
1519 {
1520
1521
1523 }
1524
1525fatal:
1528 return rc;
1529}
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
static const char * mutt_buffer_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
unsigned char cs_subset_enum(const struct ConfigSubset *sub, const char *name)
Get a enumeration 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 mutt_body_free(struct Body **ptr)
Free a Body.
int mutt_file_copy_stream(FILE *fp_in, FILE *fp_out)
Copy the contents of one file into another.
int mutt_file_fclose(FILE **fp)
Close a FILE handle (and NULL the pointer)
bool mutt_file_seek(FILE *fp, LOFF_T offset, int whence)
Wrapper for fseeko with error handling.
char * ShortHostname
Short version of the hostname.
char * Username
User's login name.
#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.
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
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.
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
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 mutt_buffer_pretty_mailbox(struct Buffer *buf)
Shorten a mailbox path using '~' or '='.
#define mutt_buffer_mktemp(buf)
int mx_msg_close(struct Mailbox *m, struct Message **msg)
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, int msgno)
Return a stream pointer for a message.
@ MX_STATUS_REOPENED
Mailbox was reopened.
@ MX_STATUS_NEW_MAIL
New mail received in Mailbox.
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
void mutt_sig_block(void)
Block signals during critical operations.
void mutt_sig_unblock(void)
Restore previously blocked signals.
@ SORT_ORDER
Sort by the order the messages appear in the mailbox.
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.
int msgno
Number displayed to the user.
Store of new offsets, used by mutt_sync_mailbox()
bool has_new
Mailbox has new mail.
off_t size
Size of the Mailbox.
Mbox-specific Account data -.
A local copy of an email.
FILE * fp
pointer to the message data
int cs_subset_str_native_set(const struct ConfigSubset *sub, const char *name, intptr_t value, struct Buffer *err)
Natively set the value of a string config item.