1 /*@ S-nail - a mail user agent derived from Berkeley Mail.
2  *@ `digmsg'.
3  *
4  * Copyright (c) 2016 - 2020 Steffen (Daode) Nurpmeso <steffen@sdaoden.eu>.
5  * SPDX-License-Identifier: ISC
6  *
7  * Permission to use, copy, modify, and/or distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 #ifndef mx_DIG_MSG_H
20 #define mx_DIG_MSG_H
21 
22 #include <mx/nail.h>
23 
24 #include <su/mem-bag.h>
25 
26 #define mx_HEADER
27 #include <su/code-in.h>
28 
29 struct mx_dig_msg_ctx;
30 
31 enum mx_dig_msg_flags{
32    mx_DIG_MSG_NONE,
33    mx_DIG_MSG_COMPOSE = 1u<<0, /* Compose mode object.. */
34    mx_DIG_MSG_COMPOSE_DIGGED = 1u<<1, /* ..with `digmsg' handle also! */
35    mx_DIG_MSG_RDONLY = 1u<<2, /* Message is read-only */
36    mx_DIG_MSG_OWN_MEMBAG = 1u<<3, /* .gdm_membag==&.gdm__membag_buf[0] */
37    mx_DIG_MSG_HAVE_FP = 1u<<4, /* Open on a fs_tmp_open() file */
38    mx_DIG_MSG_FCLOSE = 1u<<5 /* (mx_HAVE_FP:) needs fclose() */
39 };
40 
41 struct mx_dig_msg_ctx{
42    struct mx_dig_msg_ctx *dmc_last; /* Linked only if !DIG_MSG_COMPOSE */
43    struct mx_dig_msg_ctx *dmc_next;
44    struct message *dmc_mp; /* XXX Yet NULL if DIG_MSG_COMPOSE */
45    enum mx_dig_msg_flags dmc_flags;
46    u32 dmc_msgno; /* XXX Only if !DIG_MSG_COMPOSE */
47    FILE *dmc_fp;
48    struct header *dmc_hp;
49    struct su_mem_bag *dmc_membag;
50    struct su_mem_bag dmc__membag_buf[1];
51 };
52 
53 /* This is a bit hairy */
54 #define mx_DIG_MSG_COMPOSE_CREATE(DMCP,HP) \
55 do{\
56    union {struct mx_dig_msg_ctx *dmc; void *v; u8 *b;} __p__;\
57    mx_dig_msg_compose_ctx = __p__.dmc = DMCP;\
58    __p__.b += sizeof *__p__.dmc;\
59    do *--__p__.b = 0; while(__p__.dmc != DMCP);\
60    (DMCP)->dmc_flags = mx_DIG_MSG_COMPOSE;\
61    (DMCP)->dmc_hp = HP;\
62    (DMCP)->dmc_membag = su_mem_bag_top(n_go_data->gdc_membag);\
63 }while(0)
64 
65 #define mx_DIG_MSG_COMPOSE_GUT(DMCP) \
66 do{\
67    ASSERT(mx_dig_msg_compose_ctx == DMCP);\
68    /* File cleaned up via fs_close_all_files() */\
69    mx_dig_msg_compose_ctx = NIL;\
70 }while(0)
71 
72 EXPORT_DATA struct mx_dig_msg_ctx *mx_dig_msg_read_overlay; /* XXX HACK */
73 EXPORT_DATA struct mx_dig_msg_ctx *mx_dig_msg_compose_ctx; /* Or NIL XXX HACK*/
74 
75 /**/
76 EXPORT void mx_dig_msg_on_mailbox_close(struct mailbox *mbox); /* XXX HACK */
77 
78 /* `digmsg' */
79 EXPORT int c_digmsg(void *vp);
80 
81 /* Accessibility hook for `~^' command; needs mx_DIG_MSG_COMPOSE_CREATE() */
82 EXPORT boole mx_dig_msg_circumflex(struct mx_dig_msg_ctx *dmcp, FILE *fp,
83       char const *cmd);
84 
85 #include <su/code-ou.h>
86 #endif /* mx_DIG_MSG_H */
87 /* s-it-mode */
88