1068{
1072
1073 struct Buffer *tempfile = NULL;
1074 char buf[32] = { 0 };
1075 int j;
1076 bool unlink_tempfile = false;
1077 bool need_sort = false;
1078 int first = -1;
1079 LOFF_T offset;
1080 struct stat st = { 0 };
1081 struct MUpdate *new_offset = NULL;
1082 struct MUpdate *old_offset = NULL;
1083 FILE *fp = NULL;
1084 struct Progress *progress = NULL;
1086
1087
1090 {
1092 need_sort = true;
1093 }
1094
1095
1096
1099 {
1101 mutt_error(
_(
"Fatal error! Could not reopen mailbox!"));
1102 goto fatal;
1103 }
1104
1106
1108 {
1111 goto bail;
1112 }
1113
1114
1117 {
1118
1119 rc = check;
1120 goto bail;
1121 }
1122 else if (check < 0)
1123 {
1124 goto fatal;
1125 }
1126
1127
1130 int fd = open(
buf_string(tempfile), O_WRONLY | O_EXCL | O_CREAT, 0600);
1131 if ((fd == -1) || !(fp = fdopen(fd, "w")))
1132 {
1133 if (fd != -1)
1134 {
1135 close(fd);
1136 unlink_tempfile = true;
1137 }
1139 goto bail;
1140 }
1141 unlink_tempfile = true;
1142
1143
1144
1145 int i = 0;
1148 i++)
1149 {
1150 }
1152 {
1153
1154
1155
1156 mutt_error(
_(
"sync: mbox modified, but no modified messages (report this bug)"));
1158 goto bail;
1159 }
1160
1161
1162 first = i;
1163
1165
1166
1167
1170
1171
1174
1176 {
1179 }
1180
1181 for (i = first, j = 0; i < m->
msg_count; i++)
1182 {
1184
1185
1186
1187 old_offset[i - first].
valid =
true;
1192
1194 {
1195 j++;
1196
1198 {
1200 {
1202 goto bail;
1203 }
1204 }
1205
1206
1207
1208
1209 new_offset[i - first].
hdr = ftello(fp) + offset;
1210
1215 if (rc2 != 0)
1216 {
1218 goto bail;
1219 }
1220
1221
1222
1223
1224
1225
1228
1230 {
1232 {
1234 goto bail;
1235 }
1236 }
1237 else
1238 {
1239 if (fputs(
"\n",
fp) == EOF)
1240 {
1242 goto bail;
1243 }
1244 }
1245 }
1246 }
1247
1249 {
1252 goto bail;
1253 }
1254
1255
1257 {
1259 goto bail;
1260 }
1261
1262 unlink_tempfile = false;
1263
1266 {
1273 goto fatal;
1274 }
1275
1277
1278 !fgets(buf,
sizeof(buf), adata->
fp) ||
1281 {
1284 i = -1;
1285 }
1286 else
1287 {
1289 {
1290 i = -1;
1291 }
1292 else
1293 {
1294
1295
1299
1300 if (ferror(adata->
fp))
1301 i = -1;
1302 }
1303 if (i >= 0)
1304 {
1305 m->
size = ftello(adata->
fp);
1306 if ((m->
size < 0) || (ftruncate(fileno(adata->
fp), m->
size) != 0))
1307 {
1308 i = -1;
1310 }
1311 }
1312 }
1313
1316
1318 {
1319
1320
1322
1334 goto fatal;
1335 }
1336
1337
1339
1340
1343 {
1345 }
1347 {
1351 mutt_error(
_(
"Fatal error! Could not reopen mailbox!"));
1354 goto fatal;
1355 }
1356
1357
1358 for (i = first, j = first; i < m->
msg_count; i++)
1359 {
1361 {
1366 }
1367 }
1373
1375 if (c_check_mbox_size)
1376 {
1380 }
1381
1383 return 0;
1384
1385bail:
1386
1388
1389 if (tempfile && unlink_tempfile)
1391
1392
1393 if ((first >= 0) && old_offset)
1394 {
1395 for (i = first; (i < m->
msg_count) && old_offset[i - first].
valid; i++)
1396 {
1402 }
1403 }
1404
1405
1407
1411
1414 {
1417 goto fatal;
1418 }
1419
1421 if (need_sort)
1422 {
1423
1424
1426 }
1427
1428fatal:
1431 return rc;
1432}
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.