@@ -213,46 +213,23 @@ def dequeue(self, filebase):
213213 mailman_log ('warning' , 'Queue file does not exist: %s (not found in backup or shunt either)' , filename )
214214 return None , None
215215
216- # Create a lock file
217- lockfile = filename + '.lock'
218- try :
219- # Try to create the lock file
220- fd = os .open (lockfile , os .O_CREAT | os .O_EXCL | os .O_WRONLY , 0o644 )
221- os .close (fd )
222- except OSError as e :
223- if e .errno != errno .EEXIST :
224- mailman_log ('error' , 'Switchboard.dequeue: Failed to create lock file for %s: %s' , filebase , str (e ))
225- raise
226- mailman_log ('debug' , 'Queue file %s is currently locked by another process' , filename )
227- return None , None
228-
216+ # Read the message object and metadata.
217+ fp = open (filename , 'rb' )
218+ # Move the file to the backup file name for processing. If this
219+ # process crashes uncleanly the .bak file will be used to re-instate
220+ # the .pck file in order to try again.
221+ os .rename (filename , bakfile )
229222 try :
230- # Read the message and metadata
231- try :
232- msg , data = self ._dequeue (filename )
233- # Add filebase to msgdata for cleanup
234- if data is not None :
235- data ['filebase' ] = filebase
236- # Log the full msgdata after dequeuing
237- mailman_log ('debug' , 'Switchboard.dequeue: Successfully dequeued file %s' , filebase )
238- except Exception as e :
239- mailman_log ('error' , 'Switchboard.dequeue: Failed to read message from %s: %s\n Traceback:\n %s' ,
240- filebase , str (e ), traceback .format_exc ())
241- raise
242-
243- # Validate data structure before returning
244- if not isinstance (data , dict ):
245- mailman_log ('error' , 'Switchboard.dequeue: Invalid data structure in %s: expected dict, got %s' ,
246- filename , type (data ))
247- return None , None
248-
249- return msg , data
223+ msg = pickle .load (fp , fix_imports = True , encoding = 'latin1' )
224+ data = pickle .load (fp , fix_imports = True , encoding = 'latin1' )
250225 finally :
251- # Always clean up the lock file
252- try :
253- os .unlink (lockfile )
254- except OSError :
255- pass
226+ fp .close ()
227+ if data .get ('_parsemsg' ):
228+ msg = email .message_from_string (msg , Message )
229+ # Add filebase to msgdata for cleanup
230+ if data is not None :
231+ data ['filebase' ] = filebase
232+ return msg , data
256233
257234 def finish (self , filebase , preserve = False ):
258235 """Finish processing a file by either removing it or moving it to the shunt queue.
0 commit comments