Commit a1278648 a1278648c641baf2dd390e407f61d748ceeaa3d3 by Sergey Poznyakoff

Minor fixes.

* libmailutils/base/argcvjoin.c (mu_argcv_join): Fix a
memory allocation error.
* libmailutils/base/msgid.c (concat): Remove.
(mu_rfc2822_references,mu_rfc2822_in_reply_to): Use mu_argcv_join
to concatenate strings.
1 parent bd8b9b79
...@@ -72,7 +72,7 @@ mu_argcv_join (int argc, char **argv, char *delim, enum mu_argcv_escape esc, ...@@ -72,7 +72,7 @@ mu_argcv_join (int argc, char **argv, char *delim, enum mu_argcv_escape esc,
72 if (quote) 72 if (quote)
73 len += 2; 73 len += 2;
74 74
75 buffer = realloc (buffer, len); 75 buffer = realloc (buffer, len + 1);
76 if (buffer == NULL) 76 if (buffer == NULL)
77 return ENOMEM; 77 return ENOMEM;
78 78
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
32 #include <mailutils/io.h> 32 #include <mailutils/io.h>
33 #include <mailutils/envelope.h> 33 #include <mailutils/envelope.h>
34 #include <mailutils/errno.h> 34 #include <mailutils/errno.h>
35 #include <mailutils/argcv.h>
35 36
36 #define ST_INIT 0 37 #define ST_INIT 0
37 #define ST_MSGID 1 38 #define ST_MSGID 1
...@@ -82,27 +83,6 @@ get_msgid_header (mu_header_t hdr, const char *name, char **val) ...@@ -82,27 +83,6 @@ get_msgid_header (mu_header_t hdr, const char *name, char **val)
82 return strip_message_id (p, val); 83 return strip_message_id (p, val);
83 } 84 }
84 85
85 static char *
86 concat (const char *s1, const char *s2)
87 {
88 int len = (s1 ? strlen (s1) : 0) + (s2 ? strlen (s2) : 0) + 2;
89 char *s = malloc (len);
90 if (s)
91 {
92 char *p = s;
93
94 if (s1)
95 {
96 strcpy (p, s1);
97 p += strlen (s1);
98 *p++ = ' ';
99 }
100 if (s2)
101 strcpy (p, s2);
102 }
103 return s;
104 }
105
106 /* rfc2822: 86 /* rfc2822:
107 87
108 The "References:" field will contain the contents of the parent's 88 The "References:" field will contain the contents of the parent's
...@@ -119,25 +99,30 @@ concat (const char *s1, const char *s2) ...@@ -119,25 +99,30 @@ concat (const char *s1, const char *s2)
119 int 99 int
120 mu_rfc2822_references (mu_message_t msg, char **pstr) 100 mu_rfc2822_references (mu_message_t msg, char **pstr)
121 { 101 {
122 char *ref = NULL, *msgid = NULL; 102 char *argv[3] = { NULL, NULL, NULL };
123 mu_header_t hdr; 103 mu_header_t hdr;
124 int rc; 104 int rc;
125 105
126 rc = mu_message_get_header (msg, &hdr); 106 rc = mu_message_get_header (msg, &hdr);
127 if (rc) 107 if (rc)
128 return rc; 108 return rc;
129 get_msgid_header (hdr, MU_HEADER_MESSAGE_ID, &msgid); 109 get_msgid_header (hdr, MU_HEADER_MESSAGE_ID, &argv[1]);
130 if (get_msgid_header (hdr, MU_HEADER_REFERENCES, &ref)) 110 if (get_msgid_header (hdr, MU_HEADER_REFERENCES, &argv[0]))
131 get_msgid_header (hdr, MU_HEADER_IN_REPLY_TO, &ref); 111 get_msgid_header (hdr, MU_HEADER_IN_REPLY_TO, &argv[0]);
132 112
133 if (ref || msgid) 113 if (argv[0] && argv[1])
134 { 114 {
135 *pstr = concat (ref, msgid); 115 rc = mu_argcv_join (2, argv, " ", mu_argcv_escape_no, pstr);
136 free (ref); 116 free (argv[0]);
137 free (msgid); 117 free (argv[1]);
138 return 0;
139 } 118 }
140 return MU_ERR_FAILURE; 119 else if (argv[0])
120 *pstr = argv[0];
121 else if (argv[1])
122 *pstr = argv[1];
123 else
124 rc = MU_ERR_FAILURE;
125 return rc;
141 } 126 }
142 127
143 int 128 int
...@@ -169,7 +154,6 @@ mu_rfc2822_msg_id (int subpart, char **pval) ...@@ -169,7 +154,6 @@ mu_rfc2822_msg_id (int subpart, char **pval)
169 return 0; 154 return 0;
170 } 155 }
171 156
172 #define DATEBUFSIZE 128
173 #define COMMENT "Your message of " 157 #define COMMENT "Your message of "
174 158
175 /* 159 /*
...@@ -184,47 +168,42 @@ mu_rfc2822_msg_id (int subpart, char **pval) ...@@ -184,47 +168,42 @@ mu_rfc2822_msg_id (int subpart, char **pval)
184 int 168 int
185 mu_rfc2822_in_reply_to (mu_message_t msg, char **pstr) 169 mu_rfc2822_in_reply_to (mu_message_t msg, char **pstr)
186 { 170 {
187 const char *value = NULL; 171 const char *argv[] = { NULL, NULL, NULL, NULL, NULL };
188 char *s1 = NULL, *s2 = NULL;
189 mu_header_t hdr; 172 mu_header_t hdr;
190 int rc; 173 int rc;
174 int idx = 0;
191 175
192 rc = mu_message_get_header (msg, &hdr); 176 rc = mu_message_get_header (msg, &hdr);
193 if (rc) 177 if (rc)
194 return rc; 178 return rc;
195 179
196 if (mu_header_sget_value (hdr, MU_HEADER_DATE, &value)) 180 if (mu_header_sget_value (hdr, MU_HEADER_DATE, &argv[idx + 1]))
197 { 181 {
198 mu_envelope_t envelope = NULL; 182 mu_envelope_t envelope = NULL;
199 mu_message_get_envelope (msg, &envelope); 183 mu_message_get_envelope (msg, &envelope);
200 mu_envelope_sget_date (envelope, &value); 184 mu_envelope_sget_date (envelope, &argv[idx + 1]);
201 } 185 }
202 186
203 if (value) 187 if (argv[idx + 1])
204 { 188 {
205 s1 = malloc (sizeof (COMMENT) + strlen (value)); 189 argv[idx] = COMMENT;
206 if (!s1) 190 idx = 2;
207 return ENOMEM;
208 strcat (strcpy (s1, COMMENT), value);
209 } 191 }
210 192
211 if (mu_header_sget_value (hdr, MU_HEADER_MESSAGE_ID, &value) == 0) 193 if (mu_header_sget_value (hdr, MU_HEADER_MESSAGE_ID, &argv[idx]) == 0)
212 { 194 {
213 s2 = malloc (strlen (value) + 3); 195 if (idx > 1)
214 if (!s2)
215 { 196 {
216 free (s1); 197 argv[idx + 1] = argv[idx];
217 return ENOMEM; 198 argv[idx] = "\n\t";
199 idx++;
218 } 200 }
219 strcat (strcpy (s2, "\n\t"), value); 201 idx++;
220 } 202 }
221 203
222 if (s1 || s2) 204 if (idx > 1)
223 { 205 rc = mu_argcv_join (idx, argv, "", mu_argcv_escape_no, pstr);
224 *pstr = concat (s1, s2); 206 else
225 free (s1); 207 rc = MU_ERR_FAILURE;
226 free (s2); 208 return rc;
227 return 0;
228 }
229 return MU_ERR_FAILURE;
230 } 209 }
......
...@@ -21,7 +21,7 @@ void ...@@ -21,7 +21,7 @@ void
21 make_in_reply_to (compose_env_t *env, mu_message_t msg) 21 make_in_reply_to (compose_env_t *env, mu_message_t msg)
22 { 22 {
23 char *value = NULL; 23 char *value = NULL;
24 24 wd();
25 mu_rfc2822_in_reply_to (msg, &value); 25 mu_rfc2822_in_reply_to (msg, &value);
26 compose_header_set (env, MU_HEADER_IN_REPLY_TO, value, 26 compose_header_set (env, MU_HEADER_IN_REPLY_TO, value,
27 COMPOSE_REPLACE); 27 COMPOSE_REPLACE);
...@@ -138,3 +138,9 @@ mail_reply (int argc, char **argv) ...@@ -138,3 +138,9 @@ mail_reply (int argc, char **argv)
138 return util_foreach_msg (argc, argv, MSG_NODELETED, reply0, &lower); 138 return util_foreach_msg (argc, argv, MSG_NODELETED, reply0, &lower);
139 } 139 }
140 140
141 wd()
142 {
143 int volatile _st=1;
144 while (!_st)
145 _st=_st;
146 }
......