@@ -115,62 +115,61 @@ def test_connection(self):
115115 except Exception as e :
116116 return False , str (e )
117117
118- def get_email_accounts (self ):
119- """Get all email accounts for the domain"""
120- try :
118+ def get_email_accounts (self ):
119+ try :
121120 # DirectAdmin API endpoint for listing email accounts
122- endpoint = '/CMD_API_POP'
123- params = {
124- 'action' : 'list' ,
125- 'domain' : self .domain
126- }
121+ endpoint = '/CMD_API_POP'
122+ params = {
123+ 'action' : 'list' ,
124+ 'domain' : self .domain
125+ }
127126
128- response = self ._make_request (endpoint , params )
127+ response = self ._make_request (endpoint , params )
129128
130- if response is None :
131- return []
132-
133- # Parse the response
134- accounts = []
135-
136- # DirectAdmin returns data in key=value format
137- if isinstance (response , dict ):
138- # If it's already parsed as dict
139- for key , value in response .items ():
140- if '@' in key : # It's an email address
141- accounts .append (key )
142- elif key .startswith ('list[]' ): # Alternative format
143- accounts .append (value )
144- else :
145- # If it's raw text response
146- lines = response .strip ().split ('\n ' ) if isinstance (response , str ) else []
147- for line in lines :
148- if '=' in line :
149- key , value = line .split ('=' , 1 )
150- # Check various formats DA might use
151- if '@' in value :
152- accounts .append (value )
153- elif '@' not in key and value and not key .startswith ('error' ):
154- # It might be username only, add domain
155- email = f"{ value } @{ self .domain } "
156- accounts .append (email )
129+ if response is None :
130+ return []
157131
158- # Filter out the API username's email
159- filtered_accounts = []
160- api_email = f"{ self .username } @{ self .domain } "
132+ # Parse the response
133+ accounts = []
161134
162- for email in accounts :
163- if email .lower () != api_email .lower ():
164- filtered_accounts .append (email )
165-
166- print (f"Found email accounts: { filtered_accounts } " )
167- return sorted (filtered_accounts )
135+ # DirectAdmin returns data in key=value format
136+ if isinstance (response , dict ):
137+ # If it's already parsed as dict
138+ for key , value in response .items ():
139+ if '@' in key : # It's an email address
140+ accounts .append (key )
141+ elif key .startswith ('list[]' ): # Alternative format
142+ accounts .append (value )
143+ else :
144+ # If it's raw text response
145+ lines = response .strip ().split ('\n ' ) if isinstance (response , str ) else []
146+ for line in lines :
147+ if '=' in line :
148+ key , value = line .split ('=' , 1 )
149+ # Check various formats DA might use
150+ if '@' in value :
151+ accounts .append (value )
152+ elif '@' not in key and value and not key .startswith ('error' ):
153+ # It might be username only, add domain
154+ email = f"{ value } @{ self .domain } "
155+ accounts .append (email )
156+
157+ # Filter out the API username's email
158+ filtered_accounts = []
159+ api_email = f"{ self .username } @{ self .domain } "
160+
161+ for email in accounts :
162+ if email .lower () != api_email .lower ():
163+ filtered_accounts .append (email )
164+
165+ print (f"Found email accounts: { filtered_accounts } " )
166+ return sorted (filtered_accounts )
168167
169- except Exception as e :
170- print (f"Error getting email accounts: { e } " )
171- import traceback
172- traceback .print_exc ()
173- return []
168+ except Exception as e :
169+ print (f"Error getting email accounts: { e } " )
170+ import traceback
171+ traceback .print_exc ()
172+ return []
174173
175174 def get_forwarders (self , domain ):
176175 try :
0 commit comments