masqmail

annotate src/deliver.c @ 430:180a7f6a9383

Adds a correct cast
author markus schnalke <meillo@marmaro.de>
date Sat, 07 Feb 2015 11:14:09 +0100
parents 8fedb93e9b72
children
rev   line source
meillo@367 1 /*
meillo@367 2 ** MasqMail
meillo@367 3 ** Copyright (C) 1999-2002 Oliver Kurth
meillo@367 4 ** Copyright (C) 2008, 2010 markus schnalke <meillo@marmaro.de>
meillo@367 5 **
meillo@367 6 ** This program is free software; you can redistribute it and/or modify
meillo@367 7 ** it under the terms of the GNU General Public License as published by
meillo@367 8 ** the Free Software Foundation; either version 2 of the License, or
meillo@367 9 ** (at your option) any later version.
meillo@367 10 **
meillo@367 11 ** This program is distributed in the hope that it will be useful,
meillo@367 12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
meillo@367 13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
meillo@367 14 ** GNU General Public License for more details.
meillo@367 15 **
meillo@367 16 ** You should have received a copy of the GNU General Public License
meillo@367 17 ** along with this program; if not, write to the Free Software
meillo@367 18 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
meillo@0 19 */
meillo@0 20
meillo@0 21 #include <fnmatch.h>
meillo@0 22 #include <sysexits.h>
meillo@0 23 #include <netdb.h>
meillo@0 24
meillo@15 25 #include "masqmail.h"
meillo@15 26 #include "smtp_out.h"
meillo@15 27
meillo@367 28 /*
meillo@367 29 ** collect failed/defered rcpts for failure/warning messages
meillo@367 30 ** returns TRUE if either there are no failures or a failure message has
meillo@367 31 ** been successfully sent
meillo@367 32 */
meillo@10 33 gboolean
meillo@366 34 delivery_failures(message *msg, GList *rcpt_list, gchar *err_fmt, ...)
meillo@0 35 {
meillo@10 36 gboolean ok_fail = TRUE, ok_warn = TRUE;
meillo@10 37 time_t now = time(NULL);
meillo@0 38
meillo@10 39 GList *failed_list = NULL, *defered_list = NULL, *rcpt_node;
meillo@10 40 va_list args;
meillo@10 41 va_start(args, err_fmt);
meillo@0 42
meillo@10 43 foreach(rcpt_list, rcpt_node) {
meillo@10 44 address *rcpt = (address *) (rcpt_node->data);
meillo@10 45
meillo@10 46 if (addr_is_defered(rcpt)) {
meillo@403 47 if ((now - msg->received_time) >= conf.max_defer_time){
meillo@10 48 addr_mark_failed(rcpt);
meillo@280 49 } else {
meillo@403 50 defered_list = g_list_prepend(defered_list,
meillo@403 51 rcpt);
meillo@280 52 }
meillo@10 53 }
meillo@280 54 if (addr_is_failed(rcpt)) {
meillo@10 55 failed_list = g_list_prepend(failed_list, rcpt);
meillo@280 56 }
meillo@10 57 }
meillo@280 58 if (failed_list) {
meillo@403 59 ok_fail = fail_msg(msg, conf.errmsg_file, failed_list,
meillo@403 60 err_fmt, args);
meillo@10 61 g_list_free(failed_list);
meillo@10 62 }
meillo@280 63 if (defered_list) {
meillo@403 64 ok_warn = warn_msg(msg, conf.warnmsg_file, defered_list,
meillo@403 65 err_fmt, args);
meillo@10 66 g_list_free(defered_list);
meillo@10 67 }
meillo@10 68 va_end(args);
meillo@10 69 return ok_fail && ok_warn;
meillo@0 70 }
meillo@0 71
meillo@10 72 static gint
meillo@10 73 _g_list_strcasecmp(gconstpointer a, gconstpointer b)
meillo@0 74 {
meillo@10 75 return (gint) strcasecmp(a, b);
meillo@0 76 }
meillo@0 77
meillo@10 78 gboolean
meillo@403 79 deliver_local_mbox(message *msg, GList *hdr_list, address *rcpt,
meillo@403 80 address *env_addr)
meillo@280 81 {
meillo@280 82 DEBUG(1) debugf("attempting to deliver %s with mbox\n", msg->uid);
meillo@280 83 if (append_file(msg, hdr_list, rcpt->local_part)) {
meillo@280 84 if (env_addr != rcpt) {
meillo@403 85 logwrite(LOG_NOTICE, "%s => %s@%s <%s@%s> with mbox\n",
meillo@403 86 msg->uid, rcpt->local_part,
meillo@403 87 rcpt->domain, env_addr->local_part,
meillo@403 88 env_addr->domain);
meillo@280 89 } else {
meillo@403 90 logwrite(LOG_NOTICE, "%s => <%s@%s> with mbox\n",
meillo@403 91 msg->uid, rcpt->local_part,
meillo@403 92 rcpt->domain);
meillo@280 93 }
meillo@280 94 addr_mark_delivered(rcpt);
meillo@280 95 return TRUE;
meillo@280 96 }
meillo@280 97
meillo@280 98 /* prevents 'Resource temporarily unavailable (11)' */
meillo@280 99 if (errno != EAGAIN) {
meillo@280 100 addr_mark_failed(rcpt);
meillo@280 101 } else {
meillo@280 102 addr_mark_defered(rcpt);
meillo@280 103 }
meillo@280 104 return FALSE;
meillo@280 105 }
meillo@280 106
meillo@280 107 gboolean
meillo@403 108 deliver_local_pipe(message *msg, GList *hdr_list, address *rcpt,
meillo@403 109 address *env_addr)
meillo@280 110 {
meillo@403 111 guint flags = 0;
meillo@280 112
meillo@280 113 DEBUG(1) debugf("attempting to deliver %s with pipe\n", msg->uid);
meillo@280 114
meillo@403 115 flags |= (conf.pipe_fromline) ? MSGSTR_FROMLINE : 0;
meillo@280 116 flags |= (conf.pipe_fromhack) ? MSGSTR_FROMHACK : 0;
meillo@280 117 if (pipe_out(msg, hdr_list, rcpt, &(rcpt->local_part[1]), flags)) {
meillo@280 118 logwrite(LOG_NOTICE, "%s => %s <%s@%s> with pipe\n",
meillo@403 119 msg->uid, rcpt->local_part,
meillo@403 120 env_addr->local_part, env_addr->domain);
meillo@280 121 addr_mark_delivered(rcpt);
meillo@280 122 return TRUE;
meillo@280 123 }
meillo@280 124
meillo@280 125 if ((errno != (1024 + EX_TEMPFAIL)) && (errno != EAGAIN)) {
meillo@280 126 addr_mark_failed(rcpt);
meillo@280 127 } else {
meillo@280 128 addr_mark_defered(rcpt);
meillo@280 129 /* has no effect yet, except that mail remains in spool */
meillo@280 130 }
meillo@280 131 return FALSE;
meillo@280 132 }
meillo@280 133
meillo@280 134 gboolean
meillo@403 135 deliver_local_mda(message *msg, GList *hdr_list, address *rcpt,
meillo@403 136 address *env_addr)
meillo@280 137 {
meillo@280 138 gboolean ok = FALSE;
meillo@280 139 gchar *cmd = g_malloc(256);
meillo@280 140 GList *var_table = var_table_rcpt(var_table_msg(NULL, msg), rcpt);
meillo@403 141 guint flags = 0;
meillo@280 142
meillo@280 143 DEBUG(1) debugf("attempting to deliver %s with mda\n", msg->uid);
meillo@280 144
meillo@280 145 if (!expand(var_table, conf.mda, cmd, 256)) {
meillo@280 146 logwrite(LOG_ALERT, "could not expand string %s\n", conf.mda);
meillo@280 147 destroy_table(var_table);
meillo@280 148 return FALSE;
meillo@280 149 }
meillo@280 150
meillo@403 151 flags |= (conf.mda_fromline) ? MSGSTR_FROMLINE : 0;
meillo@280 152 flags |= (conf.mda_fromhack) ? MSGSTR_FROMHACK : 0;
meillo@280 153 if (pipe_out(msg, hdr_list, rcpt, cmd, flags)) {
meillo@280 154 logwrite(LOG_NOTICE, "%s => %s@%s with mda (cmd = '%s')\n",
meillo@403 155 msg->uid, rcpt->local_part, rcpt->domain, cmd);
meillo@280 156 addr_mark_delivered(rcpt);
meillo@280 157 ok = TRUE;
meillo@280 158 } else if ((errno != (1024 + EX_TEMPFAIL)) && (errno != EAGAIN)) {
meillo@280 159 addr_mark_failed(rcpt);
meillo@280 160 } else {
meillo@280 161 addr_mark_defered(rcpt);
meillo@280 162 /* has no effect yet, except that mail remains in spool */
meillo@280 163 }
meillo@280 164
meillo@280 165 destroy_table(var_table);
meillo@280 166 return ok;
meillo@280 167 }
meillo@280 168
meillo@280 169 gboolean
meillo@366 170 deliver_local(msg_out *msgout)
meillo@0 171 {
meillo@10 172 message *msg = msgout->msg;
meillo@10 173 GList *rcpt_list = msgout->rcpt_list;
meillo@10 174 GList *rcpt_node;
meillo@280 175 gboolean ok = FALSE, flag = FALSE, ok_fail = FALSE;
meillo@0 176
meillo@10 177 DEBUG(5) debugf("deliver_local entered\n");
meillo@0 178
meillo@10 179 flag = (msg->data_list == NULL);
meillo@280 180 if (flag && !spool_read_data(msg)) {
meillo@403 181 logwrite(LOG_ALERT, "could not open data spool file for %s\n",
meillo@403 182 msg->uid);
meillo@280 183 return FALSE;
meillo@10 184 }
meillo@0 185
meillo@403 186 for (rcpt_node = g_list_first(rcpt_list); rcpt_node;
meillo@403 187 rcpt_node = g_list_next(rcpt_node)) {
meillo@10 188 GList *hdr_list;
meillo@10 189 address *rcpt = (address *) (rcpt_node->data);
meillo@10 190 address *env_addr = addr_find_ancestor(rcpt);
meillo@10 191 address *ret_path = msg->return_path;
meillo@10 192 header *retpath_hdr, *envto_hdr;
meillo@0 193
meillo@367 194 /*
meillo@367 195 ** we need a private copy of the hdr list because we add
meillo@367 196 ** headers here that belong to the rcpt only. g_list_copy
meillo@367 197 ** copies only the nodes, so it is safe to g_list_free it
meillo@367 198 */
meillo@10 199 hdr_list = g_list_copy(msg->hdr_list);
meillo@403 200 retpath_hdr = create_header(HEAD_ENVELOPE_TO,
meillo@403 201 "Envelope-to: %s\n", addr_string(env_addr));
meillo@403 202 envto_hdr = create_header(HEAD_RETURN_PATH,
meillo@403 203 "Return-path: %s\n", addr_string(ret_path));
meillo@0 204
meillo@10 205 hdr_list = g_list_prepend(hdr_list, envto_hdr);
meillo@10 206 hdr_list = g_list_prepend(hdr_list, retpath_hdr);
meillo@0 207
meillo@403 208 if (*rcpt->local_part == '|') {
meillo@367 209 /*
meillo@367 210 ** probably for expanded aliases, but why not done
meillo@367 211 ** like with the mda? //meillo 2010-12-06
meillo@367 212 */
meillo@403 213 if (deliver_local_pipe(msg, hdr_list, rcpt,
meillo@403 214 env_addr)) {
meillo@10 215 ok = TRUE;
meillo@10 216 }
meillo@10 217 } else {
meillo@403 218 /* figure out which mailbox type should be used
meillo@403 219 ** for this user */
meillo@10 220 gchar *user = rcpt->local_part;
meillo@10 221 gchar *mbox_type = conf.mbox_default;
meillo@0 222
meillo@403 223 if (g_list_find_custom(conf.mbox_users, user,
meillo@403 224 _g_list_strcasecmp)) {
meillo@10 225 mbox_type = "mbox";
meillo@403 226 } else if (g_list_find_custom (conf.mda_users, user,
meillo@403 227 _g_list_strcasecmp)) {
meillo@10 228 mbox_type = "mda";
meillo@280 229 }
meillo@10 230
meillo@403 231 if (strcmp(mbox_type, "mbox")==0) {
meillo@403 232 if (deliver_local_mbox(msg, hdr_list, rcpt,
meillo@403 233 env_addr)) {
meillo@280 234 ok = TRUE;
meillo@280 235 }
meillo@280 236 } else if (strcmp(mbox_type, "mda") == 0) {
meillo@280 237 if (conf.mda) {
meillo@403 238 if (deliver_local_mda(msg, hdr_list,
meillo@403 239 rcpt, env_addr)) {
meillo@280 240 ok = TRUE;
meillo@10 241 }
meillo@10 242 } else {
meillo@403 243 logwrite(LOG_ALERT, "mbox type is "
meillo@403 244 "mda, but no mda "
meillo@403 245 "command given in "
meillo@403 246 "configuration\n");
meillo@10 247 }
meillo@10 248
meillo@280 249 } else {
meillo@403 250 logwrite(LOG_ALERT, "unknown mbox type '%s'\n",
meillo@403 251 mbox_type);
meillo@280 252 }
meillo@10 253 }
meillo@0 254
meillo@10 255 destroy_header(retpath_hdr);
meillo@10 256 destroy_header(envto_hdr);
meillo@0 257
meillo@10 258 g_list_free(hdr_list);
meillo@10 259 }
meillo@403 260 ok_fail = delivery_failures(msg, rcpt_list, "%s (%d)",
meillo@403 261 ext_strerror(errno), errno);
meillo@0 262
meillo@280 263 if (flag) {
meillo@10 264 msg_free_data(msg);
meillo@280 265 }
meillo@280 266 if (ok || ok_fail) {
meillo@10 267 deliver_finish(msgout);
meillo@280 268 }
meillo@0 269
meillo@10 270 return ok;
meillo@0 271 }
meillo@0 272
meillo@367 273 /*
meillo@367 274 ** make a list of rcpt's of a message that are local
meillo@367 275 ** return a new copy of the list
meillo@367 276 */
meillo@10 277 void
meillo@367 278 msg_rcptlist_local(GList *rcpt_list, GList **p_local_list,
meillo@367 279 GList **p_nonlocal_list)
meillo@0 280 {
meillo@10 281 GList *rcpt_node;
meillo@0 282
meillo@10 283 foreach(rcpt_list, rcpt_node) {
meillo@10 284 address *rcpt = (address *) (rcpt_node->data);
meillo@10 285 GList *dom_node;
meillo@0 286
meillo@10 287 DEBUG(5) debugf("checking address %s\n", rcpt->address);
meillo@0 288
meillo@10 289 /* search for local host list: */
meillo@10 290 foreach(conf.local_hosts, dom_node) {
meillo@403 291 if (fnmatch(dom_node->data, rcpt->domain,
meillo@403 292 FNM_CASEFOLD)==0) {
meillo@403 293 *p_local_list = g_list_append(*p_local_list,
meillo@403 294 rcpt);
meillo@403 295 DEBUG(5) debugf("<%s@%s> is local\n",
meillo@403 296 rcpt->local_part,
meillo@403 297 rcpt->domain);
meillo@10 298 break;
meillo@10 299 } else {
meillo@403 300 *p_nonlocal_list = g_list_append(
meillo@403 301 *p_nonlocal_list, rcpt);
meillo@10 302 }
meillo@10 303 }
meillo@10 304 }
meillo@0 305 }
meillo@0 306
meillo@10 307 gboolean
meillo@370 308 deliver_msglist_host_pipe(connect_route *route, GList *msgout_list,
meillo@370 309 gchar *host, GList *res_list)
meillo@0 310 {
meillo@10 311 gboolean ok = TRUE;
meillo@10 312 GList *msgout_node;
meillo@0 313
meillo@10 314 DEBUG(5) debugf("deliver_msglist_host_pipe entered\n");
meillo@0 315
meillo@10 316 foreach(msgout_list, msgout_node) {
meillo@10 317 msg_out *msgout = (msg_out *) (msgout_node->data);
meillo@280 318 gboolean flag, ok_fail = FALSE;
meillo@10 319 message *msg = msgout->msg;
meillo@10 320 GList *rcpt_node, *rcpt_list = msgout->rcpt_list;
meillo@0 321
meillo@403 322 DEBUG(1) debugf("attempting to deliver %s with pipe\n",
meillo@403 323 msg->uid);
meillo@0 324
meillo@10 325 flag = (msg->data_list == NULL);
meillo@280 326 if (flag && !spool_read_data(msg)) {
meillo@403 327 logwrite(LOG_ALERT, "could not open data spool file "
meillo@403 328 "for %s\n", msg->uid);
meillo@280 329 continue;
meillo@10 330 }
meillo@0 331
meillo@10 332 ok = FALSE;
meillo@10 333 foreach(rcpt_list, rcpt_node) {
meillo@10 334 address *rcpt = (address *) (rcpt_node->data);
meillo@10 335 gchar *cmd = g_malloc(256);
meillo@403 336 GList *var_table = var_table_rcpt(var_table_msg(NULL,
meillo@403 337 msg), rcpt);
meillo@0 338
meillo@403 339 DEBUG(1) debugf("attempting to deliver %s to %s@%s "
meillo@403 340 "with pipe\n", msg->uid,
meillo@403 341 rcpt->local_part, rcpt->domain);
meillo@10 342
meillo@280 343 if (!expand(var_table, route->pipe, cmd, 256)) {
meillo@321 344 logwrite(LOG_ALERT, "could not expand string `%s'\n", route->pipe);
meillo@321 345 destroy_table(var_table);
meillo@321 346 continue;
meillo@321 347 }
meillo@321 348
meillo@321 349 if (pipe_out(msg, msg->hdr_list, rcpt, cmd, (route->pipe_fromline ? MSGSTR_FROMLINE : 0)
meillo@321 350 | (route->pipe_fromhack ? MSGSTR_FROMHACK : 0))) {
meillo@321 351 logwrite(LOG_NOTICE, "%s => %s@%s with pipe (cmd = '%s')\n",
meillo@321 352 msg->uid, rcpt->local_part, rcpt->domain, cmd);
meillo@321 353 addr_mark_delivered(rcpt);
meillo@321 354 ok = TRUE;
meillo@280 355 } else {
meillo@321 356 logwrite(LOG_ALERT, "pipe_out '%s' failed\n", route->pipe);
meillo@10 357
meillo@321 358 if (route->connect_error_fail) {
meillo@321 359 addr_mark_failed(rcpt);
meillo@10 360 } else {
meillo@321 361 addr_mark_defered(rcpt);
meillo@10 362 }
meillo@280 363 }
meillo@10 364
meillo@10 365 destroy_table(var_table);
meillo@10 366 }
meillo@10 367 ok_fail = delivery_failures(msg, rcpt_list, "%s", strerror(errno));
meillo@10 368
meillo@280 369 if (flag) {
meillo@10 370 msg_free_data(msg);
meillo@280 371 }
meillo@280 372 if (ok || ok_fail) {
meillo@10 373 deliver_finish(msgout);
meillo@280 374 }
meillo@0 375 }
meillo@0 376
meillo@10 377 return ok;
meillo@0 378 }
meillo@0 379
meillo@367 380 /*
meillo@367 381 ** deliver list of messages to one host and finishes them if the message was
meillo@367 382 ** delivered to at least one rcpt.
meillo@367 383 ** Returns TRUE if at least one msg was delivered to at least one rcpt.
meillo@0 384 */
meillo@10 385 gboolean
meillo@367 386 deliver_msglist_host_smtp(connect_route *route, GList *msgout_list,
meillo@367 387 gchar *host, GList *res_list)
meillo@0 388 {
meillo@10 389 gboolean ok = FALSE;
meillo@10 390 GList *msgout_node;
meillo@10 391 smtp_base *psb;
meillo@178 392 gint port = 25;
meillo@0 393
meillo@10 394 /* paranoid check: */
meillo@280 395 if (!msgout_list) {
meillo@10 396 logwrite(LOG_ALERT, "Ooops: empty list of messages in deliver_msglist_host()\n");
meillo@10 397 return FALSE;
meillo@10 398 }
meillo@10 399
meillo@280 400 if (!host) {
meillo@179 401 /* XXX: what if mail_host isn't set? Is this possible? */
meillo@10 402 host = route->mail_host->address;
meillo@10 403 port = route->mail_host->port;
meillo@178 404 }
meillo@10 405
meillo@280 406 if (route->wrapper) {
meillo@372 407 psb = smtp_out_open_child(route->wrapper);
meillo@372 408 if (psb) {
meillo@372 409 psb->remote_host = host;
meillo@372 410 }
meillo@280 411 } else {
meillo@280 412 psb = smtp_out_open(host, port, res_list);
meillo@280 413 }
meillo@0 414
meillo@280 415 if (!psb) {
meillo@10 416 /* smtp_out_open() failed */
meillo@10 417 foreach(msgout_list, msgout_node) {
meillo@10 418 msg_out *msgout = (msg_out *) (msgout_node->data);
meillo@10 419 GList *rcpt_node;
meillo@10 420
meillo@280 421 for (rcpt_node = g_list_first(msgout->rcpt_list);
meillo@404 422 rcpt_node;
meillo@404 423 rcpt_node = g_list_next(rcpt_node)) {
meillo@10 424 address *rcpt = (address *) (rcpt_node->data);
meillo@280 425 gboolean ret = FALSE;
meillo@10 426
meillo@10 427 addr_unmark_delivered(rcpt);
meillo@10 428 if (route->connect_error_fail) {
meillo@10 429 addr_mark_failed(rcpt);
meillo@10 430 } else {
meillo@10 431 addr_mark_defered(rcpt);
meillo@10 432 }
meillo@280 433 if (route->wrapper) {
meillo@404 434 ret = delivery_failures(msgout->msg,
meillo@404 435 msgout->rcpt_list,
meillo@404 436 "could not open "
meillo@404 437 "wrapper:\n\t%s",
meillo@404 438 strerror(errno));
meillo@280 439 } else {
meillo@404 440 ret = delivery_failures(msgout->msg,
meillo@404 441 msgout->rcpt_list,
meillo@404 442 "could not open "
meillo@404 443 "connection to %s:%d "
meillo@404 444 ":\n\t%s", host, port,
meillo@404 445 h_errno != 0 ?
meillo@404 446 hstrerror(h_errno) :
meillo@404 447 strerror(errno));
meillo@280 448 }
meillo@280 449 if (ret) {
meillo@10 450 deliver_finish(msgout);
meillo@280 451 }
meillo@10 452 }
meillo@10 453 }
meillo@280 454 return ok;
meillo@0 455 }
meillo@280 456
meillo@404 457 set_heloname(psb, route->helo_name ? route->helo_name : conf.host_name,
meillo@404 458 route->do_correct_helo);
meillo@280 459
meillo@280 460 #ifdef ENABLE_AUTH
meillo@321 461 if (route->auth_name && route->auth_login && route->auth_secret) {
meillo@404 462 set_auth(psb, route->auth_name, route->auth_login,
meillo@404 463 route->auth_secret);
meillo@280 464 }
meillo@280 465 #endif
meillo@280 466 if (!smtp_out_init(psb, route->instant_helo)) {
meillo@280 467 /* smtp_out_init() failed */
meillo@404 468 if ((psb->error==smtp_fail) || (psb->error==smtp_trylater) ||
meillo@404 469 (psb->error==smtp_syntax)) {
meillo@280 470 smtp_out_quit(psb);
meillo@280 471
meillo@280 472 foreach(msgout_list, msgout_node) {
meillo@404 473 msg_out *msgout =
meillo@404 474 (msg_out *)(msgout_node->data);
meillo@280 475 smtp_out_mark_rcpts(psb, msgout->rcpt_list);
meillo@280 476
meillo@404 477 if (delivery_failures(msgout->msg,
meillo@404 478 msgout->rcpt_list,
meillo@404 479 "while connected with %s, "
meillo@404 480 "the server replied\n\t%s",
meillo@404 481 (route->wrapper) ?
meillo@404 482 "<wrapper>" : host,
meillo@404 483 psb->buffer)) {
meillo@280 484 deliver_finish(msgout);
meillo@280 485 }
meillo@280 486 }
meillo@280 487 }
meillo@280 488 destroy_smtpbase(psb);
meillo@280 489 return ok;
meillo@280 490 }
meillo@280 491
meillo@280 492 if (!route->do_pipelining) {
meillo@280 493 psb->use_pipelining = FALSE;
meillo@280 494 }
meillo@280 495
meillo@280 496 foreach(msgout_list, msgout_node) {
meillo@280 497 msg_out *msgout = (msg_out *) (msgout_node->data);
meillo@280 498 gboolean flag, ok_msg = FALSE, ok_fail = FALSE;
meillo@280 499 message *msg = msgout->msg;
meillo@280 500
meillo@404 501 /* we may have to read the data at this point
meillo@404 502 ** and remember if we did */
meillo@280 503 flag = (msg->data_list == NULL);
meillo@280 504 if (flag && !spool_read_data(msg)) {
meillo@404 505 logwrite(LOG_ALERT, "could not open data spool "
meillo@404 506 "file %s\n", msg->uid);
meillo@280 507 break;
meillo@280 508 }
meillo@280 509
meillo@404 510 smtp_out_msg(psb, msg, msgout->return_path, msgout->rcpt_list,
meillo@404 511 msgout->hdr_list);
meillo@280 512
meillo@404 513 ok_fail = delivery_failures(msg, msgout->rcpt_list,
meillo@404 514 "while connected with %s, the server "
meillo@404 515 "replied\n\t%s", (route->wrapper) ?
meillo@404 516 "<wrapper>" : host, psb->buffer);
meillo@280 517
meillo@280 518 if ((psb->error == smtp_eof) || (psb->error == smtp_timeout)) {
meillo@280 519 /* connection lost */
meillo@280 520 break;
meillo@280 521 } else if (psb->error != smtp_ok) {
meillo@280 522 if (g_list_next(msgout_node) && !smtp_out_rset(psb)) {
meillo@280 523 break;
meillo@280 524 }
meillo@280 525 }
meillo@280 526 ok_msg = (psb->error == smtp_ok);
meillo@280 527
meillo@280 528 if (flag) {
meillo@280 529 msg_free_data(msg);
meillo@280 530 }
meillo@280 531 if (ok_msg) {
meillo@280 532 ok = TRUE;
meillo@280 533 }
meillo@280 534 if (ok_msg || ok_fail) {
meillo@280 535 deliver_finish(msgout);
meillo@280 536 }
meillo@280 537 }
meillo@404 538 if (psb->error == smtp_ok || (psb->error == smtp_fail) ||
meillo@404 539 (psb->error == smtp_trylater) ||
meillo@404 540 (psb->error == smtp_syntax)) {
meillo@280 541 smtp_out_quit(psb);
meillo@280 542 }
meillo@280 543 destroy_smtpbase(psb);
meillo@10 544 return ok;
meillo@0 545 }
meillo@0 546
meillo@10 547 gboolean
meillo@370 548 deliver_msglist_host(connect_route *route, GList *msgout_list, gchar *host,
meillo@370 549 GList *res_list)
meillo@0 550 {
meillo@0 551
meillo@311 552 if (route->pipe) {
meillo@311 553 DEBUG(5) debugf("with pipe\n");
meillo@404 554 return deliver_msglist_host_pipe(route, msgout_list,
meillo@404 555 host, res_list);
meillo@10 556 } else {
meillo@311 557 DEBUG(5) debugf("with smtp\n");
meillo@404 558 return deliver_msglist_host_smtp(route, msgout_list,
meillo@404 559 host, res_list);
meillo@10 560 }
meillo@0 561 }
meillo@0 562
meillo@0 563 /*
meillo@367 564 ** delivers messages in msgout_list using route
meillo@0 565 */
meillo@10 566 gboolean
meillo@366 567 deliver_route_msgout_list(connect_route *route, GList *msgout_list)
meillo@0 568 {
meillo@10 569 gboolean ok = FALSE;
meillo@280 570 GList *mo_ph_list;
meillo@280 571 GList *mo_ph_node;
meillo@0 572
meillo@404 573 DEBUG(5) debugf("deliver_route_msgout_list entered, route->name=%s\n",
meillo@404 574 route->name);
meillo@0 575
meillo@179 576 if (route->mail_host) {
meillo@404 577 /* easy: deliver everything to a smart host for relay */
meillo@370 578 return deliver_msglist_host(route, msgout_list, NULL,
meillo@370 579 route->resolve_list);
meillo@280 580 }
meillo@280 581
meillo@280 582 /* this is not easy... */
meillo@280 583
meillo@280 584 mo_ph_list = route_msgout_list(route, msgout_list);
meillo@280 585 /* okay, now we have ordered our messages by the hosts. */
meillo@280 586 if (!mo_ph_list) {
meillo@280 587 return FALSE;
meillo@280 588 }
meillo@280 589
meillo@367 590 /*
meillo@367 591 ** TODO: It would be nice to be able to fork for each host.
meillo@367 592 ** We cannot do that yet because of complications with finishing the
meillo@367 593 ** messages. Threads could be a solution because they use the same
meillo@367 594 ** memory. But we are not thread safe yet...
meillo@367 595 */
meillo@280 596 foreach(mo_ph_list, mo_ph_node) {
meillo@280 597 msgout_perhost *mo_ph = (msgout_perhost *) (mo_ph_node->data);
meillo@370 598 if (deliver_msglist_host(route, mo_ph->msgout_list,
meillo@370 599 mo_ph->host, route->resolve_list)) {
meillo@10 600 ok = TRUE;
meillo@10 601 }
meillo@280 602 destroy_msgout_perhost(mo_ph);
meillo@10 603 }
meillo@280 604 g_list_free(mo_ph_list);
meillo@10 605 return ok;
meillo@0 606 }
meillo@0 607
meillo@0 608 /*
meillo@367 609 ** calls route_prepare_msg()
meillo@367 610 ** delivers messages in msg_list using route by calling
meillo@367 611 ** deliver_route_msgout_list()
meillo@0 612 */
meillo@10 613 gboolean
meillo@366 614 deliver_route_msg_list(connect_route *route, GList *msgout_list)
meillo@0 615 {
meillo@10 616 GList *msgout_list_deliver = NULL;
meillo@10 617 GList *msgout_node;
meillo@10 618 gboolean ok = TRUE;
meillo@0 619
meillo@10 620 DEBUG(6) debugf("deliver_route_msg_list()\n");
meillo@0 621
meillo@10 622 foreach(msgout_list, msgout_node) {
meillo@10 623 msg_out *msgout = (msg_out *) (msgout_node->data);
meillo@10 624 msg_out *msgout_cloned = clone_msg_out(msgout);
meillo@10 625 GList *rcpt_list_non_delivered = NULL;
meillo@10 626 GList *rcpt_node;
meillo@0 627
meillo@367 628 /*
meillo@367 629 ** we have to delete already delivered rcpt's because a
meillo@367 630 ** previous route may have delivered to it
meillo@367 631 */
meillo@10 632 foreach(msgout_cloned->rcpt_list, rcpt_node) {
meillo@10 633 address *rcpt = (address *) (rcpt_node->data);
meillo@367 634 /*
meillo@367 635 ** failed addresses already have been bounced;
meillo@367 636 ** there should be a better way to handle those.
meillo@367 637 */
meillo@404 638 if (!addr_is_delivered(rcpt) &&
meillo@404 639 !addr_is_failed(rcpt) &&
meillo@404 640 !(rcpt->flags & ADDR_FLAG_LAST_ROUTE)){
meillo@10 641 rcpt_list_non_delivered = g_list_append(rcpt_list_non_delivered, rcpt);
meillo@280 642 }
meillo@10 643 }
meillo@10 644 g_list_free(msgout_cloned->rcpt_list);
meillo@10 645 msgout_cloned->rcpt_list = rcpt_list_non_delivered;
meillo@0 646
meillo@280 647 if (!msgout_cloned->rcpt_list) {
meillo@280 648 destroy_msg_out(msgout_cloned);
meillo@280 649 continue;
meillo@280 650 }
meillo@0 651
meillo@317 652 /* filter by allowed envelope sender */
meillo@404 653 if (!route_sender_is_allowed(route, msgout->msg->return_path)){
meillo@404 654 DEBUG(6) debugf("sender `%s' is not allowed for this "
meillo@404 655 "route\n", msgout->msg->return_path);
meillo@280 656 destroy_msg_out(msgout_cloned);
meillo@280 657 continue;
meillo@280 658 }
meillo@0 659
meillo@317 660 /* filter by allowed envelope rcpts */
meillo@366 661 GList *rcpt_list_allowed = NULL;
meillo@366 662 GList *rcpt_list_notallowed = NULL;
meillo@370 663 route_split_rcpts(route, msgout_cloned->rcpt_list,
meillo@370 664 &rcpt_list_allowed, &rcpt_list_notallowed);
meillo@280 665 if (!rcpt_list_allowed) {
meillo@280 666 destroy_msg_out(msgout_cloned);
meillo@280 667 continue;
meillo@280 668 }
meillo@317 669
meillo@429 670 /* filter by allowed from header */
meillo@429 671 GList *from_hdrs = NULL;
meillo@429 672 char *from_hdr = NULL;
meillo@429 673 from_hdrs = find_header(msgout->msg->hdr_list, HEAD_FROM,
meillo@429 674 NULL);
meillo@429 675 if (from_hdrs) {
meillo@429 676 from_hdr = (char *) ((header *)from_hdrs->data)->value;
meillo@429 677 if (!route_from_hdr_is_allowed(route, from_hdr)){
meillo@429 678 DEBUG(6) debugf("from hdr `%s' is not allowed for this "
meillo@429 679 "route\n", from_hdr);
meillo@429 680 destroy_msg_out(msgout_cloned);
meillo@429 681 continue;
meillo@429 682 }
meillo@429 683 }
meillo@429 684
meillo@370 685 logwrite(LOG_NOTICE, "%s using '%s'\n", msgout->msg->uid,
meillo@370 686 route->name);
meillo@10 687
meillo@280 688 g_list_free(msgout_cloned->rcpt_list);
meillo@280 689 msgout_cloned->rcpt_list = rcpt_list_allowed;
meillo@280 690
meillo@280 691 if (route->last_route) {
meillo@280 692 GList *rcpt_node;
meillo@280 693 foreach(msgout_cloned->rcpt_list, rcpt_node) {
meillo@280 694 address *rcpt = (address *) (rcpt_node->data);
meillo@280 695 rcpt->flags |= ADDR_FLAG_LAST_ROUTE;
meillo@280 696 }
meillo@280 697 }
meillo@280 698
meillo@280 699 route_prepare_msgout(route, msgout_cloned);
meillo@404 700 msgout_list_deliver = g_list_append(msgout_list_deliver,
meillo@404 701 msgout_cloned);
meillo@10 702 }
meillo@10 703
meillo@280 704 if (msgout_list_deliver) {
meillo@280 705 if (deliver_route_msgout_list(route, msgout_list_deliver)) {
meillo@10 706 ok = TRUE;
meillo@280 707 }
meillo@10 708 destroy_msg_out_list(msgout_list_deliver);
meillo@10 709 }
meillo@10 710 return ok;
meillo@0 711 }
meillo@0 712
meillo@367 713 /*
meillo@367 714 ** copy pointers of delivered addresses to the msg's non_rcpt_list,
meillo@367 715 ** to make sure that they will not be delivered again.
meillo@0 716 */
meillo@10 717 void
meillo@366 718 update_non_rcpt_list(msg_out *msgout)
meillo@0 719 {
meillo@10 720 GList *rcpt_node;
meillo@10 721 message *msg = msgout->msg;
meillo@0 722
meillo@10 723 foreach(msgout->rcpt_list, rcpt_node) {
meillo@10 724 address *rcpt = (address *) (rcpt_node->data);
meillo@280 725 if (addr_is_delivered(rcpt) || addr_is_failed(rcpt)) {
meillo@404 726 msg->non_rcpt_list = g_list_append(msg->non_rcpt_list,
meillo@404 727 rcpt);
meillo@280 728 }
meillo@10 729 }
meillo@0 730 }
meillo@0 731
meillo@367 732 /*
meillo@367 733 ** after delivery attempts, we check if there are any rcpt addresses left in
meillo@367 734 ** the message. If all addresses have been completed, the spool files will be
meillo@367 735 ** deleted, otherwise the header spool will be written back. We never changed
meillo@367 736 ** the data spool, so there is no need to write that back.
meillo@367 737 **
meillo@367 738 ** returns TRUE if all went well.
meillo@0 739 */
meillo@10 740 gboolean
meillo@366 741 deliver_finish(msg_out *msgout)
meillo@0 742 {
meillo@10 743 GList *rcpt_node;
meillo@10 744 message *msg = msgout->msg;
meillo@10 745 gboolean finished = TRUE;
meillo@0 746
meillo@10 747 update_non_rcpt_list(msgout);
meillo@0 748
meillo@367 749 /*
meillo@367 750 ** we NEVER made copies of the addresses, flags affecting addresses
meillo@367 751 ** were always set on the original address structs
meillo@367 752 */
meillo@10 753 foreach(msg->rcpt_list, rcpt_node) {
meillo@10 754 address *rcpt = (address *) (rcpt_node->data);
meillo@280 755 if (!addr_is_finished_children(rcpt)) {
meillo@10 756 finished = FALSE;
meillo@280 757 } else {
meillo@367 758 /*
meillo@367 759 ** if ALL children have been delivered, mark parent as
meillo@367 760 ** delivered. if there is one or more not delivered,
meillo@367 761 ** it must have failed, we mark the parent as failed
meillo@367 762 ** as well.
meillo@367 763 */
meillo@10 764 if (addr_is_delivered_children(rcpt)) {
meillo@10 765 addr_mark_delivered(rcpt);
meillo@10 766 } else {
meillo@10 767 addr_mark_failed(rcpt);
meillo@10 768 }
meillo@10 769 }
meillo@10 770 }
meillo@10 771
meillo@280 772 if (finished) {
meillo@280 773 if (spool_delete_all(msg)) {
meillo@10 774 logwrite(LOG_NOTICE, "%s completed.\n", msg->uid);
meillo@280 775 return TRUE;
meillo@280 776 }
meillo@280 777 return FALSE;
meillo@10 778 }
meillo@280 779
meillo@280 780 /* one not delivered address was found */
meillo@280 781 if (!spool_write(msg, FALSE)) {
meillo@404 782 logwrite(LOG_ALERT, "could not write back spool header "
meillo@404 783 "for %s\n", msg->uid);
meillo@280 784 return FALSE;
meillo@280 785 }
meillo@280 786
meillo@280 787 DEBUG(2) debugf("spool header for %s written back.\n", msg->uid);
meillo@280 788 return TRUE;
meillo@0 789 }
meillo@0 790
meillo@354 791 int
meillo@366 792 deliver_remote(GList *remote_msgout_list)
meillo@10 793 {
meillo@354 794 int ok = TRUE;
meillo@354 795 GList *route_list = NULL;
meillo@354 796 GList *route_node;
meillo@10 797 GList *rf_list = NULL;
meillo@280 798 gchar *connect_name = NULL;
meillo@0 799
meillo@354 800 if (!remote_msgout_list) {
meillo@354 801 return FALSE;
meillo@354 802 }
meillo@354 803
meillo@354 804 /* perma routes */
meillo@354 805 if (conf.perma_routes) {
meillo@354 806 DEBUG(5) debugf("processing perma_routes\n");
meillo@354 807
meillo@354 808 route_list = read_route_list(conf.perma_routes, TRUE);
meillo@354 809 foreach(route_list, route_node) {
meillo@404 810 connect_route *route =
meillo@404 811 (connect_route *) (route_node->data);
meillo@404 812 if (!deliver_route_msg_list(route,
meillo@404 813 remote_msgout_list)) {
meillo@354 814 ok = FALSE;
meillo@354 815 }
meillo@354 816 }
meillo@354 817 destroy_route_list(route_list);
meillo@354 818 }
meillo@354 819
meillo@354 820 /* query routes */
meillo@310 821 connect_name = online_query();
meillo@280 822 if (!connect_name) {
meillo@344 823 DEBUG(5) debugf("online query returned false\n");
meillo@280 824 return FALSE;
meillo@10 825 }
meillo@280 826
meillo@280 827 /* we are online! */
meillo@344 828 DEBUG(5) debugf("processing query_routes\n");
meillo@404 829 logwrite(LOG_NOTICE, "detected online configuration `%s'\n",
meillo@404 830 connect_name);
meillo@280 831
meillo@354 832 rf_list = (GList *) table_find(conf.query_routes, connect_name);
meillo@280 833 if (!rf_list) {
meillo@404 834 logwrite(LOG_ALERT, "route list with name '%s' not found.\n",
meillo@404 835 connect_name);
meillo@280 836 return FALSE;
meillo@280 837 }
meillo@280 838
meillo@321 839 route_list = read_route_list(rf_list, FALSE);
meillo@280 840 if (!route_list) {
meillo@404 841 logwrite(LOG_ALERT, "could not read route list '%s'\n",
meillo@404 842 connect_name);
meillo@280 843 return FALSE;
meillo@280 844 }
meillo@280 845
meillo@280 846 foreach(route_list, route_node) {
meillo@280 847 connect_route *route = (connect_route *) (route_node->data);
meillo@280 848 /* TODO: ok gets overwritten */
meillo@354 849 ok = deliver_route_msg_list(route, remote_msgout_list);
meillo@280 850 }
meillo@280 851 destroy_route_list(route_list);
meillo@344 852
meillo@10 853 return ok;
meillo@10 854 }
meillo@0 855
meillo@321 856 /*
meillo@367 857 ** This function splits the list of rcpt addresses
meillo@367 858 ** into local and remote addresses and processes them accordingly.
meillo@321 859 */
meillo@10 860 gboolean
meillo@366 861 deliver_msg_list(GList *msg_list, guint flags)
meillo@10 862 {
meillo@343 863 GList *msgout_list = NULL;
meillo@343 864 GList *msg_node;
meillo@280 865 GList *local_msgout_list = NULL;
meillo@354 866 GList *remote_msgout_list = NULL;
meillo@10 867 GList *msgout_node;
meillo@10 868 GList *alias_table = NULL;
meillo@387 869 GList *globalias_table = NULL;
meillo@10 870 gboolean ok = TRUE;
meillo@0 871
meillo@343 872 /* create msgout_list */
meillo@343 873 foreach(msg_list, msg_node) {
meillo@343 874 message *msg = (message *) msg_node->data;
meillo@343 875 msgout_list = g_list_append(msgout_list, create_msg_out(msg));
meillo@343 876 }
meillo@343 877
meillo@387 878 if (conf.globalias_file) {
meillo@387 879 globalias_table = table_read(conf.globalias_file, ':');
meillo@387 880 }
meillo@10 881 if (conf.alias_file) {
meillo@17 882 alias_table = table_read(conf.alias_file, ':');
meillo@10 883 }
meillo@0 884
meillo@10 885 /* sort messages for different deliveries */
meillo@10 886 foreach(msgout_list, msgout_node) {
meillo@10 887 msg_out *msgout = (msg_out *) (msgout_node->data);
meillo@10 888 GList *rcpt_list;
meillo@10 889 GList *local_rcpt_list = NULL;
meillo@237 890 GList *other_rcpt_list = NULL;
meillo@0 891
meillo@114 892 if (!spool_lock(msgout->msg->uid)) {
meillo@404 893 DEBUG(5) debugf("spool_lock(%s) failed.\n",
meillo@404 894 msgout->msg->uid);
meillo@10 895 continue;
meillo@114 896 }
meillo@114 897 DEBUG(5) debugf("spool_lock(%s)\n", msgout->msg->uid);
meillo@0 898
meillo@10 899 rcpt_list = g_list_copy(msgout->msg->rcpt_list);
meillo@10 900 if (conf.log_user) {
meillo@404 901 address *addr = create_address_qualified(conf.log_user,
meillo@404 902 TRUE, conf.host_name);
meillo@280 903 if (addr) {
meillo@10 904 rcpt_list = g_list_prepend(rcpt_list, addr);
meillo@280 905 } else {
meillo@404 906 logwrite(LOG_ALERT, "invalid log_user "
meillo@404 907 "address `%s', ignoring\n",
meillo@404 908 conf.log_user);
meillo@280 909 }
meillo@10 910 }
meillo@387 911 if (globalias_table) {
meillo@387 912 GList *globaliased_rcpt_list;
meillo@417 913
meillo@417 914 DEBUG(5) debugf("Doing globalias expansion\n");
meillo@387 915 globaliased_rcpt_list = alias_expand(globalias_table,
meillo@387 916 rcpt_list,
meillo@387 917 msgout->msg->non_rcpt_list, 1);
meillo@387 918 g_list_free(rcpt_list);
meillo@387 919 rcpt_list = globaliased_rcpt_list;
meillo@387 920 }
meillo@10 921 if (alias_table) {
meillo@10 922 GList *aliased_rcpt_list;
meillo@417 923
meillo@417 924 DEBUG(5) debugf("Doing alias expansion\n");
meillo@387 925 aliased_rcpt_list = alias_expand(alias_table,
meillo@387 926 rcpt_list,
meillo@387 927 msgout->msg->non_rcpt_list, 0);
meillo@10 928 g_list_free(rcpt_list);
meillo@10 929 rcpt_list = aliased_rcpt_list;
meillo@10 930 }
meillo@0 931
meillo@404 932 /* split_rcpts(rcpt_list, NULL, &local_rcpt_list, NULL,
meillo@404 933 ** &other_rcpt_list); */
meillo@354 934 local_rcpt_list = local_rcpts(rcpt_list);
meillo@354 935 other_rcpt_list = remote_rcpts(rcpt_list);
meillo@237 936 g_list_free(rcpt_list);
meillo@237 937
meillo@10 938 /* local recipients */
meillo@237 939 if ((flags & DLVR_LOCAL) && local_rcpt_list) {
meillo@237 940 msg_out *local_msgout = clone_msg_out(msgout);
meillo@237 941 local_msgout->rcpt_list = local_rcpt_list;
meillo@404 942 local_msgout_list = g_list_append(local_msgout_list,
meillo@404 943 local_msgout);
meillo@10 944 }
meillo@0 945
meillo@354 946 /* remote recipients, requires online delivery */
meillo@237 947 if ((flags & DLVR_ONLINE) && other_rcpt_list) {
meillo@354 948 msg_out *remote_msgout = clone_msg_out(msgout);
meillo@354 949 remote_msgout->rcpt_list = other_rcpt_list;
meillo@404 950 remote_msgout_list = g_list_append(remote_msgout_list,
meillo@404 951 remote_msgout);
meillo@10 952 }
meillo@10 953 }
meillo@0 954
meillo@280 955 if (alias_table) {
meillo@10 956 destroy_table(alias_table);
meillo@280 957 }
meillo@387 958 if (globalias_table) {
meillo@387 959 destroy_table(globalias_table);
meillo@387 960 }
meillo@0 961
meillo@354 962 /* process local/remote msgout lists -> delivery */
meillo@237 963
meillo@237 964 if (local_msgout_list) {
meillo@114 965 DEBUG(5) debugf("local_msgout_list\n");
meillo@10 966 foreach(local_msgout_list, msgout_node) {
meillo@10 967 msg_out *msgout = (msg_out *) (msgout_node->data);
meillo@280 968 if (!deliver_local(msgout)) {
meillo@10 969 ok = FALSE;
meillo@280 970 }
meillo@10 971 }
meillo@10 972 destroy_msg_out_list(local_msgout_list);
meillo@10 973 }
meillo@0 974
meillo@354 975 if (remote_msgout_list) {
meillo@354 976 DEBUG(5) debugf("remote_msgout_list\n");
meillo@354 977 deliver_remote(remote_msgout_list);
meillo@354 978 destroy_msg_out_list(remote_msgout_list);
meillo@10 979 }
meillo@10 980
meillo@344 981 /* unlock spool files */
meillo@10 982 foreach(msgout_list, msgout_node) {
meillo@10 983 msg_out *msgout = (msg_out *) (msgout_node->data);
meillo@114 984 if (spool_unlock(msgout->msg->uid)) {
meillo@404 985 DEBUG(5) debugf("spool_unlock(%s)\n",
meillo@404 986 msgout->msg->uid);
meillo@114 987 } else {
meillo@404 988 DEBUG(5) debugf("spool_unlock(%s) failed.\n",
meillo@404 989 msgout->msg->uid);
meillo@114 990 }
meillo@10 991 }
meillo@10 992 destroy_msg_out_list(msgout_list);
meillo@10 993
meillo@10 994 return ok;
meillo@0 995 }
meillo@0 996
meillo@321 997 /*
meillo@367 998 ** deliver() is called when a message has just been received
meillo@367 999 ** (mode_accept and smtp_in) and should be delivered immediately
meillo@367 1000 ** (neither -odq nor do_queue). Only this one message will be tried to
meillo@367 1001 ** deliver then.
meillo@0 1002 */
meillo@10 1003 gboolean
meillo@366 1004 deliver(message *msg)
meillo@0 1005 {
meillo@10 1006 gboolean ok;
meillo@10 1007 GList *msg_list = g_list_append(NULL, msg);
meillo@0 1008
meillo@10 1009 ok = deliver_msg_list(msg_list, DLVR_ALL);
meillo@10 1010 g_list_free(msg_list);
meillo@0 1011
meillo@10 1012 return ok;
meillo@0 1013 }