- if (flags & CH_UPDATE)
- {
- if ((flags & CH_NOSTATUS) == 0)
- {
- if (h->old || h->read)
- {
- if (fputs ("Status: ", out) == EOF)
- return (-1);
-
- if (h->read)
- {
- if (fputs ("RO", out) == EOF)
- return (-1);
- }
- else if (h->old)
- {
- if (fputc ('O', out) == EOF)
- return (-1);
- }
-
- if (fputc ('\n', out) == EOF)
- return (-1);
+ if (flags & CH_UPDATE) {
+ if ((flags & CH_NOSTATUS) == 0) {
+ if (h->env->irt_changed && h->env->in_reply_to) {
+ string_list_t *listp = h->env->in_reply_to;
+
+ if (fputs ("In-Reply-To: ", out) == EOF)
+ return (-1);
+
+ for (; listp; listp = listp->next)
+ if ((fputs (listp->data, out) == EOF) || (fputc (' ', out) == EOF))
+ return (-1);
+
+ if (fputc ('\n', out) == EOF)
+ return (-1);
+ }
+
+ if (h->env->refs_changed && h->env->references) {
+ string_list_t *listp = h->env->references, *refs = NULL, *t;
+
+ if (fputs ("References: ", out) == EOF)
+ return (-1);
+
+ /* Mutt stores references in reverse order, thus we create
+ * a reordered refs list that we can put in the headers */
+ for (; listp; listp = listp->next, refs = t) {
+ t = p_new(string_list_t, 1);
+ t->data = listp->data;
+ t->next = refs;
+ }
+
+ for (; refs; refs = refs->next)
+ if ((fputs (refs->data, out) == EOF) || (fputc (' ', out) == EOF))
+ return (-1);
+
+ /* clearing refs from memory */
+ for (t = refs; refs; refs = t->next, t = refs)
+ p_delete(&refs);
+
+ if (fputc ('\n', out) == EOF)
+ return (-1);
+ }
+
+ if (h->old || h->read) {
+ if (fputs ("Status: ", out) == EOF)
+ return (-1);
+
+ if (h->read) {
+ if (fputs ("RO", out) == EOF)
+ return (-1);
+ }
+ else if (h->old) {
+ if (fputc ('O', out) == EOF)
+ return (-1);
+ }
+
+ if (fputc ('\n', out) == EOF)
+ return (-1);