talons

Fork of Claws Mail https://www.claws-mail
Log | Files | Refs | README | LICENSE

procmsg.h (12196B)


      1 /*
      2  * Claws Mail -- a GTK based, lightweight, and fast e-mail client
      3  * Copyright (C) 1999-2018 Hiroyuki Yamamoto and the Claws Mail team
      4  *
      5  * This program is free software; you can redistribute it and/or modify
      6  * it under the terms of the GNU General Public License as published by
      7  * the Free Software Foundation; either version 3 of the License, or
      8  * (at your option) any later version.
      9  *
     10  * This program is distributed in the hope that it will be useful,
     11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13  * GNU General Public License for more details.
     14  *
     15  * You should have received a copy of the GNU General Public License
     16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
     17  */
     18 
     19 #ifndef __PROCMSG_H__
     20 #define __PROCMSG_H__
     21 
     22 #include <glib.h>
     23 #include <stdio.h>
     24 #include <time.h>
     25 #include <sys/types.h>
     26 #include <string.h>
     27 #include "common/utils.h"
     28 #include "proctypes.h"
     29 
     30 #define MSG_NEW			(1U << 0)
     31 #define MSG_UNREAD		(1U << 1)
     32 #define MSG_MARKED		(1U << 2)
     33 #define MSG_DELETED		(1U << 3)
     34 #define MSG_REPLIED		(1U << 4)
     35 #define MSG_FORWARDED		(1U << 5)
     36 
     37 #define MSG_CLABEL_SBIT	(6)		/* start bit of color label */
     38 /* color labels use 4 bits: 6, 7, 8, 9; bit weight is 7<8<9<6,
     39   IOW the color label value itself must be computed from MsgPermFlags
     40   bits like this:
     41   value =   bit-7-value*2^0
     42           + bit-8-value*2^1
     43           + bit-9-value*2^2
     44           + bit-6-value*2^3 */
     45 
     46 /* color label permflags masks */
     47 #define MAKE_MSG_CLABEL(x, h, m, l)	(\
     48 					 ((x) << (MSG_CLABEL_SBIT + 0)) | \
     49 					 ((h) << (MSG_CLABEL_SBIT + 3)) | \
     50 					 ((m) << (MSG_CLABEL_SBIT + 2)) | \
     51 					 ((l) << (MSG_CLABEL_SBIT + 1)))
     52 #define MSG_CLABEL_NONE		MAKE_MSG_CLABEL(0U, 0U, 0U, 0U)
     53 #define MSG_CLABEL_1		MAKE_MSG_CLABEL(0U, 0U, 0U, 1U)
     54 #define MSG_CLABEL_2		MAKE_MSG_CLABEL(0U, 0U, 1U, 0U)
     55 #define MSG_CLABEL_3		MAKE_MSG_CLABEL(0U, 0U, 1U, 1U)
     56 #define MSG_CLABEL_4		MAKE_MSG_CLABEL(0U, 1U, 0U, 0U)
     57 #define MSG_CLABEL_5		MAKE_MSG_CLABEL(0U, 1U, 0U, 1U)
     58 #define MSG_CLABEL_6		MAKE_MSG_CLABEL(0U, 1U, 1U, 0U)
     59 #define MSG_CLABEL_7		MAKE_MSG_CLABEL(0U, 1U, 1U, 1U)
     60 #define MSG_CLABEL_8		MAKE_MSG_CLABEL(1U, 0U, 0U, 0U)
     61 #define MSG_CLABEL_9		MAKE_MSG_CLABEL(1U, 0U, 0U, 1U)
     62 #define MSG_CLABEL_10		MAKE_MSG_CLABEL(1U, 0U, 1U, 0U)
     63 #define MSG_CLABEL_11		MAKE_MSG_CLABEL(1U, 0U, 1U, 1U)
     64 #define MSG_CLABEL_12		MAKE_MSG_CLABEL(1U, 1U, 0U, 0U)
     65 #define MSG_CLABEL_13		MAKE_MSG_CLABEL(1U, 1U, 0U, 1U)
     66 #define MSG_CLABEL_14		MAKE_MSG_CLABEL(1U, 1U, 1U, 0U)
     67 #define MSG_CLABEL_15		MAKE_MSG_CLABEL(1U, 1U, 1U, 1U)
     68 #define MSG_CLABEL_FLAG_MASK	(MSG_CLABEL_15)
     69 
     70 #define MSG_IGNORE_THREAD	(1U << 10)   /* ignore threads */
     71 #define MSG_LOCKED		(1U << 11)   /* msg is locked  */
     72 #define MSG_RETRCPT_SENT	(1U << 12)   /* new one */
     73 #define MSG_SPAM		(1U << 13)   /* new one */
     74 #define MSG_POSTFILTERED	(1U << 14)
     75 #define MSG_WATCH_THREAD	(1U << 15)   /* watch threads */
     76 #define MSG_FULLY_CACHED	(1U << 16)   /* IMAP: fully cached */
     77 #define MSG_RETRCPT_GOT		(1U << 17)   /* got return receipt */
     78 
     79 /* RESERVED */
     80 #define	MSG_RESERVED_CLAWS	(1U << 30)   /* for Claws Mail */
     81 #define	MSG_RESERVED		(1U << 31)
     82 
     83 #define MSG_MOVE		(1U << 0)
     84 #define MSG_COPY		(1U << 1)
     85 #define MSG_MOVE_DONE		(1U << 15)
     86 #define MSG_QUEUED		(1U << 16)
     87 #define MSG_DRAFT		(1U << 17)
     88 #define MSG_ENCRYPTED		(1U << 18)
     89 #define MSG_IMAP		(1U << 19)
     90 #define MSG_NEWS		(1U << 20)
     91 #define MSG_SIGNED		(1U << 21)
     92 #define MSG_MULTIPART		(1U << 29)
     93 #define MSG_HAS_ATTACHMENT	(1U << 30)
     94 #define MSG_SCANNED		(1U << 31)
     95 
     96 #define MSG_CACHED_FLAG_MASK	(MSG_MULTIPART | MSG_ENCRYPTED | MSG_SIGNED | MSG_HAS_ATTACHMENT | MSG_SCANNED)
     97 
     98 #define MSG_SET_FLAGS(msg, flags)	{ (msg) |= (flags); }
     99 #define MSG_UNSET_FLAGS(msg, flags)	{ (msg) &= ~(flags); }
    100 #define MSG_SET_PERM_FLAGS(msg, flags) \
    101 	MSG_SET_FLAGS((msg).perm_flags, flags)
    102 #define MSG_SET_TMP_FLAGS(msg, flags) \
    103 	MSG_SET_FLAGS((msg).tmp_flags, flags)
    104 #define MSG_UNSET_PERM_FLAGS(msg, flags) \
    105 	MSG_UNSET_FLAGS((msg).perm_flags, flags)
    106 #define MSG_UNSET_TMP_FLAGS(msg, flags) \
    107 	MSG_UNSET_FLAGS((msg).tmp_flags, flags)
    108 
    109 #define MSG_IS_NEW(msg)			(((msg).perm_flags & MSG_NEW) != 0)
    110 #define MSG_IS_UNREAD(msg)		(((msg).perm_flags & MSG_UNREAD) != 0)
    111 #define MSG_IS_MARKED(msg)		(((msg).perm_flags & MSG_MARKED) != 0)
    112 #define MSG_IS_DELETED(msg)		(((msg).perm_flags & MSG_DELETED) != 0)
    113 #define MSG_IS_REPLIED(msg)		(((msg).perm_flags & MSG_REPLIED) != 0)
    114 #define MSG_IS_LOCKED(msg)		(((msg).perm_flags & MSG_LOCKED) != 0)
    115 #define MSG_IS_FORWARDED(msg)		(((msg).perm_flags & MSG_FORWARDED) != 0)
    116 #define MSG_IS_POSTFILTERED(msg)	(((msg).perm_flags & MSG_POSTFILTERED) != 0)
    117 
    118 /* color label decoding/encoding (permflag storage bits <-> color list index value)*/
    119 #define MSG_COLORLABEL_TO_FLAGS(val) (((((guint)(val)) & 7) << (MSG_CLABEL_SBIT+1)) \
    120 									  | (((guint)(val) & 8) << (MSG_CLABEL_SBIT-3)))
    121 #define MSG_COLORLABEL_FROM_FLAGS(val) ((((guint)(val) >> (MSG_CLABEL_SBIT+1)) & 7 ) \
    122 										| (((guint)(val) >> (MSG_CLABEL_SBIT-3)) & 8))
    123 #define MSG_GET_COLORLABEL(msg)		(((msg).perm_flags & MSG_CLABEL_FLAG_MASK))
    124 #define MSG_GET_COLORLABEL_VALUE(msg)	(MSG_COLORLABEL_FROM_FLAGS(MSG_GET_COLORLABEL(msg)))
    125 #define MSG_SET_COLORLABEL_VALUE(msg, val)	MSG_SET_PERM_FLAGS(msg, MSG_COLORLABEL_TO_FLAGS(val))
    126 
    127 #define MSG_IS_MOVE(msg)		(((msg).tmp_flags & MSG_MOVE) != 0)
    128 #define MSG_IS_COPY(msg)		(((msg).tmp_flags & MSG_COPY) != 0)
    129 #define MSG_IS_MOVE_DONE(msg)		(((msg).tmp_flags & MSG_MOVE_DONE) != 0)
    130 
    131 #define MSG_IS_QUEUED(msg)		(((msg).tmp_flags & MSG_QUEUED) != 0)
    132 #define MSG_IS_DRAFT(msg)		(((msg).tmp_flags & MSG_DRAFT) != 0)
    133 #define MSG_IS_ENCRYPTED(msg)		(((msg).tmp_flags & MSG_ENCRYPTED) != 0)
    134 #define MSG_IS_SIGNED(msg)		(((msg).tmp_flags & MSG_SIGNED) != 0)
    135 #define MSG_IS_IMAP(msg)		(((msg).tmp_flags & MSG_IMAP) != 0)
    136 #define MSG_IS_NEWS(msg)		(((msg).tmp_flags & MSG_NEWS) != 0)
    137 #define MSG_IS_MULTIPART(msg)		(((msg).tmp_flags & MSG_MULTIPART) != 0)
    138 #define MSG_IS_WITH_ATTACHMENT(msg)	(((msg).tmp_flags & MSG_HAS_ATTACHMENT) != 0)
    139 #define MSG_IS_SCANNED(msg)		(((msg).tmp_flags & MSG_SCANNED) != 0)
    140 
    141 /* Claws related flags */
    142 #define MSG_IS_IGNORE_THREAD(msg)	(((msg).perm_flags & MSG_IGNORE_THREAD) != 0)
    143 #define MSG_IS_RETRCPT_SENT(msg)	(((msg).perm_flags & MSG_RETRCPT_SENT) != 0)
    144 #define MSG_IS_RETRCPT_GOT(msg)		(((msg).perm_flags & MSG_RETRCPT_GOT) != 0)
    145 #define MSG_IS_SPAM(msg)		(((msg).perm_flags & MSG_SPAM) != 0)
    146 #define MSG_IS_WATCH_THREAD(msg)	(((msg).perm_flags & MSG_WATCH_THREAD) != 0)
    147 #define MSG_IS_FULLY_CACHED(msg)	(((msg).perm_flags & MSG_FULLY_CACHED) != 0)
    148 
    149 #define MSGINFO_UPDATE_HOOKLIST "msginfo_update"
    150 #define MAIL_FILTERING_HOOKLIST "mail_filtering_hooklist"
    151 #define MAIL_LISTFILTERING_HOOKLIST "mail_listfiltering_hooklist"
    152 #define MAIL_POSTFILTERING_HOOKLIST "mail_postfiltering_hooklist"
    153 
    154 typedef enum {
    155 	MSGINFO_UPDATE_FLAGS = 1 << 0,
    156 	MSGINFO_UPDATE_DELETED = 1 << 1
    157 } MsgInfoUpdateFlags;
    158 
    159 #include "folder.h"
    160 
    161 struct _MsgFlags
    162 {
    163 	MsgPermFlags perm_flags;
    164 	MsgTmpFlags  tmp_flags;
    165 };
    166 
    167 typedef enum {
    168 	IS_NOTHING = 0,
    169 	IS_MOVE,
    170 	IS_COPY,
    171 	IS_DELE
    172 } FiltOp;
    173 
    174 /* *********************************************************** *
    175  * WARNING: When adding or removing members to this structure, *
    176  * be sure to update procmsg.c::procmsg_msginfo_memusage()  to *
    177  * avoid underestimating cache memory usage - especially since *
    178  * this would cause an overflow and metadata loss when writing *
    179  * the cache to disk.                                          *
    180  * *********************************************************** */
    181 struct _MsgInfo
    182 {
    183 	guint refcnt;
    184 
    185 	guint  msgnum;
    186 	goffset  size;
    187 	time_t mtime;
    188 	time_t date_t;
    189 	time_t thread_date;
    190 
    191 	MsgFlags flags;
    192 
    193 	gchar *fromname;
    194 
    195 	gchar *date;
    196 	gchar *from;
    197 	gchar *to;
    198 	gchar *cc;
    199 	gchar *subject;
    200 	gchar *msgid;
    201 	gchar *inreplyto;
    202 	gchar *xref;
    203 
    204 	FolderItem *folder;
    205 	FolderItem *to_folder;
    206 
    207 	FolderItem *to_filter_folder;
    208 	FiltOp filter_op;
    209 
    210 	GSList *references;
    211 	gchar *fromspace;
    212 
    213 	gint score;
    214 
    215 	/* used only for encrypted messages */
    216 	// TODO(otl): really?
    217 	char *plaintext_file;
    218 
    219 	gint hidden;
    220 
    221 	/* used only for partially received messages */
    222 	gint total_size;
    223 	gint planned_download;
    224 
    225 	/* list of tags ids */
    226 	GSList *tags;
    227 
    228 	MsgInfoExtraData *extradata;
    229 };
    230 
    231 struct _MsgInfoExtraData
    232 {
    233 	gchar *dispositionnotificationto;
    234 	gchar *returnreceiptto;
    235 
    236 	gchar *resent_from;
    237 
    238 	/* used only for partially received messages */
    239 	gchar *partial_recv;
    240 	gchar *account_server;
    241 	gchar *account_login;
    242 
    243  	/* Mailing list support */
    244  	gchar *list_post;
    245  	gchar *list_subscribe;
    246  	gchar *list_unsubscribe;
    247  	gchar *list_help;
    248  	gchar *list_archive;
    249  	gchar *list_owner;
    250 };
    251 
    252 struct _MsgFileInfo
    253 {
    254 	MsgInfo *msginfo;
    255         gchar *file;
    256         MsgFlags *flags;
    257 };
    258 
    259 struct _MsgInfoUpdate {
    260 	MsgInfo	*msginfo;
    261 	MsgInfoUpdateFlags flags;
    262 };
    263 
    264 GSList *procmsg_read_cache		(FolderItem	*item,
    265 					 gboolean	 scan_file);
    266 void	procmsg_msg_list_free		(MsgInfoList	*mlist);
    267 MsgNumberList *procmsg_get_number_list_for_msgs(MsgInfoList *msglist);
    268 void	procmsg_get_mark_sum		(const gchar	*folder,
    269 					 gint		*new_msgs,
    270 					 gint		*unread_msgs,
    271 					 gint		*total_msgs,
    272 					 gint		*min,
    273 					 gint		*max,
    274 					 gint		 first);
    275 
    276 GNode  *procmsg_get_thread_tree		(GSList		*mlist);
    277 
    278 gint	procmsg_move_messages		(GSList		*mlist);
    279 void	procmsg_copy_messages		(GSList		*mlist);
    280 
    281 /* return path is locale charset */
    282 gchar  *procmsg_get_message_file_path	(MsgInfo	*msginfo);
    283 gchar  *procmsg_get_message_file	(MsgInfo	*msginfo);
    284 gchar  *procmsg_get_message_file_full	(MsgInfo	*msginfo,
    285 					 gboolean 	 get_headers,
    286 					 gboolean	 get_body);
    287 GSList *procmsg_get_message_file_list	(MsgInfoList	*mlist);
    288 void	procmsg_message_file_list_free	(MsgInfoList	*file_list);
    289 FILE   *procmsg_open_message		(MsgInfo	*msginfo,
    290 					 gboolean	skip_special_headers);
    291 gboolean procmsg_msg_exist		(MsgInfo	*msginfo);
    292 
    293 void	procmsg_empty_all_trash		(void);
    294 
    295 gint	procmsg_send_queue		(FolderItem	*queue,
    296 					 gboolean	 save_msgs,
    297 					 gchar		**errstr);
    298 gboolean procmsg_queue_lock		(gchar		**errstr);
    299 void     procmsg_queue_unlock		(void);
    300 gboolean procmsg_queue_is_empty	(FolderItem *queue);
    301 
    302 MsgInfo *procmsg_msginfo_new		();
    303 MsgInfo *procmsg_msginfo_new_ref	(MsgInfo 	*msginfo);
    304 MsgInfo *procmsg_msginfo_copy		(MsgInfo	*msginfo);
    305 MsgInfo *procmsg_msginfo_get_full_info	(MsgInfo	*msginfo);
    306 MsgInfo *procmsg_msginfo_get_full_info_from_file
    307 					(MsgInfo *msginfo,
    308 					const gchar *file);
    309 void	 procmsg_msginfo_free		(MsgInfo	**msginfo);
    310 guint	 procmsg_msginfo_memusage	(MsgInfo	*msginfo);
    311 
    312 gint procmsg_send_message_queue_with_lock(const gchar *file,
    313 					  gchar **errstr,
    314 					  FolderItem *queue,
    315 					  gint msgnum,
    316 					  gboolean *queued_removed);
    317 
    318 gint procmsg_send_message_queue		(const gchar *file,
    319 					 gchar **errstr,
    320 					 FolderItem *queue,
    321 					 gint msgnum,
    322 					 gboolean *queued_removed);
    323 
    324 void procmsg_msginfo_set_flags		(MsgInfo *msginfo,
    325 					 MsgPermFlags perm_flags,
    326 					 MsgTmpFlags tmp_flags);
    327 void procmsg_msginfo_unset_flags	(MsgInfo *msginfo,
    328 					 MsgPermFlags perm_flags,
    329 					 MsgTmpFlags tmp_flags);
    330 void procmsg_msginfo_change_flags	(MsgInfo *msginfo,
    331 					 MsgPermFlags add_perm_flags,
    332 					 MsgTmpFlags add_tmp_flags,
    333 					 MsgPermFlags rem_perm_flags,
    334 					 MsgTmpFlags rem_tmp_flags);
    335 
    336 gint procmsg_save_to_outbox(FolderItem *outbox, const gchar *file);
    337 gboolean procmsg_msg_has_flagged_parent	(MsgInfo 	*info,
    338 					 MsgPermFlags    perm_flags);
    339 gboolean procmsg_msg_has_marked_parent	(MsgInfo	*info);
    340 void procmsg_msginfo_set_to_folder	(MsgInfo 	*msginfo,
    341 					 FolderItem 	*to_folder);
    342 
    343 MsgInfo *procmsg_msginfo_new_from_mimeinfo
    344 					(MsgInfo 	*src_msginfo,
    345 					 MimeInfo	*mimeinfo);
    346 
    347 gboolean procmsg_have_queued_mails_fast (void);
    348 gboolean procmsg_have_trashed_mails_fast (void);
    349 gboolean procmsg_is_sending(void);
    350 gchar *procmsg_msginfo_get_tags_str(MsgInfo *msginfo);
    351 void procmsg_msginfo_update_tags(MsgInfo *msginfo, gboolean set, gint id);
    352 void procmsg_msginfo_clear_tags(MsgInfo *msginfo);
    353 void procmsg_msginfo_commit_tags(GSList *msglist);
    354 MsgInfo *procmsg_get_msginfo_from_identifier(const gchar *id);
    355 gchar *procmsg_msginfo_get_identifier(MsgInfo *msginfo);
    356 
    357 #endif /* __PROCMSG_H__ */