Commit 203c6eb3 203c6eb363274b8463ff114b3e382952a2cff8b7 by Alain Magloire

supporting CC BCC when mailing.

1 parent ad9f147e
...@@ -47,8 +47,7 @@ extern void mailer_destroy __P ((mailer_t *)); ...@@ -47,8 +47,7 @@ extern void mailer_destroy __P ((mailer_t *));
47 extern int mailer_open __P ((mailer_t, int flags)); 47 extern int mailer_open __P ((mailer_t, int flags));
48 extern int mailer_close __P ((mailer_t)); 48 extern int mailer_close __P ((mailer_t));
49 49
50 extern int mailer_send_message __P ((mailer_t, const char *from, 50 extern int mailer_send_message __P ((mailer_t, message_t));
51 const char *rcpt, int dsn, message_t));
52 /* stream settings */ 51 /* stream settings */
53 extern int mailer_get_stream __P ((mailer_t, stream_t *)); 52 extern int mailer_get_stream __P ((mailer_t, stream_t *));
54 extern int mailer_set_stream __P ((mailer_t, stream_t)); 53 extern int mailer_set_stream __P ((mailer_t, stream_t));
......
...@@ -50,6 +50,9 @@ extern int message_create __P ((message_t *, void *owner)); ...@@ -50,6 +50,9 @@ extern int message_create __P ((message_t *, void *owner));
50 extern void message_destroy __P ((message_t *, void *owner)); 50 extern void message_destroy __P ((message_t *, void *owner));
51 extern void * message_get_owner __P ((message_t)); 51 extern void * message_get_owner __P ((message_t));
52 52
53 extern int message_ref __P ((message_t));
54 #define message_unref(msg) message_destroy (&msg)
55
53 extern int message_get_header __P ((message_t, header_t *)); 56 extern int message_get_header __P ((message_t, header_t *));
54 extern int message_set_header __P ((message_t, header_t, void *owner)); 57 extern int message_set_header __P ((message_t, header_t, void *owner));
55 58
......
...@@ -74,8 +74,7 @@ struct _mailer ...@@ -74,8 +74,7 @@ struct _mailer
74 void (*_destroy) __P ((mailer_t)); 74 void (*_destroy) __P ((mailer_t));
75 int (*_open) __P ((mailer_t, int flags)); 75 int (*_open) __P ((mailer_t, int flags));
76 int (*_close) __P ((mailer_t)); 76 int (*_close) __P ((mailer_t));
77 int (*_send_message) __P ((mailer_t, const char *from, const char *rcpt, 77 int (*_send_message) __P ((mailer_t, message_t));
78 int dsn, message_t));
79 }; 78 };
80 79
81 /* Mail locks. */ 80 /* Mail locks. */
......
...@@ -52,6 +52,9 @@ struct _message ...@@ -52,6 +52,9 @@ struct _message
52 mime_t mime; 52 mime_t mime;
53 observable_t observable; 53 observable_t observable;
54 54
55 /* Reference count. */
56 int ref;
57
55 /* Holder for message_write. */ 58 /* Holder for message_write. */
56 char *hdr_buf; 59 char *hdr_buf;
57 size_t hdr_buflen; 60 size_t hdr_buflen;
......
...@@ -156,12 +156,11 @@ mailer_close (mailer_t mailer) ...@@ -156,12 +156,11 @@ mailer_close (mailer_t mailer)
156 156
157 /* messages */ 157 /* messages */
158 int 158 int
159 mailer_send_message (mailer_t mailer, const char *from, const char *rcpt, 159 mailer_send_message (mailer_t mailer, message_t msg)
160 int dsn, message_t msg)
161 { 160 {
162 if (mailer == NULL || mailer->_send_message == NULL) 161 if (mailer == NULL || mailer->_send_message == NULL)
163 return ENOSYS; 162 return ENOSYS;
164 return mailer->_send_message (mailer, from, rcpt, dsn, msg); 163 return mailer->_send_message (mailer, msg);
165 } 164 }
166 165
167 int 166 int
......
...@@ -50,6 +50,7 @@ message_create (message_t *pmsg, void *owner) ...@@ -50,6 +50,7 @@ message_create (message_t *pmsg, void *owner)
50 if (msg == NULL) 50 if (msg == NULL)
51 return ENOMEM; 51 return ENOMEM;
52 msg->owner = owner; 52 msg->owner = owner;
53 msg->ref = 1;
53 *pmsg = msg; 54 *pmsg = msg;
54 return 0; 55 return 0;
55 } 56 }
...@@ -61,6 +62,7 @@ message_destroy (message_t *pmsg, void *owner) ...@@ -61,6 +62,7 @@ message_destroy (message_t *pmsg, void *owner)
61 { 62 {
62 message_t msg = *pmsg; 63 message_t msg = *pmsg;
63 64
65 msg->ref--;
64 if (msg->owner == owner) 66 if (msg->owner == owner)
65 { 67 {
66 /* Notify the listeners. */ 68 /* Notify the listeners. */
...@@ -91,6 +93,7 @@ message_destroy (message_t *pmsg, void *owner) ...@@ -91,6 +93,7 @@ message_destroy (message_t *pmsg, void *owner)
91 if (msg->mime) 93 if (msg->mime)
92 mime_destroy (&(msg->mime)); 94 mime_destroy (&(msg->mime));
93 95
96 if (msg->ref <= 0)
94 free (msg); 97 free (msg);
95 } 98 }
96 /* Loose the link */ 99 /* Loose the link */
...@@ -98,6 +101,14 @@ message_destroy (message_t *pmsg, void *owner) ...@@ -98,6 +101,14 @@ message_destroy (message_t *pmsg, void *owner)
98 } 101 }
99 } 102 }
100 103
104 int
105 message_ref (message_t msg)
106 {
107 if (msg)
108 msg->ref++;
109 return 0;
110 }
111
101 void * 112 void *
102 message_get_owner (message_t msg) 113 message_get_owner (message_t msg)
103 { 114 {
...@@ -132,7 +143,7 @@ message_set_header (message_t msg, header_t hdr, void *owner) ...@@ -132,7 +143,7 @@ message_set_header (message_t msg, header_t hdr, void *owner)
132 return EACCES; 143 return EACCES;
133 /* Make sure we destoy the old if it was own by the mesg */ 144 /* Make sure we destoy the old if it was own by the mesg */
134 /* FIXME: I do not know if somebody has already a ref on this ? */ 145 /* FIXME: I do not know if somebody has already a ref on this ? */
135 /* header_destroy (&(msg->header), msg); */ 146 header_destroy (&(msg->header), msg);
136 msg->header = hdr; 147 msg->header = hdr;
137 return 0; 148 return 0;
138 } 149 }
...@@ -165,7 +176,7 @@ message_set_body (message_t msg, body_t body, void *owner) ...@@ -165,7 +176,7 @@ message_set_body (message_t msg, body_t body, void *owner)
165 return EACCES; 176 return EACCES;
166 /* Make sure we destoy the old if it was own by the mesg. */ 177 /* Make sure we destoy the old if it was own by the mesg. */
167 /* FIXME: I do not know if somebody has already a ref on this ? */ 178 /* FIXME: I do not know if somebody has already a ref on this ? */
168 /* body_destroy (&(msg->body), msg); */ 179 body_destroy (&(msg->body), msg);
169 msg->body = body; 180 msg->body = body;
170 return 0; 181 return 0;
171 } 182 }
...@@ -177,6 +188,9 @@ message_set_stream (message_t msg, stream_t stream, void *owner) ...@@ -177,6 +188,9 @@ message_set_stream (message_t msg, stream_t stream, void *owner)
177 return EINVAL; 188 return EINVAL;
178 if (msg->owner != owner) 189 if (msg->owner != owner)
179 return EACCES; 190 return EACCES;
191 /* Make sure we destoy the old if it was own by the mesg. */
192 /* FIXME: I do not know if somebody has already a ref on this ? */
193 stream_destroy (&(msg->stream), msg);
180 msg->stream = stream; 194 msg->stream = stream;
181 return 0; 195 return 0;
182 } 196 }
......
...@@ -72,8 +72,7 @@ typedef struct _sendmail * sendmail_t; ...@@ -72,8 +72,7 @@ typedef struct _sendmail * sendmail_t;
72 static void sendmail_destroy (mailer_t); 72 static void sendmail_destroy (mailer_t);
73 static int sendmail_open (mailer_t, int); 73 static int sendmail_open (mailer_t, int);
74 static int sendmail_close (mailer_t); 74 static int sendmail_close (mailer_t);
75 static int sendmail_send_message (mailer_t, const char *from, const char *rcpt, 75 static int sendmail_send_message (mailer_t, message_t);
76 int dsn, message_t);
77 76
78 int 77 int
79 sendmail_init (mailer_t mailer) 78 sendmail_init (mailer_t mailer)
...@@ -148,8 +147,7 @@ sendmail_close (mailer_t mailer) ...@@ -148,8 +147,7 @@ sendmail_close (mailer_t mailer)
148 } 147 }
149 148
150 static int 149 static int
151 sendmail_send_message (mailer_t mailer, const char *from, const char *rcpt, 150 sendmail_send_message (mailer_t mailer, message_t msg)
152 int dsn, message_t msg)
153 { 151 {
154 sendmail_t sendmail = mailer->data; 152 sendmail_t sendmail = mailer->data;
155 int status = 0; 153 int status = 0;
...@@ -157,8 +155,6 @@ sendmail_send_message (mailer_t mailer, const char *from, const char *rcpt, ...@@ -157,8 +155,6 @@ sendmail_send_message (mailer_t mailer, const char *from, const char *rcpt,
157 if (sendmail == NULL || msg == NULL) 155 if (sendmail == NULL || msg == NULL)
158 return EINVAL; 156 return EINVAL;
159 157
160 sendmail->dsn = dsn;
161
162 switch (sendmail->state) 158 switch (sendmail->state)
163 { 159 {
164 case SENDMAIL_NO_STATE: 160 case SENDMAIL_NO_STATE:
...@@ -173,45 +169,6 @@ sendmail_send_message (mailer_t mailer, const char *from, const char *rcpt, ...@@ -173,45 +169,6 @@ sendmail_send_message (mailer_t mailer, const char *from, const char *rcpt,
173 argvec[1] = strdup ("-oi"); 169 argvec[1] = strdup ("-oi");
174 argvec[2] = strdup ("-t"); 170 argvec[2] = strdup ("-t");
175 171
176 if (from)
177 {
178 size_t len = strlen (from) + 1;
179 char *addr = calloc (len, sizeof (char));
180 if (parseaddr (from, addr, len) == 0)
181 {
182 argc++;
183 argvec = realloc (argvec, argc * (sizeof (*argvec)));
184 argvec[argc - 1] = strdup ("-f");
185 argc++;
186 argvec = realloc (argvec, argc * (sizeof (*argvec)));
187 argvec[argc - 1] = addr;
188 }
189 else
190 free (addr);
191 }
192
193 if (rcpt)
194 {
195 const char *p = rcpt;
196 do
197 {
198 size_t len = strlen (p) + 1;
199 char *addr = calloc (len, sizeof (char));
200 if (parseaddr (rcpt, addr, len) == 0)
201 {
202 argc++;
203 argvec = realloc (argvec, argc * (sizeof (*argvec)));
204 argvec[argc - 1] = addr;
205 }
206 else
207 free (addr);
208 p = strchr (p, ',');
209 if (p != NULL)
210 p++;
211 }
212 while (p != NULL && *p != '\0');
213 }
214
215 argc++; 172 argc++;
216 argvec = realloc (argvec, argc * (sizeof (*argvec))); 173 argvec = realloc (argvec, argc * (sizeof (*argvec)));
217 argvec[argc - 1] = NULL; 174 argvec[argc - 1] = NULL;
......