BoundSeg * find_mask_boundary (PixelRegion *maskPR, int *num_elems, BoundaryType type, int x1, int y1, int x2, int y2) { BoundSeg *new_segs = NULL; /* The mask paramater can be any PixelRegion. If the region * has more than 1 bytes/pixel, the last byte of each pixel is * used to determine the boundary outline. */ /* Calculate the boundary */ generate_boundary (maskPR, type, x1, y1, x2, y2); /* Set the number of X segments */ *num_elems = num_segs; /* Make a copy of the boundary */ if (num_segs) { new_segs = g_new (BoundSeg, num_segs); memcpy (new_segs, tmp_segs, (sizeof (BoundSeg) * num_segs)); } /* Return the new boundary */ return new_segs; }
/** * boundary_find: * @maskPR: any PixelRegion * @type: type of bounds * @x1: left side of bounds * @y1: top side of bounds * @x2: right side of bounds * @y2: botton side of bounds * @threshold: pixel value of boundary line * @num_segs: number of returned #BoundSeg's * * This function returns an array of #BoundSeg's which describe all * outlines along pixel value @threahold, optionally within specified * bounds instead of the whole region. * * The @maskPR paramater can be any PixelRegion. If the region has * more than 1 bytes/pixel, the last byte of each pixel is used to * determine the boundary outline. * * Return value: the boundary array. **/ BoundSeg * boundary_find (PixelRegion *maskPR, BoundaryType type, int x1, int y1, int x2, int y2, guchar threshold, int *num_segs) { Boundary *boundary; g_return_val_if_fail (maskPR != NULL, NULL); g_return_val_if_fail (num_segs != NULL, NULL); boundary = generate_boundary (maskPR, type, x1, y1, x2, y2, threshold); *num_segs = boundary->num_segs; return boundary_free (boundary, FALSE); }
static int dump_me(char *name, int matchlen __attribute__((unused)), int maycreate __attribute__((unused)), void *rock) { int r; char boundary[128]; struct imapurl url; char imapurl[MAX_MAILBOX_PATH+1]; struct incremental_record *irec = (struct incremental_record *) rock; struct searchargs searchargs; struct index_state *state; unsigned *uids; unsigned *uidseq; int i, n, numuids; r = index_open(name, NULL, &state); if (r) { if (verbose) { printf("error opening %s: %s\n", name, error_message(r)); } return 0; } generate_boundary(boundary, sizeof(boundary)); printf("Content-Type: multipart/related; boundary=\"%s\"\n\n", boundary); printf("--%s\n", boundary); printf("Content-Type: text/xml\n"); printf("IMAP-Dump-Version: 0\n"); printf("\n"); printf("<imapdump uniqueid=\"%s\">\n", state->mailbox->uniqueid); memset(&url, 0, sizeof(struct imapurl)); url.server = config_servername; url.mailbox = name; imapurl_toURL(imapurl, &url); printf(" <mailbox-url>%s</mailbox-url>\n", imapurl); printf(" <incremental-uid>%d</incremental-uid>\n", irec->incruid); printf(" <nextuid>%u</nextuid>\n", state->mailbox->i.last_uid + 1); printf("\n"); memset(&searchargs, 0, sizeof(struct searchargs)); numuids = index_getuidsequence(state, &searchargs, &uids); print_seq("uidlist", NULL, uids, numuids); printf("\n"); printf(" <flags>\n"); searchargs.system_flags_set = FLAG_ANSWERED; n = index_getuidsequence(state, &searchargs, &uidseq); print_seq("flag", "name=\"\\Answered\" user=\"*\"", uidseq, n); if (uidseq) free(uidseq); searchargs.system_flags_set = FLAG_DELETED; n = index_getuidsequence(state, &searchargs, &uidseq); print_seq("flag", "name=\"\\Deleted\" user=\"*\"", uidseq, n); if (uidseq) free(uidseq); searchargs.system_flags_set = FLAG_DRAFT; n = index_getuidsequence(state, &searchargs, &uidseq); print_seq("flag", "name=\"\\Draft\" user=\"*\"", uidseq, n); if (uidseq) free(uidseq); searchargs.system_flags_set = FLAG_FLAGGED; n = index_getuidsequence(state, &searchargs, &uidseq); print_seq("flag", "name=\"\\Flagged\" user=\"*\"", uidseq, n); if (uidseq) free(uidseq); printf(" </flags>\n"); printf("</imapdump>\n"); for (i = 0; i < numuids; i++) { const char *base; size_t len; if (uids[i] < irec->incruid) { /* already dumped this message */ /* xxx could do binary search to get to the first undumped uid */ continue; } printf("\n--%s\n", boundary); printf("Content-Type: message/rfc822\n"); printf("Content-ID: %d\n", uids[i]); printf("\n"); r = mailbox_map_message(state->mailbox, uids[i], &base, &len); if (r) { if (verbose) { printf("error mapping message %d: %s\n", uids[i], error_message(r)); } break; } fwrite(base, 1, len, stdout); mailbox_unmap_message(state->mailbox, uids[i], &base, &len); } printf("\n--%s--\n", boundary); index_close(&state); return 0; }
static struct mailmime * part_new_empty(struct mailmime_content * content, struct mailmime_fields * mime_fields, const char * boundary_prefix, int force_single) { struct mailmime * build_info; clist * list; int r; int mime_type; list = NULL; if (force_single) { mime_type = MAILMIME_SINGLE; } else { switch (content->ct_type->tp_type) { case MAILMIME_TYPE_DISCRETE_TYPE: mime_type = MAILMIME_SINGLE; break; case MAILMIME_TYPE_COMPOSITE_TYPE: switch (content->ct_type->tp_data.tp_composite_type->ct_type) { case MAILMIME_COMPOSITE_TYPE_MULTIPART: mime_type = MAILMIME_MULTIPLE; break; case MAILMIME_COMPOSITE_TYPE_MESSAGE: if (strcasecmp(content->ct_subtype, "rfc822") == 0) mime_type = MAILMIME_MESSAGE; else mime_type = MAILMIME_SINGLE; break; default: goto err; } break; default: goto err; } } if (mime_type == MAILMIME_MULTIPLE) { char * attr_name; char * attr_value; struct mailmime_parameter * param; clist * parameters; char * boundary; list = clist_new(); if (list == NULL) goto err; attr_name = strdup("boundary"); boundary = generate_boundary(boundary_prefix); attr_value = boundary; if (attr_name == NULL) { free(attr_name); goto free_list; } param = mailmime_parameter_new(attr_name, attr_value); if (param == NULL) { free(attr_value); free(attr_name); goto free_list; } if (content->ct_parameters == NULL) { parameters = clist_new(); if (parameters == NULL) { mailmime_parameter_free(param); goto free_list; } } else parameters = content->ct_parameters; r = clist_append(parameters, param); if (r != 0) { clist_free(parameters); mailmime_parameter_free(param); goto free_list; } if (content->ct_parameters == NULL) content->ct_parameters = parameters; } build_info = mailmime_new(mime_type, NULL, 0, mime_fields, content, NULL, NULL, NULL, list, NULL, NULL); if (build_info == NULL) { clist_free(list); return NULL; } return build_info; free_list: clist_free(list); err: return NULL; }
static int dump_me(struct findall_data *data, void *rock) { int r; char boundary[128]; struct imapurl url; char imapurl[MAX_MAILBOX_PATH+1]; struct incremental_record *irec = (struct incremental_record *) rock; struct searchargs searchargs; struct index_state *state; unsigned *uids = NULL; unsigned *uidseq = NULL; int i, n, numuids; unsigned msgno; /* don't want partial matches */ if (!data || !data->mbname) return 0; const char *name = mbname_intname(data->mbname); r = index_open(name, NULL, &state); if (r) { if (verbose) { printf("error opening %s: %s\n", name, error_message(r)); } return 0; } generate_boundary(boundary, sizeof(boundary)); printf("Content-Type: multipart/related; boundary=\"%s\"\n\n", boundary); printf("--%s\n", boundary); printf("Content-Type: text/xml\n"); printf("IMAP-Dump-Version: 0\n"); printf("\n"); printf("<imapdump uniqueid=\"%s\">\n", state->mailbox->uniqueid); memset(&url, 0, sizeof(struct imapurl)); url.server = config_servername; url.mailbox = name; imapurl_toURL(imapurl, &url); printf(" <mailbox-url>%s</mailbox-url>\n", imapurl); printf(" <incremental-uid>%d</incremental-uid>\n", irec->incruid); printf(" <nextuid>%u</nextuid>\n", state->mailbox->i.last_uid + 1); printf("\n"); memset(&searchargs, 0, sizeof(struct searchargs)); searchargs.root = search_expr_new(NULL, SEOP_TRUE); numuids = index_getuidsequence(state, &searchargs, &uids); search_expr_free(searchargs.root); print_seq("uidlist", NULL, uids, numuids); printf("\n"); printf(" <flags>\n"); searchargs.root = systemflag_match(FLAG_ANSWERED); uidseq = NULL; n = index_getuidsequence(state, &searchargs, &uidseq); search_expr_free(searchargs.root); print_seq("flag", "name=\"\\Answered\" user=\"*\"", uidseq, n); if (uidseq) free(uidseq); searchargs.root = systemflag_match(FLAG_DELETED); uidseq = NULL; n = index_getuidsequence(state, &searchargs, &uidseq); search_expr_free(searchargs.root); print_seq("flag", "name=\"\\Deleted\" user=\"*\"", uidseq, n); if (uidseq) free(uidseq); searchargs.root = systemflag_match(FLAG_DRAFT); uidseq = NULL; n = index_getuidsequence(state, &searchargs, &uidseq); search_expr_free(searchargs.root); print_seq("flag", "name=\"\\Draft\" user=\"*\"", uidseq, n); if (uidseq) free(uidseq); searchargs.root = systemflag_match(FLAG_FLAGGED); uidseq = NULL; n = index_getuidsequence(state, &searchargs, &uidseq); search_expr_free(searchargs.root); print_seq("flag", "name=\"\\Flagged\" user=\"*\"", uidseq, n); if (uidseq) free(uidseq); printf(" </flags>\n"); printf("</imapdump>\n"); i = 0; while (i < numuids && uids[i] < irec->incruid) { /* already dumped this message */ /* xxx could do binary search to get to the first undumped uid */ i++; } for (msgno = 1; msgno <= state->exists; msgno++) { struct buf buf = BUF_INITIALIZER; struct index_map *im = &state->map[msgno-1]; struct index_record record; while (im->uid > uids[i] && i < numuids) i++; if (i >= numuids) break; if (im->uid < uids[i]) continue; /* got a match */ i++; memset(&record, 0, sizeof(struct index_record)); record.recno = im->recno; record.uid = im->uid; if (mailbox_reload_index_record(state->mailbox, &record)) continue; printf("\n--%s\n", boundary); printf("Content-Type: message/rfc822\n"); printf("Content-ID: %d\n", uids[i]); printf("\n"); r = mailbox_map_record(state->mailbox, &record, &buf); if (r) { if (verbose) { printf("error mapping message %u: %s\n", record.uid, error_message(r)); } break; } fwrite(buf.s, 1, buf.len, stdout); buf_free(&buf); } printf("\n--%s--\n", boundary); free(uids); index_close(&state); return 0; }