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