- if (h->flagged || h->replied)
- {
- if (fputs ("X-Status: ", out) == EOF)
- return (-1);
-
- if (h->replied)
- {
- if (fputc ('A', out) == EOF)
- return (-1);
- }
-
- if (h->flagged)
- {
- if (fputc ('F', 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);
+ }
+
+ if (h->flagged || h->replied) {
+ if (fputs ("X-Status: ", out) == EOF)
+ return (-1);
+
+ if (h->replied) {
+ if (fputc ('A', out) == EOF)
+ return (-1);
+ }
+
+ if (h->flagged) {
+ if (fputc ('F', out) == EOF)
+ return (-1);
+ }
+
+ if (fputc ('\n', out) == EOF)
+ return (-1);