1 /* -*-mode:c; c-style:k&r; c-basic-offset:4; -*- */
2 /* Balsa E-Mail Client
3  *
4  * Copyright (C) 1997-2013 Stuart Parmenter and others,
5  *                         See the file AUTHORS for a list.
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2, or (at your option)
10  * any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20  * 02111-1307, USA.
21  */
22 
23 
24 #ifndef __SEND_H__
25 #define __SEND_H__
26 
27 #ifndef BALSA_VERSION
28 # error "Include config.h before this file."
29 #endif
30 
31 #include "libbalsa.h"
32 
33 typedef LibBalsaMailbox* (*LibBalsaFccboxFinder)(const gchar *url);
34 typedef enum _LibBalsaMsgCreateResult LibBalsaMsgCreateResult;
35 enum _LibBalsaMsgCreateResult {
36     LIBBALSA_MESSAGE_CREATE_OK,
37 #ifdef HAVE_GPGME
38     LIBBALSA_MESSAGE_SIGN_ERROR,
39     LIBBALSA_MESSAGE_ENCRYPT_ERROR,
40 #endif
41     LIBBALSA_MESSAGE_CREATE_ERROR,
42     LIBBALSA_MESSAGE_QUEUE_ERROR,
43     LIBBALSA_MESSAGE_SAVE_ERROR,
44     LIBBALSA_MESSAGE_SEND_ERROR,
45     LIBBALSA_MESSAGE_SERVER_ERROR
46 };
47 
48 gboolean libbalsa_message_postpone(LibBalsaMessage * message,
49 				   LibBalsaMailbox * draftbox,
50 				   LibBalsaMessage * reply_message,
51 				   gchar ** extra_headers,
52 				   gboolean flow,
53 				   GError **error);
54 
55 
56 #if ENABLE_ESMTP
57 
58 LibBalsaMsgCreateResult libbalsa_message_queue(LibBalsaMessage* message,
59 					       LibBalsaMailbox* outbox,
60                                                LibBalsaMailbox* fccbox,
61                                                LibBalsaSmtpServer *
62                                                smtp_server,
63 					       gboolean flow,
64 					       GError ** error);
65 LibBalsaMsgCreateResult libbalsa_message_send(LibBalsaMessage * message,
66                                               LibBalsaMailbox * outbox,
67                                               LibBalsaMailbox * fccbox,
68                                               LibBalsaFccboxFinder finder,
69                                               LibBalsaSmtpServer *
70                                               smtp_server, gboolean flow,
71                                               gboolean debug,
72 					      GError ** error);
73 gboolean libbalsa_process_queue(LibBalsaMailbox * outbox,
74                                 LibBalsaFccboxFinder finder,
75                                 GSList * smtp_servers, gboolean debug);
76 #else
77 
78 LibBalsaMsgCreateResult libbalsa_message_queue(LibBalsaMessage* message,
79 					       LibBalsaMailbox* outbox,
80                                                LibBalsaMailbox* fccbox,
81 					       gboolean flow,
82 					       GError ** error);
83 LibBalsaMsgCreateResult libbalsa_message_send(LibBalsaMessage* message,
84 					      LibBalsaMailbox* outbox,
85 					      LibBalsaMailbox* fccbox,
86                                               LibBalsaFccboxFinder finder,
87 					      gboolean flow, gboolean debug,
88 					      GError ** error);
89 gboolean libbalsa_process_queue(LibBalsaMailbox* outbox,
90                                 LibBalsaFccboxFinder finder,
91                                 gboolean debug);
92 
93 #endif
94 
95 #ifdef BALSA_USE_THREADS
96 extern pthread_t send_mail;
97 extern pthread_mutex_t send_messages_lock;
98 extern int send_thread_pipes[2];
99 
100 typedef struct {
101     int message_type;
102     char message_string[256];
103     LibBalsaMessage *msg;
104     LibBalsaMailbox *mbox;
105     float of_total;
106 } SendThreadMessage;
107 
108 #define  MSGSENDTHREAD(t_message, type, string, s_msg, s_mbox, messof) \
109   t_message = g_new(SendThreadMessage, 1); \
110   t_message->message_type = type; \
111   strncpy(t_message->message_string, string, sizeof(t_message->message_string)); \
112   t_message->msg = s_msg; \
113   t_message->mbox = s_mbox; \
114   t_message->of_total = messof; \
115   if (write( send_thread_pipes[1], (void *) &t_message, sizeof(void *) ) \
116       < (ssize_t) sizeof(void *)) \
117     g_warning("pipe error");
118 
119 enum {
120     MSGSENDTHREADERROR,
121     MSGSENDTHREADPROGRESS,
122     MSGSENDTHREADPOSTPONE,
123     MSGSENDTHREADDELETE,
124     MSGSENDTHREADFINISHED
125 };
126 
127 #endif /* BALSA_USE_THREADS */
128 
129 #endif /* __SEND_H__ */
130