mbox-sync-update.c revision 84e1634acc701d14e358e27f1beff5ad74f5004a
a8c5a86d183db25a57bf193c06b41e092ec2e151Timo Sirainen/* Copyright (C) 2004 Timo Sirainen */
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainenstatic void status_flags_append(struct mbox_sync_mail_context *ctx,
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainen if ((ctx->mail.flags & flags_list[i].flag) != 0)
d6af1e63bc7824f1cc5b9b73a1c5f8f8789788d6Timo Sirainenvoid mbox_sync_move_buffer(struct mbox_sync_mail_context *ctx,
0e3f8c6edad565112d91f0a53568c0313d657e48Timo Sirainen /* FIXME: if (diff < ctx->space && pos < ctx->offset) then
0e3f8c6edad565112d91f0a53568c0313d657e48Timo Sirainen move the data only up to space offset and give/take the
0e3f8c6edad565112d91f0a53568c0313d657e48Timo Sirainen space from there. update header_last_change accordingly.
0e3f8c6edad565112d91f0a53568c0313d657e48Timo Sirainen (except pos and offset can't be compared directly) */
d5cebe7f98e63d4e2822863ef2faa4971e8b3a5dTimo Sirainen for (i = 0; i < MBOX_HDR_COUNT; i++) {
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainenstatic void status_flags_replace(struct mbox_sync_mail_context *ctx, size_t pos,
6a9f9a5101b665fd2ef80c9e048a5eace78e01efTimo Sirainen unsigned char *data;
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainen /* how many bytes do we need? */
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainen for (i = 0, need = 0; flags_list[i].chr != 0; i++) {
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen if ((ctx->mail.flags & flags_list[i].flag) != 0)
a3ea111cfdbfd4f32baeb0bd7f1d72568c60a023Timo Sirainen /* how many bytes do we have now? */
8d80659e504ffb34bb0c6a633184fece35751b18Timo Sirainen data = buffer_get_modifyable_data(ctx->header, &size);
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainen /* see if this is unknown flag for us */
1f57716285d4c5bc9bf2fd5569e3c85fd496afd9Timo Sirainen /* save this one */
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainen /* @UNSAFE */
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainen data = buffer_get_space_unsafe(ctx->header, pos, need);
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainen for (i = 0, need = 0; flags_list[i].chr != 0; i++) {
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen if ((ctx->mail.flags & flags_list[i].flag) != 0)
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainenstatic void keywords_append(struct mbox_sync_context *sync_ctx, string_t *dest,
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainen ARRAY_SET_TYPE(keyword_indexes_arr, unsigned int);
a29a5b7520f7b8d6cdaf97e66d184b6a9e4f4ecfTimo Sirainen const char *const *keyword_names;
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainen const unsigned int *keyword_indexes;
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen keyword_names = array_get(sync_ctx->ibox->keyword_names,
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainen keyword_indexes = array_get(keyword_indexes_arr, &idx_count);
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainen for (i = 0, last_break = 0; i < idx_count; i++) {
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainen i_assert(keyword_indexes[i] < keywords_count);
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainen /* try avoid overly long lines but cutting them
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainen every 70 chars or so */
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainen str_append(dest, keyword_names[keyword_indexes[i]]);
b09be485e9373be4288f5615bbce6ebed65a425aTimo Sirainenkeywords_append_all(struct mbox_sync_mail_context *ctx, string_t *dest)
b09be485e9373be4288f5615bbce6ebed65a425aTimo Sirainen const char *const *names;
b09be485e9373be4288f5615bbce6ebed65a425aTimo Sirainen const unsigned char *p;
b09be485e9373be4288f5615bbce6ebed65a425aTimo Sirainen unsigned int i, count;
b09be485e9373be4288f5615bbce6ebed65a425aTimo Sirainen /* set last_break to beginning of line */
b09be485e9373be4288f5615bbce6ebed65a425aTimo Sirainen for (last_break = str_len(dest); last_break > 0; last_break--) {
22c1ec434d7323e125c150e3fd237316c74de6d5Timo Sirainen names = array_get(ctx->sync_ctx->ibox->keyword_names, &count);
743c3ba9d4b06d4797d06136ec53a4a652422a57Timo Sirainen for (i = 0; i < count; i++) {
22c1ec434d7323e125c150e3fd237316c74de6d5Timo Sirainen /* try avoid overly long lines but cutting them
b09be485e9373be4288f5615bbce6ebed65a425aTimo Sirainen every 70 chars or so */
b09be485e9373be4288f5615bbce6ebed65a425aTimo Sirainenstatic void mbox_sync_add_missing_headers(struct mbox_sync_mail_context *ctx)
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainen old_hdr_size = ctx->body_offset - ctx->hdr_offset;
9453e8d75cfd8fab2232cf772e9b120f308fb3eeTimo Sirainen str_data(ctx->header)[new_hdr_size-1] != '\n') {
9453e8d75cfd8fab2232cf772e9b120f308fb3eeTimo Sirainen /* broken header - doesn't end with \n. fix it. */
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainen ctx->hdr_pos[MBOX_HDR_X_IMAPBASE] == (size_t)-1) {
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen i_assert(ctx->sync_ctx->base_uid_validity != 0);
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainen ctx->hdr_pos[MBOX_HDR_X_IMAPBASE] = str_len(ctx->header);
const char *hdr, *p;
if (p == NULL) {
t_push();
t_pop();
t_push();
t_pop();
t_push();
t_pop();
int keywords_changed;
if (keywords_changed)