--- gateway/gw/dlr.c	2002-09-04 20:42:56.000000000 +0300
+++ gateway/gw/dlr.c	2002-09-05 10:34:54.000000000 +0300
@@ -530,7 +530,9 @@
                 /* ok that was a status report but we where not interested in having it */
                 msg = NULL;
             }
-            if ((typ & DLR_BUFFERED) && ((dlr_mask & DLR_SUCCESS) || (dlr_mask & DLR_FAIL))) {
+            if (( (typ & DLR_SMSC_SUCCESS) && (dlr_mask & (DLR_SUCCESS | DLR_BUFFERED | DLR_FAIL)) )
+            	||
+            	( (typ & DLR_BUFFERED) && (dlr_mask & (DLR_SUCCESS | DLR_FAIL)) ) ) {
                 info(0, "dlr not destroyed, still waiting for other delivery report"); 
             } else {
                 list_delete(dlr_waiting_list, i, 1);
@@ -628,8 +630,10 @@
         debug("dlr.dlr", 0, "ignoring DLR message because of mask");
     }
  
-    if ((typ & DLR_BUFFERED) && ((dlr_mask & DLR_SUCCESS) || (dlr_mask & DLR_FAIL))) {
-        debug("dlr.mysql", 0, "DLR not deleted because we wait on more reports");
+    if (( (typ & DLR_SMSC_SUCCESS) && (dlr_mask & (DLR_SUCCESS | DLR_BUFFERED | DLR_FAIL)) )
+    	||
+	( (typ & DLR_BUFFERED) && (dlr_mask & (DLR_SUCCESS | DLR_FAIL)) ) ) {
+        debug("dlr.mysql", 0, "dlr not deleted because we wait on more reports");
     } else {
         debug("dlr.mysql", 0, "removing DLR from database");
         sql = octstr_format("DELETE FROM %s WHERE %s='%s' AND %s='%s' LIMIT 1;",
