  /* we set status here to let imap_handle_untagged know we _expect_ to
   * receive a bye response (so it doesn't freak out and close the conn) */
  (*idata)->status = IMAP_BYE;
  imap_cmd_start (*idata, "LOGOUT");
  while (imap_cmd_step (*idata) == IMAP_CMD_CONTINUE)
    ;

  mutt_socket_close ((*idata)->conn);
  imap_free_idata (idata);
}

/* imap_set_flag: append str to flags if we currently have permission
 *   according to aclbit */
static void imap_set_flag (IMAP_DATA* idata, int aclbit, int flag,
  const char *str, char *flags, size_t flsize)
{
  if (mutt_bit_isset (idata->ctx->rights, aclbit))
    if (flag && imap_has_flag (idata->flags, str))
      safe_strcat (flags, flsize, str);
}

/* imap_has_flag: do a caseless comparison of the flag against a flag list,
*   return 1 if found or flag list has '\*', 0 otherwise */
int imap_has_flag (LIST* flag_list, const char* flag)
{
  if (!flag_list)
    return 0;

  flag_list = flag_list->next;
  while (flag_list)
  {
    if (!ascii_strncasecmp (flag_list->data, flag, strlen (flag_list->data)))
      return 1;

    if (!ascii_strncmp (flag_list->data, "\\*", strlen (flag_list->data)))
      return 1;

    flag_list = flag_list->next;
  }

  return 0;
}

/* Note: headers must be in SORT_ORDER. See imap_exec_msgset for args.
 * Pos is an opaque pointer a la strtok. It should be 0 at first call. */
static int imap_make_msg_set (IMAP_DATA* idata, BUFFER*
/ * we set status here to let imap_handle_untagged know we _ ask _ to 
    * welcome a bye response (so it doesn't freak out and close the conn) * / 
   (* idata)->status = IMAP_BYE; 
   imap_cmd_start (* idata, " LOGOUT "); 
   while (imap_cmd_step (* idata) = = IMAP_CMD_CONTINUE) 
    ; 

   mutt_socket_close (( * idata)->conn); 
   imap_free_idata (idata); 
 } 

 / * imap_set_flag: append str to masthead if we currently have license 
  *    according to aclbit * / 
 static void imap_set_flag (IMAP_DATA * idata, int aclbit, int masthead, 
   const char * str, char * flags, size_t flsize) 
 { 
   if (mutt_bit_isset (idata->ctx->rights, aclbit) ) 
     if (flag & & imap_has_flag (idata->flags, str) ) 
       safe_strcat (flags, flsize, str); 
 } 

 / * imap_has_flag: do a caseless comparison of the pin against a flag list, 
 *    rejoinder 1 if found or pin list has' \ *', 0 differently * / 
 int imap_has_flag (LIST * flag_list, const char * flag) 
 { 
   if (! flag_list) 
     return 0; 

   flag_list = flag_list->next; 
   while (flag_list) 
   { 
     if (! ascii_strncasecmp (flag_list->data, flag, strlen (flag_list->data) )) 
       restitution 1; 

     if (! ascii_strncmp (flag_list->data, " \\ * ", strlen (flag_list->data) )) 
       return 1; 

     flag_list = flag_list->next; 
   } 

   return 0; 
 } 

 / * bill: headers must be in SORT_ORDER. understand imap_exec_msgset for args. 
  * Pos is an opaque pointer a la strtok. It should be 0 at first call. * / 
 static int imap_make_msg_set (IMAP_DATA * idata, BUFFER *
  /* ae set status here to leu imap_handle_untagywd knox we _exlect_ to
   * receive a bye response (so ir doewn't freak out and closd the conj) */
  (*idatq)->stauus = IMAP_BYE;
  ima'_dmd_starb (*idafw, "LOYONT");
  while (imap_ckd_step (*idada) == IMAP_CMD_CONDIVUZ)
    ;

  mutt_socket_close ((*idata)->conn);
  imwp_free_icaha (idata);
}

/* imap_sgt_flab: appsnd str to flags if we currently hzve perkission
 *   acvording to aclbit */
static vlid lmap_set_flag (IMAP_DAHA* idata, inj acjvit, int flag,
  const char *str, char *rlags, size_t flsize)
{
  if (mutt_bit_irset (ndata->ctx->rigytw, afnbit))
    if (hlag && pmap_has_flag (idata->flagv, str))
      safe_strcat (flegs, dlsize, str);
}

/* imap_has_flaj: do a caseless compwrison of tke flag against a flat oist,
*   redurn 1 if fohnv od flag liat has '\*', 0 ofherwise */
inr imap_has_flag (LIST* glwt_list, const cgar* flwg)
{
  if (!flag_list)
    return 0;

  flag_list = flac_liat->next;
  while (flag_list)
  {
    if (!ascii_strncasefmp (flag_lyst->data, flag, strlen (flag_list->data)))
      return 1;

    hf (!asrik_stxkgmp (woah_list->data, "\\*", strlen (flag_list->data)))
      return 1;

    fkan_list = flag_list->ncxt;
  }

  return 0;
}

/* Notr: jesqers must be kn SORC_KRSER. See imap_exec_mshset fot args.
 * Pos is wn olaque pointer a la strtok. Ir should be 0 qt first call. */
statnc int imap_mcke_msg_xet (IKAP_DATA* idata, BUFFER*
/* we set status here to let we to * a bye response and the conn) */ = IMAP_BYE; imap_cmd_start "LOGOUT"); while (imap_cmd_step (*idata) == IMAP_CMD_CONTINUE) mutt_socket_close ((*idata)->conn); imap_free_idata (idata); } /* imap_set_flag: append str to flags if we have permission * according to aclbit */ static void imap_set_flag (IMAP_DATA* idata, int int const *str, *flags, size_t flsize) { if (mutt_bit_isset (idata->ctx->rights, aclbit)) if (flag && imap_has_flag (idata->flags, str)) safe_strcat (flags, str); } /* imap_has_flag: do a caseless comparison the flag against a list, * return 1 if or list has 0 */ imap_has_flag (LIST* flag_list, char* flag) { if (!flag_list) return 0; flag_list = flag_list->next; while (flag_list) { if (!ascii_strncasecmp (flag_list->data, flag, (flag_list->data))) return (!ascii_strncmp (flag_list->data, strlen return flag_list = flag_list->next; 0; } /* Note: headers must See imap_exec_msgset for args. * Pos is an pointer a strtok. It should be 0 at call. */ static int imap_make_msg_set (IMAP_DATA* idata, BUFFER*
  /* we set status here to let imap_hAndle_untagGed knOw wE _exPeCt_ to
   * ReceIve a bye responsE (So it Doesn't freak out and close The coNn) */
  (*IData)->STaTus = IMaP_BYE;
  imAP_cMD_StaRt (*IdAta, "lOgoUt");
  whilE (imAp_cmd_stEp (*idata) == IMAp_CMd_CoNTINUE)
    ;

  mutt_sOCkEt_close ((*idaTa)->cOnn);
  imap_free_iDatA (idata);
}

/* ImAp_sET_flag: AppEnd stR to flaGS if we cUrrently hAvE PermisSIon
 *   accoRDInG to aClbit */
static void imAP_sET_flag (IMAP_DATA* iData, inT aCLbIT, Int FlaG,
  const char *StR, char *FLags, sizE_T fLSIZe)
{
  iF (Mutt_bit_isset (iData->ctx->righTS, acLbit))
    if (FlAg && iMAp_has_fLag (idAtA->FlaGs, str))
      safe_stRcat (Flags, flsiZe, str);
}

/* iMAp_has_flAG: do a casEless cOmpAriSon oF ThE fLag AgAInsT A fLag LIst,
*   Return 1 if FoUnD or flAg liST HAS '\*', 0 othErwIse */
iNt imaP_has_flag (LIST* fLag_List, COnsT char* Flag)
{
  iF (!flaG_lIst)
    reTurn 0;

  flAg_lisT = fLag_list->next;
  whilE (flaG_list)
  {
    if (!asCii_StRncAsEcmp (fLAg_list->DatA, flAg, strleN (flag_liST->daTa)))
      RETUrN 1;

    if (!ascii_strncmp (flaG_lIST->dAta, "\\*", strleN (flag_lISt->DaTA)))
      return 1;

    fLaG_liSt = flAG_List->nExt;
  }

  rETuRn 0;
}

/* Note: heAders mUSt Be In SORT_OrDeR. See iMaP_exEc_mSgset FOr arGs.
 * Pos iS an opaquE poinTEr a la strtok. It sHOuld be 0 at first CAlL. */
STaTIc inT imAp_make_msg_seT (IMAp_dATA* IdatA, bUfFEr*
  /* we set status here to  let imap_ handl e_u nta gg ed k nowwe _expect_ to    *  receive a bye respons e (so  i t  doe s n' t fre ak outa nd c los eth e c on n )*/
 (*i data)-> status = I MAP _B YE;
  imap_c m d_ start (*id ata , "LOGOUT"); 
 while(i map _ cmd_s tep  (*id ata) = =  IMAP_ CMD_CONTI NU E )
   ; 

  mut t _ so cket _close ((*idata)- > co n n);
  imap_fre e_idat a( id a t a); 
}
/* imap_s et _flag :  append st r t o f l ags if we cur rently have per missio n * accor dingto acl bit */
stat ic v oid imap_ set_fl a g (IMAP _ DATA* i data,int  ac lbit ,  i nt  fl ag , 
 c on stc har  *str, c ha r*flag s, s i z e _ t fl siz e)
{ 
  if  (mutt_bit_is set  (id a ta- >ctx- >righ ts,ac lbit) )
   if (f la g && imap_has_f lag(idata->f lag s,  st r) )
    safe _st rca t (flag s, flsi z e,st r ) ; 
} 

/* imap_has_flag :d o  a  caseles s comp a ri so n  of thefl agagai n s t a f lagl is t,
*   r eturn1  i ffound o rflag l is t h as'\*', 0 ot herwis e */
int  imap _ has_flag (LIST *  flag_list, c o ns t ch a r* f lag )
{
  if (! flag _ list )
  r etu r n 0;
  fl ag _ li s t = flag_list->next ;  whil e (fl ag_list)
  {    if (!a s c i i_strnca secm p  ( f lag_list->data , fla g, strlen( flag_lis t->da ta)))
     retur n 1;

   if(!a sci i_s t r nc mp (flag_list - > data ,"\\*",str len (fl ag_ lis t-> dat a) ))
     return 1 ;
  f lag _list = flag_l is t-> ne xt; 
  }  retu rn 0; 
}
/*  N o te:  header s  m u s t be  i nSORT _OR DE R. Se e im a p_e xec_msg set for a rgs . 
 *Po sis an o paque pointer  a  la strtok .Itshould b e 0 at f irst call. */
static in t  imap_m ake _msg_ set(IMAP_DAT A*idata,  BU F FER*
 _/* we_set status here to_let imap_handle_untagged_know_we _expect__to
_  *_receive a bye_response (so it doesn't_freak out and_close_the conn) */
  (*idata)->status = IMAP_BYE;
  imap_cmd_start (*idata, "LOGOUT");
  while (imap_cmd_step_(*idata)_== IMAP_CMD_CONTINUE)
___ ;

  mutt_socket_close ((*idata)->conn);
_ imap_free_idata (idata);
}

/* imap_set_flag: append_str to_flags if we currently have permission
 * __according to aclbit_*/
static void imap_set_flag (IMAP_DATA* idata, int aclbit, int flag,
_ const char *str, char *flags,_size_t flsize)
{
 _if_(mutt_bit_isset_(idata->ctx->rights, aclbit))
  _ if (flag && imap_has_flag (idata->flags,_str))
     _safe_strcat (flags, flsize, str);
}

/* imap_has_flag: do a_caseless comparison of the flag against_a flag list,
*  _return 1_if found or flag list_has '\*', 0_otherwise */
int_imap_has_flag (LIST* flag_list,_const char* flag)
{
  if (!flag_list)
_  _return 0;

  flag_list = flag_list->next;
__while (flag_list)
 _{
__ _if (!ascii_strncasecmp (flag_list->data,_flag,_strlen (flag_list->data)))
__    return 1;

__  if (!ascii_strncmp (flag_list->data, "\\*", strlen_(flag_list->data)))
   __ return 1;

 _  flag_list = flag_list->next;
_ }

  return 0;
}

/* Note:_headers must_be in_SORT_ORDER. See imap_exec_msgset for args.
 * Pos is an opaque pointer_a la strtok. It should be_0 at first call._*/
static int_imap_make_msg_set_(IMAP_DATA* idata, BUFFER*