extern int edg_wll_MaildirInit(const char *);
extern int edg_wll_MaildirStoreMsg(const char *, const char *, const char *);
-extern int edg_wll_MaildirRetryTransStart(const char *, time_t, char **, char **);
+extern int edg_wll_MaildirRetryTransStart(const char *, time_t, time_t, char **, char **);
extern int edg_wll_MaildirTransStart(const char *, char **, char **);
extern int edg_wll_MaildirTransEnd(const char *, char *, int);
LBMD_DIR_TMP = 0,
LBMD_DIR_NEW,
LBMD_DIR_WORK,
- LBMD_DIR_POST
+ LBMD_DIR_POST,
+ LBMD_DIR_UNDELIVERABLE
};
-static const char *dirs[] = { "tmp", "new", "work", "post" };
+static const char *dirs[] = { "tmp", "new", "work", "post", "undeliverable" };
#define MAX_ERR_LEN 1024
int edg_wll_MaildirRetryTransStart(
- const char *root,
- time_t tm,
- char **msg,
- char **fname)
+ const char *root,
+ time_t retry,
+ time_t remove,
+ char **msg,
+ char **fname)
{
- static DIR *dir = NULL;
- struct dirent *ent;
- time_t tlimit;
- struct stat st;
- char newfname[PATH_MAX],
- oldfname[PATH_MAX],
- *buf = NULL;
- int fhnd,
- toread, ct,
- bufsz, bufuse;
+ static DIR *dir = NULL;
+ struct dirent *ent;
+ time_t tlimit_retry, tlimit_remove;
+ struct stat st;
+ char newfname[PATH_MAX],
+ oldfname[PATH_MAX],
+ *buf = NULL;
+ int fhnd,
+ toread, ct,
+ bufsz, bufuse;
if ( !root ) root = DEFAULT_ROOT;
}
}
- tlimit = time(NULL) - tm;
+ tlimit_retry = time(NULL) - retry;
+ tlimit_remove = time(NULL) - remove;
do {
errno = 0;
if ( !(ent = readdir(dir)) ) {
goto err;
}
- if ( st.st_ctime > tlimit ) continue;
+ /* if we cannot deliver the file for 'remove' time limit, */
+ /* it is moved to undeliverable folder and forgotten */
+ if ( st.st_mtime < tlimit_remove ) {
+ snprintf(newfname, PATH_MAX, "%s/%s/%s",
+ root, dirs[LBMD_DIR_UNDELIVERABLE], ent->d_name);
+ }
+ /* try to deliver file every 'retry' seconds */
+ else if ( st.st_ctime > tlimit_retry ) continue;
+
if ( rename(oldfname, newfname) ) {
if ( errno == ENOENT ) {
goto err;
}
} else {
- /* we have found and moved the file with which we will work now */
- break;
+ if (st.st_mtime < tlimit_remove) {
+ /* we have moved undeliverable file to undeliverable folder */
+ /* no other action needed */
+ snprintf(oldfname, PATH_MAX, "%s/%s/%s", root, dirs[LBMD_DIR_TMP], ent->d_name);
+ unlink(oldfname);
+ continue;
+ } else {
+ /* we have found and moved the file to work folder */
+ /* going to process it */
+ break;
+ }
}
} while ( 1 );