@@ -47,14 +47,12 @@ def update_account_list():
4747 f"## Configured Accounts\n { accounts_md } " ,
4848 gr .update (choices = email_accounts , value = None ),
4949 gr .update (visible = True ),
50- gr .update (visible = True ),
5150 )
5251 else :
5352 return (
5453 "No email accounts configured yet." ,
5554 gr .update (choices = [], value = None ),
5655 gr .update (visible = False ),
57- gr .update (visible = False ),
5856 )
5957
6058 # Display current email accounts and allow deletion
@@ -102,7 +100,7 @@ def delete_email_account(account_name):
102100 app .load (
103101 fn = update_account_list ,
104102 inputs = None ,
105- outputs = [accounts_display , account_to_delete , delete_btn , delete_btn ],
103+ outputs = [accounts_display , account_to_delete , delete_btn ],
106104 )
107105
108106 # Form for adding a new email account
@@ -178,9 +176,13 @@ def save_email_settings(
178176 try :
179177 # Validate required fields
180178 if not account_name or not full_name or not email_address or not user_name or not password :
181- return [
179+ # Get account list update
180+ account_md , account_choices , btn_visible = update_account_list ()
181+ return (
182182 "Error: Please fill in all required fields." ,
183- * update_account_list (),
183+ account_md ,
184+ account_choices ,
185+ btn_visible ,
184186 account_name ,
185187 full_name ,
186188 email_address ,
@@ -194,14 +196,19 @@ def save_email_settings(
194196 smtp_host ,
195197 smtp_port ,
196198 smtp_ssl ,
199+ smtp_start_ssl ,
197200 smtp_user_name ,
198201 smtp_password ,
199- ]
202+ )
200203
201204 if not imap_host or not smtp_host :
202- return [
205+ # Get account list update
206+ account_md , account_choices , btn_visible = update_account_list ()
207+ return (
203208 "Error: IMAP and SMTP hosts are required." ,
204- * update_account_list (),
209+ account_md ,
210+ account_choices ,
211+ btn_visible ,
205212 account_name ,
206213 full_name ,
207214 email_address ,
@@ -218,17 +225,21 @@ def save_email_settings(
218225 smtp_start_ssl ,
219226 smtp_user_name ,
220227 smtp_password ,
221- ]
228+ )
222229
223230 # Get current settings
224231 settings = get_settings ()
225232
226233 # Check if account name already exists
227234 for email in settings .emails :
228235 if email .account_name == account_name :
229- return [
236+ # Get account list update
237+ account_md , account_choices , btn_visible = update_account_list ()
238+ return (
230239 f"Error: Account name '{ account_name } ' already exists." ,
231- * update_account_list (),
240+ account_md ,
241+ account_choices ,
242+ btn_visible ,
232243 account_name ,
233244 full_name ,
234245 email_address ,
@@ -245,7 +256,7 @@ def save_email_settings(
245256 smtp_start_ssl ,
246257 smtp_user_name ,
247258 smtp_password ,
248- ]
259+ )
249260
250261 # Create new email settings
251262 email_settings = EmailSettings .init (
@@ -273,30 +284,40 @@ def save_email_settings(
273284 # Store settings
274285 store_settings (settings )
275286
287+ # Get account list update
288+ account_md , account_choices , btn_visible = update_account_list ()
289+
276290 # Return success message, update the UI, and clear form fields
277- return [
291+ return (
278292 f"Success: Email account '{ account_name } ' has been added." ,
279- * update_account_list (),
280- "" ,
281- "" ,
282- "" ,
283- "" ,
284- "" , # Clear basic info and credentials
285- "" ,
286- 993 ,
287- True ,
288- "" ,
289- "" , # Clear IMAP settings
290- "" ,
291- 465 ,
292- True ,
293- "" ,
294- "" , # Clear SMTP settings
295- ]
293+ account_md ,
294+ account_choices ,
295+ btn_visible ,
296+ "" , # Clear account_name
297+ "" , # Clear full_name
298+ "" , # Clear email_address
299+ "" , # Clear user_name
300+ "" , # Clear password
301+ "" , # Clear imap_host
302+ 993 , # Reset imap_port
303+ True , # Reset imap_ssl
304+ "" , # Clear imap_user_name
305+ "" , # Clear imap_password
306+ "" , # Clear smtp_host
307+ 465 , # Reset smtp_port
308+ True , # Reset smtp_ssl
309+ False , # Reset smtp_start_ssl
310+ "" , # Clear smtp_user_name
311+ "" , # Clear smtp_password
312+ )
296313 except Exception as e :
297- return [
314+ # Get account list update
315+ account_md , account_choices , btn_visible = update_account_list ()
316+ return (
298317 f"Error: { e !s} " ,
299- * update_account_list (),
318+ account_md ,
319+ account_choices ,
320+ btn_visible ,
300321 account_name ,
301322 full_name ,
302323 email_address ,
@@ -313,7 +334,7 @@ def save_email_settings(
313334 smtp_start_ssl ,
314335 smtp_user_name ,
315336 smtp_password ,
316- ]
337+ )
317338
318339 # Connect the save button to the save function
319340 save_btn .click (
@@ -341,7 +362,6 @@ def save_email_settings(
341362 accounts_display ,
342363 account_to_delete ,
343364 delete_btn ,
344- delete_btn ,
345365 account_name ,
346366 full_name ,
347367 email_address ,
0 commit comments