Commit aa02b2ec aa02b2ecffe339a8a3573b41a360c31eb450637f by Sergey Poznyakoff

(concat,strip_message_id,get_msgid_header): Removed

(make_in_reply_to,make_references): Rewritten using new rfc2822 functions.
1 parent e6b45504
Showing 1 changed file with 13 additions and 135 deletions
...@@ -17,148 +17,25 @@ ...@@ -17,148 +17,25 @@
17 17
18 #include "mail.h" 18 #include "mail.h"
19 19
20 #define DATEBUFSIZE 128
21
22 static char *
23 concat (const char *s1, const char *s2)
24 {
25 int len = (s1 ? strlen (s1) : 0) + (s2 ? strlen (s2) : 0) + 2;
26 char *s = malloc (len);
27 if (s)
28 {
29 char *p = s;
30
31 if (s1)
32 {
33 strcpy (p, s1);
34 p += strlen (s1);
35 *p++ = ' ';
36 }
37 if (s2)
38 strcpy (p, s2);
39 }
40 return s;
41 }
42
43 void 20 void
44 make_in_reply_to (compose_env_t *env, message_t msg) 21 make_in_reply_to (compose_env_t *env, message_t msg)
45 { 22 {
46 char *value, *s1 = NULL, *s2 = NULL; 23 char *value = NULL;
47 header_t hdr;
48
49 if (message_get_header (msg, &hdr))
50 return;
51
52 if (header_aget_value (hdr, MU_HEADER_DATE, &value))
53 {
54 envelope_t envelope = NULL;
55 value = malloc (DATEBUFSIZE);
56 if (value)
57 {
58 message_get_envelope (msg, &envelope);
59 envelope_date (envelope, value, DATEBUFSIZE, NULL);
60 }
61 }
62
63 if (value)
64 asprintf (&s1, _("Your message of %s"), value);
65
66 if (header_aget_value (hdr, MU_HEADER_MESSAGE_ID, &value) == 0)
67 {
68 asprintf (&s2, "\n\t%s", value);
69 free (value);
70 }
71
72 if (s1 || s2)
73 {
74 value = concat (s1, s2);
75 free (s1);
76 free (s2);
77 compose_header_set (env, MU_HEADER_IN_REPLY_TO, value,
78 COMPOSE_REPLACE);
79 free (value);
80 }
81 }
82
83 int
84 strip_message_id (char *msgid, char **val)
85 {
86 address_t addr;
87 char *p = strchr (msgid, '<');
88 if (!p)
89 p = msgid;
90 if (address_create (&addr, p) == 0)
91 {
92 size_t count = 0;
93 char *p;
94
95 address_get_count (addr, &count);
96 if (count != 1)
97 {
98 address_destroy (&addr);
99 return 1;
100 }
101 if (address_aget_email (addr, 1, &p))
102 return -1;
103 address_destroy (&addr);
104 *val = malloc (strlen (p) + 3);
105 if (!*val)
106 {
107 free (p);
108 return -1;
109 }
110 sprintf (*val, "<%s>", p);
111 free (p);
112 return 0;
113 }
114 return 1;
115 }
116 24
117 int 25 mu_rfc2822_in_reply_to (msg, &value);
118 get_msgid_header (header_t hdr, const char *name, char **val) 26 compose_header_set (env, MU_HEADER_IN_REPLY_TO, value,
119 { 27 COMPOSE_REPLACE);
120 char *p; 28 free (value);
121 int status = header_aget_value (hdr, name, &p);
122 if (status)
123 return status;
124 status = strip_message_id (p, val);
125 free (p);
126 return status;
127 } 29 }
128 30
129 /* rfc2822:
130
131 The "References:" field will contain the contents of the parent's
132 "References:" field (if any) followed by the contents of the parent's
133 "Message-ID:" field (if any). If the parent message does not contain
134 a "References:" field but does have an "In-Reply-To:" field
135 containing a single message identifier, then the "References:" field
136 will contain the contents of the parent's "In-Reply-To:" field
137 followed by the contents of the parent's "Message-ID:" field (if
138 any). If the parent has none of the "References:", "In-Reply-To:",
139 or "Message-ID:" fields, then the new message will have no
140 References:" field. */
141
142 void 31 void
143 make_references (compose_env_t *env, message_t msg) 32 make_references (compose_env_t *env, message_t msg)
144 { 33 {
145 char *ref = NULL, *msgid = NULL; 34 char *value = NULL;
146 header_t hdr;
147
148 if (message_get_header (msg, &hdr))
149 return;
150
151 get_msgid_header (hdr, MU_HEADER_MESSAGE_ID, &msgid);
152 if (get_msgid_header (hdr, MU_HEADER_REFERENCES, &ref))
153 get_msgid_header (hdr, MU_HEADER_IN_REPLY_TO, &ref);
154 35
155 if (ref || msgid) 36 mu_rfc2822_references (msg, &value);
156 { 37 compose_header_set (env, MU_HEADER_REFERENCES, value, COMPOSE_REPLACE);
157 char *s = concat (ref, msgid); 38 free (value);
158 free (ref);
159 free (msgid);
160 compose_header_set (env, MU_HEADER_REFERENCES, s, COMPOSE_REPLACE);
161 }
162 } 39 }
163 40
164 /* 41 /*
...@@ -176,11 +53,14 @@ reply0 (msgset_t *mspec, message_t msg, void *data) ...@@ -176,11 +53,14 @@ reply0 (msgset_t *mspec, message_t msg, void *data)
176 int status; 53 int status;
177 char *str; 54 char *str;
178 55
56 cursor = mspec->msg_part[0];
57
179 compose_init (&env); 58 compose_init (&env);
180 59
181 message_get_header (msg, &hdr); 60 message_get_header (msg, &hdr);
182 61
183 compose_header_set (&env, MU_HEADER_TO, util_get_sender (mspec->msg_part[0], 0), 62 compose_header_set (&env, MU_HEADER_TO,
63 util_get_sender (mspec->msg_part[0], 0),
184 COMPOSE_SINGLE_LINE); 64 COMPOSE_SINGLE_LINE);
185 65
186 if (*(int*) data) /* reply starts with a lowercase */ 66 if (*(int*) data) /* reply starts with a lowercase */
...@@ -240,8 +120,6 @@ reply0 (msgset_t *mspec, message_t msg, void *data) ...@@ -240,8 +120,6 @@ reply0 (msgset_t *mspec, message_t msg, void *data)
240 status = mail_send0 (&env, 0); 120 status = mail_send0 (&env, 0);
241 compose_destroy (&env); 121 compose_destroy (&env);
242 122
243 cursor = mspec->msg_part[0];
244
245 return status; 123 return status;
246 } 124 }
247 125
......