1/* $NetBSD$ */ 2 3/*++ 4/* NAME 5/* qmgr_move 3 6/* SUMMARY 7/* move queue entries to another queue 8/* SYNOPSIS 9/* #include "qmgr.h" 10/* 11/* void qmgr_move(from, to, time_stamp) 12/* const char *from; 13/* const char *to; 14/* time_t time_stamp; 15/* DESCRIPTION 16/* The \fBqmgr_move\fR routine scans the \fIfrom\fR queue for entries 17/* with valid queue names and moves them to the \fIto\fR queue. 18/* If \fItime_stamp\fR is non-zero, the queue file time stamps are 19/* set to the specified value. 20/* Entries with invalid names are left alone. No attempt is made to 21/* look for other badness such as multiple links or weird file types. 22/* These issues are dealt with when a queue file is actually opened. 23/* LICENSE 24/* .ad 25/* .fi 26/* The Secure Mailer license must be distributed with this software. 27/* AUTHOR(S) 28/* Wietse Venema 29/* IBM T.J. Watson Research 30/* P.O. Box 704 31/* Yorktown Heights, NY 10598, USA 32/*--*/ 33 34/* System library. */ 35 36#include <sys_defs.h> 37#include <sys/stat.h> 38#include <string.h> 39#include <utime.h> 40#include <errno.h> 41 42/* Utility library. */ 43 44#include <msg.h> 45#include <scan_dir.h> 46#include <recipient_list.h> 47 48/* Global library. */ 49 50#include <mail_queue.h> 51#include <mail_scan_dir.h> 52 53/* Application-specific. */ 54 55#include "qmgr.h" 56 57/* qmgr_move - move queue entries to another queue, leave bad files alone */ 58 59void qmgr_move(const char *src_queue, const char *dst_queue, 60 time_t time_stamp) 61{ 62 const char *myname = "qmgr_move"; 63 SCAN_DIR *queue_dir; 64 char *queue_id; 65 struct utimbuf tbuf; 66 const char *path; 67 68 if (strcmp(src_queue, dst_queue) == 0) 69 msg_panic("%s: source queue %s is destination", myname, src_queue); 70 if (msg_verbose) 71 msg_info("start move queue %s -> %s", src_queue, dst_queue); 72 73 queue_dir = scan_dir_open(src_queue); 74 while ((queue_id = mail_scan_dir_next(queue_dir)) != 0) { 75 if (mail_queue_id_ok(queue_id)) { 76 if (time_stamp > 0) { 77 tbuf.actime = tbuf.modtime = time_stamp; 78 path = mail_queue_path((VSTRING *) 0, src_queue, queue_id); 79 if (utime(path, &tbuf) < 0) { 80 if (errno != ENOENT) 81 msg_fatal("%s: update %s time stamps: %m", myname, path); 82 msg_warn("%s: update %s time stamps: %m", myname, path); 83 continue; 84 } 85 } 86 if (mail_queue_rename(queue_id, src_queue, dst_queue)) { 87 if (errno != ENOENT) 88 msg_fatal("%s: rename %s from %s to %s: %m", 89 myname, queue_id, src_queue, dst_queue); 90 msg_warn("%s: rename %s from %s to %s: %m", 91 myname, queue_id, src_queue, dst_queue); 92 continue; 93 } 94 if (msg_verbose) 95 msg_info("%s: moved %s from %s to %s", 96 myname, queue_id, src_queue, dst_queue); 97 } else { 98 msg_warn("%s: ignored: queue %s id %s", 99 myname, src_queue, queue_id); 100 } 101 } 102 scan_dir_close(queue_dir); 103 104 if (msg_verbose) 105 msg_info("end move queue %s -> %s", src_queue, dst_queue); 106} 107