static int getmetadata(void *sc, const char *extname, const char *keyname, char **res) { script_data_t *sd = (script_data_t *)sc; struct buf attrib = BUF_INITIALIZER; char *intname = extname ? mboxname_from_external(extname, sd->ns, mbname_userid(sd->mbname)) : xstrdup(""); int r; if (!strncmp(keyname, "/private/", 9)) { r = annotatemore_lookup(intname, keyname+8, mbname_userid(sd->mbname), &attrib); } else if (!strncmp(keyname, "/shared/", 8)) { r = annotatemore_lookup(intname, keyname+7, "", &attrib); } else { r = IMAP_MAILBOX_NONEXISTENT; } *res = (r || !attrib.len) ? NULL : buf_release(&attrib); free(intname); buf_free(&attrib); return r ? 0 : 1; }
/* This is called once for each mailbox we're told to index. */ static int index_one(const char *name, int blocking) { mbentry_t *mbentry = NULL; struct mailbox *mailbox = NULL; int r; int flags = 0; if (incremental_mode) flags |= SEARCH_UPDATE_INCREMENTAL; /* Convert internal name to external */ char *extname = mboxname_to_external(name, &squat_namespace, NULL); /* Skip remote mailboxes */ r = mboxlist_lookup(name, &mbentry, NULL); if (r) { if (verbose) { printf("error looking up %s: %s\n", extname, error_message(r)); } syslog(LOG_INFO, "error looking up %s: %s\n", extname, error_message(r)); free(extname); return r; } if (mbentry->mbtype & MBTYPE_REMOTE) { mboxlist_entry_free(&mbentry); free(extname); return 0; } mboxlist_entry_free(&mbentry); /* make sure the mailbox (or an ancestor) has /vendor/cmu/cyrus-imapd/squat set to "true" */ if (annotation_flag) { char buf[MAX_MAILBOX_BUFFER] = "", *p; struct buf attrib = BUF_INITIALIZER; int domainlen = 0; if (config_virtdomains && (p = strchr(name, '!'))) domainlen = p - name + 1; strlcpy(buf, name, sizeof(buf)); /* since mailboxes inherit /vendor/cmu/cyrus-imapd/squat, we need to iterate all the way up to "" (server entry) */ while (1) { r = annotatemore_lookup(buf, IMAP_ANNOT_NS "squat", "", &attrib); if (r || /* error */ attrib.s || /* found an entry */ !buf[0]) { /* done recursing */ break; } p = strrchr(buf, '.'); /* find parent mailbox */ if (p && (p - buf > domainlen)) /* don't split subdomain */ *p = '\0'; else if (!buf[domainlen]) /* server entry */ buf[0] = '\0'; else /* domain entry */ buf[domainlen] = '\0'; } if (r || !attrib.s || strcasecmp(attrib.s, "true")) { buf_free(&attrib); free(extname); return 0; } buf_free(&attrib); } again: if (blocking) r = mailbox_open_irl(name, &mailbox); else r = mailbox_open_irlnb(name, &mailbox); if (r == IMAP_MAILBOX_LOCKED) { if (verbose) syslog(LOG_INFO, "mailbox %s locked, retrying", extname); free(extname); return r; } if (r) { if (verbose) { printf("error opening %s: %s\n", extname, error_message(r)); } syslog(LOG_INFO, "error opening %s: %s\n", extname, error_message(r)); free(extname); return r; } syslog(LOG_INFO, "indexing mailbox %s... ", extname); if (verbose > 0) { printf("Indexing mailbox %s... ", extname); } r = search_update_mailbox(rx, mailbox, flags); mailbox_close(&mailbox); /* in non-blocking (rolling) mode, only do one batch per mailbox at * a time for fairness [IRIS-2471]. The squatter will re-insert the * mailbox in the queue */ if (blocking && r == IMAP_AGAIN) goto again; free(extname); return r; }