@@ -166,7 +166,7 @@ def get_email_accounts(self):
166166 try :
167167 print (f"\n === Getting Email Accounts for { self .domain } ===" )
168168
169- # Try multiple endpoints 【1】
169+ # Try multiple endpoints
170170 endpoints = [
171171 ('/CMD_API_POP' , {'action' : 'list' , 'domain' : self .domain }),
172172 ('/CMD_API_POP' , {'domain' : self .domain }),
@@ -245,50 +245,80 @@ def get_forwarders(self):
245245 try :
246246 print (f"\n === Getting Forwarders for { self .domain } ===" )
247247
248- endpoint = '/CMD_API_EMAIL_FORWARDERS'
249- data = {
250- 'domain' : self .domain ,
251- 'action' : 'list'
252- }
248+ # Try multiple endpoint variations
249+ endpoints = [
250+ ('/CMD_API_EMAIL_FORWARDERS' , {'domain' : self .domain , 'action' : 'list' }),
251+ ('/CMD_API_EMAIL_FORWARDERS' , {'domain' : self .domain }),
252+ ('/CMD_EMAIL_FORWARDERS' , {'domain' : self .domain }),
253+ ]
253254
254- # Try GET first, then POST
255- response = self ._make_request (endpoint , data , method = 'GET' )
256- if response is None :
257- print ("No response with GET, trying POST" )
258- response = self ._make_request (endpoint , data , method = 'POST' )
255+ response = None
256+ for endpoint , params in endpoints :
257+ print (f"\n Trying: { endpoint } with params: { params } " )
258+
259+ # Try GET first
260+ response = self ._make_request (endpoint , params , method = 'GET' )
261+ if response :
262+ print (f"Got response with GET" )
263+ break
264+
265+ # Try POST
266+ response = self ._make_request (endpoint , params , method = 'POST' )
267+ if response :
268+ print (f"Got response with POST" )
269+ break
259270
260271 if response is None :
261- print ("No response from forwarders endpoint" )
272+ print ("ERROR: No response from any forwarders endpoint! " )
262273 return []
263274
264- print (f"Raw response type: { type (response )} " )
265- print (f"Raw response: { response } " )
275+ print (f"\n === FORWARDERS RAW RESPONSE ===" )
276+ print (f"Type: { type (response )} " )
277+ print (f"Content: { response } " )
278+ print ("=" * 50 )
266279
267280 forwarders = []
268281
269282 if isinstance (response , dict ):
270- print (f"Response is dict with keys: { list (response .keys ())} " )
271-
283+ # Look for any sign of forwarders in the response
272284 for key , value in response .items ():
285+ print (f"Processing key: '{ key } ' with value: '{ value } '" )
286+
273287 if key .startswith ('error' ):
288+ print (f"Found error: { value } " )
274289 continue
275290
276- # Format: address=destination or address as key
277- if '@' in key and value :
291+ # Various possible formats
292+ if '@' in str ( key ) :
278293 forwarders .append ({
279294 'address' : key ,
280295 'destination' : str (value )
281296 })
282- # Alternative format with value containing mapping
283- elif '=' in str (value ):
297+ elif 'forward' in str (key ).lower ():
298+ print (f"Found forward-related key: { key } = { value } " )
299+ elif value and '=' in str (value ):
284300 parts = str (value ).split ('=' , 1 )
285301 if len (parts ) == 2 :
286302 forwarders .append ({
287303 'address' : parts [0 ],
288304 'destination' : parts [1 ]
289305 })
290306
291- print (f"Found { len (forwarders )} forwarders" )
307+ elif isinstance (response , str ):
308+ print ("Response is string, checking for forwarders..." )
309+ # Maybe it's a different format
310+ if '@' in response :
311+ lines = response .strip ().split ('\n ' )
312+ for line in lines :
313+ if '=' in line and '@' in line :
314+ parts = line .split ('=' , 1 )
315+ if len (parts ) == 2 :
316+ forwarders .append ({
317+ 'address' : parts [0 ].strip (),
318+ 'destination' : parts [1 ].strip ()
319+ })
320+
321+ print (f"\n Parsed { len (forwarders )} forwarders" )
292322 return forwarders
293323
294324 except Exception as e :
0 commit comments