1 /** 2 * @file 3 * Imap-specific Account data 4 * 5 * @authors 6 * Copyright (C) 2021 Richard Russon <rich@flatcap.org> 7 * 8 * @copyright 9 * This program is free software: you can redistribute it and/or modify it under 10 * the terms of the GNU General Public License as published by the Free Software 11 * Foundation, either version 2 of the License, or (at your option) any later 12 * version. 13 * 14 * This program is distributed in the hope that it will be useful, but WITHOUT 15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 16 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 17 * details. 18 * 19 * You should have received a copy of the GNU General Public License along with 20 * this program. If not, see <http://www.gnu.org/licenses/>. 21 */ 22 23 /** 24 * @page imap_adata Account data 25 * 26 * Imap-specific Account data 27 */ 28 29 #include "config.h" 30 #include "private.h" 31 #include "mutt/lib.h" 32 #include "config/lib.h" 33 #include "core/lib.h" 34 #include "conn/lib.h" 35 #include "adata.h" 36 37 /** 38 * imap_adata_free - Free the private Account data - Implements Account::adata_free() 39 */ imap_adata_free(void ** ptr)40void imap_adata_free(void **ptr) 41 { 42 if (!ptr || !*ptr) 43 return; 44 45 struct ImapAccountData *adata = *ptr; 46 47 FREE(&adata->capstr); 48 mutt_buffer_dealloc(&adata->cmdbuf); 49 FREE(&adata->buf); 50 FREE(&adata->cmds); 51 52 if (adata->conn) 53 { 54 if (adata->conn->close) 55 adata->conn->close(adata->conn); 56 FREE(&adata->conn); 57 } 58 59 FREE(ptr); 60 } 61 62 /** 63 * imap_adata_new - Allocate and initialise a new ImapAccountData structure 64 * @retval ptr New ImapAccountData 65 */ imap_adata_new(struct Account * a)66struct ImapAccountData *imap_adata_new(struct Account *a) 67 { 68 struct ImapAccountData *adata = mutt_mem_calloc(1, sizeof(struct ImapAccountData)); 69 adata->account = a; 70 71 static unsigned char new_seqid = 'a'; 72 73 adata->seqid = new_seqid; 74 const short c_imap_pipeline_depth = 75 cs_subset_number(NeoMutt->sub, "imap_pipeline_depth"); 76 adata->cmdslots = c_imap_pipeline_depth + 2; 77 adata->cmds = mutt_mem_calloc(adata->cmdslots, sizeof(*adata->cmds)); 78 79 if (++new_seqid > 'z') 80 new_seqid = 'a'; 81 82 return adata; 83 } 84 85 /** 86 * imap_adata_get - Get the Account data for this mailbox 87 * @param m Mailbox 88 * @retval ptr Private data 89 */ imap_adata_get(struct Mailbox * m)90struct ImapAccountData *imap_adata_get(struct Mailbox *m) 91 { 92 if (!m || (m->type != MUTT_IMAP) || !m->account) 93 return NULL; 94 return m->account->adata; 95 } 96