]> git.ipfire.org Git - thirdparty/HylaFAX.git/commitdiff
notify: have faxq *always* run notify
authorPatrice Fournier <pfournier@ifax.com>
Thu, 19 Jun 2008 20:42:17 +0000 (20:42 +0000)
committerPatrice Fournier <pfournier@ifax.com>
Thu, 19 Jun 2008 20:42:17 +0000 (20:42 +0000)
From Aidan:

This allows the admin to use FaxNotify to directly manipulate when
notifications are sent.  The knowledge of when to send the notify emails
is now in notify.sh.in

faxd/FaxRequest.c++
faxd/FaxRequest.h
faxd/faxQueueApp.c++
util/notify.sh.in

index 719833a9f166245faec7e6dad570f01f66396ef6..6baba2324b760bf6490438784bff487423d6b747 100644 (file)
@@ -163,6 +163,9 @@ const char* FaxRequest::opNames[18] = {
     "uucp",
     "15", "16", "17"
 };
+/*
+ * These are also used in util/notify.sh.in
+ */
 const char* FaxRequest::notifyVals[4] = {
     "none",                    // no_notice
     "when done",               // when_done
index 4ee71c9e30cf3a839adb978f35bfeaa82a10ecac..43630dca52c2edd6ff5a1f7dffdbb89a1fae5626 100644 (file)
@@ -183,8 +183,6 @@ public:
     void writeQFile();
     u_int findItem(FaxSendOp, u_int start = 0) const;
 
-    bool isNotify(u_int what) const;
-
     static bool isStrCmd(const char* cmd, u_int& ix);
     static bool isShortCmd(const char* cmd, u_int& ix);
 
@@ -206,6 +204,5 @@ private:
     fxStr      code;           // code relating to notice
 #endif
 };
-inline bool FaxRequest::isNotify(u_int what) const
-    { return (notify & (u_short) what) != 0; }
+
 #endif /* _FaxRequest_ */
index be4135d37ac6a48bf52b872299c616129f875b30..158d7a4b9e462551e8fb76da5ad10d86b324301c 100644 (file)
@@ -1716,8 +1716,7 @@ faxQueueApp::sendJobDone(Job& job, FaxRequest* req)
                    (const char*)strTime(req->tts - now), req->result.string());
                setSleep(job, req->tts);
                Trigger::post(Trigger::SEND_REQUEUE, job);
-               if (req->isNotify(FaxRequest::when_requeued))
-                   notifySender(job, Job::requeued);
+               notifySender(job, Job::requeued);
            } else {
                traceQueue(job, "SEND INCOMPLETE: retry immediately; %s",
                    req->result.string());
@@ -2284,8 +2283,8 @@ faxQueueApp::blockJob(Job& job, FaxRequest& req, const Status& r)
     req.result = r;
     updateRequest(req, job);
     traceQueue(job, "%s", r.string());
-    if (req.isNotify(FaxRequest::when_requeued) && old_state != FaxRequest::state_blocked)
-       notifySender(job, Job::blocked); 
+    if (old_state != FaxRequest::state_blocked)
+       notifySender(job, Job::blocked);
     Trigger::post(Trigger::JOB_BLOCKED, job);
 }
 
@@ -2307,8 +2306,7 @@ faxQueueApp::delayJob(Job& job, FaxRequest& req, const Status& r, time_t tts)
     traceQueue(job, "%s: requeue for %s",
            r.string(), (const char*)strTime(delay));
     setSleep(job, tts);
-    if (req.isNotify(FaxRequest::when_requeued))
-       notifySender(job, Job::requeued); 
+    notifySender(job, Job::requeued);
     Trigger::post(Trigger::JOB_DELAYED, job);
 }
 
@@ -2886,8 +2884,7 @@ faxQueueApp::deleteRequest(Job& job, FaxRequest& req, JobStatus why,
        req.pri = job.pri;                      // just in case someone cares
        req.tts = Sys::now();                   // mark job termination time
        req.writeQFile();
-       if (force || req.isNotify(FaxRequest::notify_any))
-           notifySender(job, why, duration);
+       notifySender(job, why, duration);
     } else {
        /*
         * Move failed, probably because there's no
@@ -2898,10 +2895,8 @@ faxQueueApp::deleteRequest(Job& job, FaxRequest& req, JobStatus why,
         */
        jobError(job, "rename to %s failed: %s",
            (const char*) dest, strerror(errno));
-       if (force || req.isNotify(FaxRequest::notify_any)) {
-           req.writeQFile();
-           notifySender(job, why, duration);
-       }
+       req.writeQFile();
+       notifySender(job, why, duration);
        u_int n = req.items.length();
        for (u_int i = 0; i < n; i++) {
            const FaxItem& fitem = req.items[i];
index f70fc53ef9c17c80668290072f5e464aac8f3c1a..d9b9f9156e08c30d6ad685632742386b2a1775a7 100644 (file)
@@ -119,6 +119,37 @@ COMMID=$commid
 SENDTO=$mailaddr
 export COMMID SENDTO FROMADDR TOADDR DESTINATION WHY JTIME NEXT JOBINFO
 
+# This does the grunt work of building the notify email
+do_notify()
+{
+
+
+    if [ -f etc/templates/$TEMPLATE/hook.sh ]
+    then
+        # Any hooks that the templates need
+        . etc/templates/$TEMPLATE/hook.sh
+    fi
+
+
+    if [ -n "$RETURNFILETYPE" ]; then
+        for ft in $RETURNFILETYPE
+        do
+            ATTACH_ARGS="$ATTACH_ARGS "`BuildAttachArgs $ft`
+        done
+    fi
+
+    template="etc/templates/$TEMPLATE/notify-$WHY.txt"
+    if [ "$jobtype" != "facsimile" ] && [ -f etc/templates/$TEMPLATE/notify-$WHY-page.txt ]; then
+            template="etc/templates/$TEMPLATE/notify-$WHY-page.txt"
+    fi
+
+
+    eval CreateMailMessage "$template" $ATTACH_ARGS \
+            2>$ERRORSTO | $SENDMAIL -f"$FROMADDR" -oi "$mailaddr"
+
+}
+
+
 #
 # Apply customizations.  All customizable variables should
 # be set to their non-customized defaults prior to this.
@@ -128,27 +159,25 @@ if [ -f etc/FaxNotify ]; then
     . etc/FaxNotify
 fi
 
-if [ -f etc/templates/$TEMPLATE/hook.sh ]
-then
-    # Any hooks that the templates need
-    . etc/templates/$TEMPLATE/hook.sh
-fi
+case "$WHY:$notify" in
+    "requeued:when done+requeued")  do_notify;;     # Requeued
+    "requeued:when requeued")       do_notify;;     # Requeued
+    "requeued:when done")           ;;              # Do nothing;
+    "requeued:none")                ;;              # Do nothing;
 
+    "blocked:when done+requeued")   do_notify;;     # Requeued
+    "blocked:when requeued")        do_notify;;     # Requeued
+    "blocked:when done")            ;;              # Do nothing;
+    "blocked:none")                 ;;              # Do nothing;
 
-if [ -n "$RETURNFILETYPE" ]; then
-    for ft in $RETURNFILETYPE
-    do
-       ATTACH_ARGS="$ATTACH_ARGS "`BuildAttachArgs $ft`
-    done
-fi
-
-template="etc/templates/$TEMPLATE/notify-$WHY.txt"
-if [ "$jobtype" != "facsimile" ] && [ -f etc/templates/$TEMPLATE/notify-$WHY-page.txt ]; then
-       template="etc/templates/$TEMPLATE/notify-$WHY-page.txt"
-fi
+    "done:when done+requeued")      do_notify;;     # Done
+    "done:when requeued")           ;;              # Do nothing
+    "done:when done")               do_notify;;     # Done
+    "done:none")                    ;;              # Do nothing
 
+    # Anything else is a "failure", which always runs notification
+    *)                              do_notify;;
+esac
 
-eval CreateMailMessage "$template" $ATTACH_ARGS \
-       2>$ERRORSTO | $SENDMAIL -f"$FROMADDR" -oi "$mailaddr"
 
 CleanupPrivateTmp