@@ -304,13 +304,12 @@ def get_forwarders(self):
304304 'address' : f"{ parts [0 ]} @{ self .domain } " ,
305305 'destination' : parts [1 ]
306306 })
307- elif '@' in str (value ):
308- # Might be just the email address
307+ elif value : # Accept ANY non-empty value
309308 # Check if there's a corresponding destination key
310309 dest_key = key .replace ('select' , 'destination' )
311310 if dest_key in response :
312311 forwarders .append ({
313- 'address' : value ,
312+ 'address' : f" { value } @ { self . domain } " if '@' not in str ( value ) else str ( value ) ,
314313 'destination' : response [dest_key ]
315314 })
316315
@@ -326,35 +325,20 @@ def get_forwarders(self):
326325 'destination' : parts [1 ]
327326 })
328327
329- # Format 3: Direct email keys
328+ # Format 3: Direct key-value pairs (most common)
330329 else :
331- # Look for email addresses as keys
330+ # Look for all key-value pairs
332331 for key , value in response .items ():
333332 if key .startswith ('error' ) or key == 'domain' :
334333 continue
335334
336- # If key contains @ it's likely an email
337- if '@' in str (key ):
335+ # IMPORTANT: Accept ALL non-empty values as valid destinations
336+ if value :
337+ # Key is the username, value is the destination
338338 forwarders .append ({
339- 'address' : key ,
339+ 'address' : f" { key } @ { self . domain } " ,
340340 'destination' : str (value )
341341 })
342- # If key is a username and value contains destination
343- elif value and '=' not in str (key ):
344- # Could be username as key, destination as value
345- if '@' in str (value ):
346- forwarders .append ({
347- 'address' : f"{ key } @{ self .domain } " ,
348- 'destination' : str (value )
349- })
350- # Or could be a forward entry
351- elif '=' in str (value ):
352- parts = str (value ).split ('=' , 1 )
353- if len (parts ) == 2 :
354- forwarders .append ({
355- 'address' : f"{ parts [0 ]} @{ self .domain } " if '@' not in parts [0 ] else parts [0 ],
356- 'destination' : parts [1 ]
357- })
358342
359343 elif isinstance (response , str ):
360344 print ("Response is string, parsing..." )
@@ -390,15 +374,25 @@ def create_forwarder(self, address, destination):
390374 else :
391375 username = address
392376
393- # IMPORTANT FIX: Ensure destination is a full email address!
377+ # SMART DESTINATION HANDLING:
378+ # 1. If it has @, it's already a full email address
379+ # 2. If it starts with : (like :blackhole:, :fail:), it's a special destination
380+ # 3. If it starts with | (pipe to script), it's a special destination
381+ # 4. Otherwise, assume it's a local username and add domain
382+
394383 if '@' not in destination :
395- # If destination doesn't have @, assume it's a local user on the same domain
396- destination = f"{ destination } @{ self .domain } "
384+ # Check if it's a special destination
385+ if destination .startswith (':' ) or destination .startswith ('|' ):
386+ # Special destination - use as-is
387+ print (f"Special destination detected: { destination } " )
388+ else :
389+ # Regular username - add domain
390+ destination = f"{ destination } @{ self .domain } "
397391
398392 print (f"\n === Creating Forwarder ===" )
399393 print (f"Username: { username } " )
400394 print (f"Domain: { self .domain } " )
401- print (f"Destination (full) : { destination } " )
395+ print (f"Destination: { destination } " )
402396
403397 # Use the correct parameter format that DirectAdmin expects
404398 endpoint = '/CMD_API_EMAIL_FORWARDERS'
0 commit comments