// this is ~result.js
dbg("~AJAX RESULT~ of the result command")

||ifequal||sid||0||\
	auth_error('||auth_fail_reason||');
||else||

# Send appropriate core surgweb mail client data if so requested
||ifdef||output_ident||\
	||include||_ident.js||
||endif||
||ifdef||output_folders||\
	||include||_flds.js||
||endif||
||ifdef||output_messages||\
	||include||_msgs.js||
||endif||
||ifdef||output_sig||\
	||include||_sig.js||
||endif||
||ifdef||output_stc||\
	||include||_stc.js||
||endif||

||ifdef||edit_uid2||\
	edit_uid('||edit_uid2||');
||endif||

||if(not(blank(update_unread_accounts)))||\
	update_unread_accounts(||update_unread_accounts||,||json_validate_int(alt_new)||);
||endif||

||ifdef||output_unread_many||\
	update_unread_folders(||tcmd_json_unread_many||);
||endif||
||ifdef||output_new_mail||\
	var refreshing=false;\
	||if(or(greater_than(new_mail_n,0),greater_than(gone_mail_n,0)))||\
		||define||keep_selection||TRUE||\
		refreshing=delayed_refresh(function(){
			||include||_msgs.js||
		},'||msgs_folder||');
	||endif||\
	||if(greater_than(new_mail_n,0))||\
		new_mail(||new_mail_n||,'||new_mail_tocache||',refreshing);
	||endif||\
||endif||
||ifdef||output_backoff||\
	set_backoff(||backoff_period||);
||endif||
||ifdef||output_contact_added||\
	||define||late_add||true|| ||macro((abook_entry),(true))||
||endif||



||ifdef||output_upload_info1||\
	aq_results([ ['||attach_mid||','||attach_id||','||web_encode_js(lookup(concat((attach_fname_),attach_id)))||','||bytes_basic(lookup(concat((attach_fsize_),attach_id)))||||ifdef||image_resized||(resized)||endif||','||web_encode_js(lookup(concat((attach_cid_),attach_id)))||','||bigfile_queued||'] ]);
||endif||

||ifdef||output_upload_info2||
  aq_results([\
    ||ifdef||attach_ids||\
  	  ||define||foreach||attach_ids||\
      ||begin_list_foreach|| ||if(not(istrue(first)))||,||endif||\
        ['||attach_mid||','||item||','||web_encode_js(lookup(web_encode_js(concat((attach_fname_),item))))||','||bytes_basic(lookup(concat((attach_fsize_),item)))||','||web_encode_js(lookup(web_encode_js(concat((attach_cid_),item))))||']\
      ||end_list_foreach||\
   	||endif||],\
		'||attach_ids_mpr||' \
   	);
||endif||

||ifdef||output_upload_info3||
  aq_results([\
		||ifdef||attach_ids||\
			['||attach_mid||','||attach_id||','||web_encode_js(attach_fname)||','||bytes_basic(attach_fsize)||','||web_encode_js(attach_cid)||','||web_encode_js(attach_img_url)||']\
		||endif||]\
   	);
||endif||


||iftrue(run_spellcheck)||\
#	||ifdef||output_spellcheck||
		spellchecker_said(||tcmd_json_spelling_results||);
#	||endif||
||endif||

||ifdef||output_partial_update||\
	partial_update_results(||tcmd_json_partial_update||);
||endif||\
||ifdef||output_folder_refresh||\
	folder_refresh_results();
||endif||\
||ifdef||output_folder_recalc||\
	folder_recalc_results(['||nfld_id||','||nfld_nmsg||','||nfld_unread||','||kbytes_basic(nfld_size_kb)||']);
||endif||

||ifdef||results||\
    ||begin_list_results||\
      add_error('||result_type||','||web_encode_js(result)||');
    ||end_list_results||
||endif||

||ifdef||output_version_check||\
	||iftrue(folder_index_invalid)||\
		if(sw.upgrade_pending && version==undefined) x_alert('$$st_index_fault$$'); else check_version('||web_ref_path||');\
	||else||\
		check_version('||web_ref_path||');\
	||endif||\
||else||\
	||iftrue(folder_index_invalid)||\
		x_alert('$$st_index_fault$$');\
	||endif||\
||endif||

||ifdef||output_vcheck||
	vcheck_result(||tcmd_vcheck||);
||endif||

||ifdef||output_quota||\
	cur_quota({pct:||json_validate_int(quota_pct)||,used:'||kbytes_basic(quota_used)||', limit:'||kbytes_basic(quota_max)||'});
||endif||

||ifdef||output_cal_alerts||\
	cal_alerts_add(||tcmd_cal_alerts||);
||endif||

||endif||
