1064{
1068
1069 struct Buffer *tempfile = NULL;
1070 char buf[32] = { 0 };
1071 int j;
1072 bool unlink_tempfile = false;
1073 bool need_sort = false;
1074 int first = -1;
1075 LOFF_T offset;
1076 struct stat st = { 0 };
1077 struct MUpdate *new_offset = NULL;
1078 struct MUpdate *old_offset = NULL;
1079 FILE *fp = NULL;
1080 struct Progress *progress = NULL;
1082
1083
1087 {
1093 need_sort = true;
1094 }
1095
1096
1097
1100 {
1102 mutt_error(
_(
"Fatal error! Could not reopen mailbox!"));
1103 goto fatal;
1104 }
1105
1107
1109 {
1112 goto bail;
1113 }
1114
1115
1118 {
1119
1120 rc = check;
1121 goto bail;
1122 }
1123 else if (check < 0)
1124 {
1125 goto fatal;
1126 }
1127
1128
1131 int fd = open(
buf_string(tempfile), O_WRONLY | O_EXCL | O_CREAT, 0600);
1132 if ((fd == -1) || !(fp = fdopen(fd, "w")))
1133 {
1134 if (fd != -1)
1135 {
1136 close(fd);
1137 unlink_tempfile = true;
1138 }
1140 goto bail;
1141 }
1142 unlink_tempfile = true;
1143
1144
1145
1146 int i = 0;
1149 i++)
1150 {
1151 }
1153 {
1154
1155
1156
1157 mutt_error(
_(
"sync: mbox modified, but no modified messages (report this bug)"));
1159 goto bail;
1160 }
1161
1162
1163 first = i;
1164
1166
1167
1168
1171
1172
1175
1177 {
1179 snprintf(msg,
sizeof(msg),
_(
"Writing %s..."),
mailbox_path(m));
1181 }
1182
1183 for (i = first, j = 0; i < m->
msg_count; i++)
1184 {
1186
1187
1188
1189 old_offset[i - first].
valid =
true;
1194
1196 {
1197 j++;
1198
1200 {
1202 {
1204 goto bail;
1205 }
1206 }
1207
1208
1209
1210
1211 new_offset[i - first].
hdr = ftello(fp) + offset;
1212
1217 if (rc2 != 0)
1218 {
1220 goto bail;
1221 }
1222
1223
1224
1225
1226
1227
1230
1232 {
1234 {
1236 goto bail;
1237 }
1238 }
1239 else
1240 {
1241 if (fputs(
"\n",
fp) == EOF)
1242 {
1244 goto bail;
1245 }
1246 }
1247 }
1248 }
1249
1251 {
1254 goto bail;
1255 }
1256
1257
1259 {
1261 goto bail;
1262 }
1263
1264 unlink_tempfile = false;
1265
1268 {
1275 goto fatal;
1276 }
1277
1279
1280 !fgets(buf,
sizeof(buf), adata->
fp) ||
1283 {
1286 i = -1;
1287 }
1288 else
1289 {
1291 {
1292 i = -1;
1293 }
1294 else
1295 {
1296
1297
1301
1302 if (ferror(adata->
fp))
1303 i = -1;
1304 }
1305 if (i >= 0)
1306 {
1307 m->
size = ftello(adata->
fp);
1308 if ((m->
size < 0) || (ftruncate(fileno(adata->
fp), m->
size) != 0))
1309 {
1310 i = -1;
1312 }
1313 }
1314 }
1315
1319
1321 {
1322
1323
1325
1337 goto fatal;
1338 }
1339
1340
1342
1343
1346 {
1348 }
1350 {
1354 mutt_error(
_(
"Fatal error! Could not reopen mailbox!"));
1357 goto fatal;
1358 }
1359
1360
1361 for (i = first, j = first; i < m->
msg_count; i++)
1362 {
1364 {
1369 }
1370 }
1376
1378 if (c_check_mbox_size)
1379 {
1383 }
1384
1386 return 0;
1387
1388bail:
1389
1391
1392 if (tempfile && unlink_tempfile)
1394
1395
1396 if ((first >= 0) && old_offset)
1397 {
1398 for (i = first; (i < m->
msg_count) && old_offset[i - first].valid; i++)
1399 {
1405 }
1406 }
1407
1408
1410
1414
1417 {
1420 goto fatal;
1421 }
1422
1424 if (need_sort)
1425 {
1426
1427
1429 }
1430
1431fatal:
1434 return rc;
1435}
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".
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 buf_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.
SortType
Methods for sorting.
@ 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.
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.