+
+static struct nexus *
+createpickthread(char *msgs)
+{
+ char *folder = NULL;
+ struct msgs_array msgarray = {0};
+ struct msgs_array files = {0};
+ struct nexus *ret = NULL;
+ struct nexus *c;
+ struct nexus *or;
+ struct bin_data *bd;
+ char *buf;
+ char **cp = brkstring(msgs, " \t", NULL);
+ int i;
+
+ for (; cp && *cp; cp++) {
+ switch (**cp) {
+ case '@':
+ case '+':
+ if (folder) {
+ advise("","");
+ break;
+ }
+ folder = mh_xstrdup(*cp);
+ break;
+ default:
+ app_msgarg(&msgarray, mh_xstrdup(*cp));
+ }
+ }
+
+ parse_msgs(&msgarray, folder, &files);
+
+ for (i = 0; i < files.size; i++) {
+ buf = getthreadid(files.msgs[i]);
+ if (!buf) {
+ continue;
+ }
+
+ c = createonethread(buf);
+
+ if (!ret) {
+ ret = c;
+ continue;
+ }
+
+
+ or = newnexus(TYPE_OR);
+ bd = or->data;
+ bd->right = ret;
+ bd->left = c;
+ ret = or;
+ }
+
+ mh_free0(&(files.msgs));
+ mh_free0(&(msgarray.msgs));
+
+ return ret;
+}
+
+static struct nexus *
+createonethread(char *c)
+{
+ struct nexus *ret = newnexus(TYPE_OR);
+ struct nexus *left = newnexus(TYPE_GREP);
+ struct nexus *right = newnexus(TYPE_GREP);
+ struct bin_data *bd = ret->data;
+ struct grep_data *gd = left->data;
+ char buf[BUFSIZ];
+
+ bd->left = left;
+ bd->right = right;
+ gd->header = "message-id";
+
+ snprintf(buf, sizeof(buf), "^[ \t]*<%s>", c);
+ if(!gcompile(gd, buf)) {
+ padvise(NULL, "pattern error %s", c);
+ goto error;
+ }
+
+ gd = right->data;
+ gd->header = "references";
+
+ snprintf(buf, sizeof(buf), "^[ \t]*<%s>", c);
+ if(!gcompile(gd, buf)) {
+ padvise(NULL, "pattern error in %s", c);
+ goto error;
+ }
+
+ return ret;
+
+error:
+ GREPfree(&left);
+ GREPfree(&right);
+ BINfree(&ret);
+ return NULL;
+
+}