/src/neomutt/imap/adata.c
Line | Count | Source (jump to first uncovered line) |
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 | | */ |
40 | | void imap_adata_free(void **ptr) |
41 | 0 | { |
42 | 0 | if (!ptr || !*ptr) |
43 | 0 | return; |
44 | | |
45 | 0 | struct ImapAccountData *adata = *ptr; |
46 | |
|
47 | 0 | FREE(&adata->capstr); |
48 | 0 | buf_dealloc(&adata->cmdbuf); |
49 | 0 | FREE(&adata->buf); |
50 | 0 | FREE(&adata->cmds); |
51 | |
|
52 | 0 | if (adata->conn) |
53 | 0 | { |
54 | 0 | if (adata->conn->close) |
55 | 0 | adata->conn->close(adata->conn); |
56 | 0 | FREE(&adata->conn); |
57 | 0 | } |
58 | |
|
59 | 0 | FREE(ptr); |
60 | 0 | } |
61 | | |
62 | | /** |
63 | | * imap_adata_new - Allocate and initialise a new ImapAccountData structure |
64 | | * @param a Account |
65 | | * @retval ptr New ImapAccountData |
66 | | */ |
67 | | struct ImapAccountData *imap_adata_new(struct Account *a) |
68 | 0 | { |
69 | 0 | struct ImapAccountData *adata = mutt_mem_calloc(1, sizeof(struct ImapAccountData)); |
70 | 0 | adata->account = a; |
71 | |
|
72 | 0 | static unsigned char new_seqid = 'a'; |
73 | |
|
74 | 0 | adata->seqid = new_seqid; |
75 | 0 | const short c_imap_pipeline_depth = cs_subset_number(NeoMutt->sub, "imap_pipeline_depth"); |
76 | 0 | adata->cmdslots = c_imap_pipeline_depth + 2; |
77 | 0 | adata->cmds = mutt_mem_calloc(adata->cmdslots, sizeof(*adata->cmds)); |
78 | |
|
79 | 0 | if (++new_seqid > 'z') |
80 | 0 | new_seqid = 'a'; |
81 | |
|
82 | 0 | return adata; |
83 | 0 | } |
84 | | |
85 | | /** |
86 | | * imap_adata_get - Get the Account data for this mailbox |
87 | | * @param m Mailbox |
88 | | * @retval ptr Private data |
89 | | */ |
90 | | struct ImapAccountData *imap_adata_get(struct Mailbox *m) |
91 | 0 | { |
92 | 0 | if (!m || (m->type != MUTT_IMAP) || !m->account) |
93 | 0 | return NULL; |
94 | 0 | return m->account->adata; |
95 | 0 | } |