/[winpt]/trunk/Src/wptMAPI.cpp
ViewVC logotype

Diff of /trunk/Src/wptMAPI.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 5 by twoaday, Mon Mar 7 13:21:36 2005 UTC revision 36 by werner, Thu Oct 27 15:25:13 2005 UTC
# Line 1  Line 1 
1  /* wptMAPI.cpp  /* wptMAPI.cpp
2   *      Copyright (C) 2003, 2004 Timo Schulz   *      Copyright (C) 2003, 2004 Timo Schulz
3   *   *
4   * This file is part of WinPT.   * This file is part of WinPT.
5   *   *
6   * WinPT is free software; you can redistribute it and/or modify   * WinPT is free software; you can redistribute it and/or modify
7   * it under the terms of the GNU General Public License as published by   * it under the terms of the GNU General Public License as published by
8   * the Free Software Foundation; either version 2 of the License, or   * the Free Software Foundation; either version 2 of the License, or
9   * (at your option) any later version.   * (at your option) any later version.
10   *   *
11   * WinPT is distributed in the hope that it will be useful,   * WinPT is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU General Public License for more details.   * GNU General Public License for more details.
15   *   *
16   * You should have received a copy of the GNU General Public License   * You should have received a copy of the GNU General Public License
17   * along with WinPT; if not, write to the Free Software Foundation,   * along with WinPT; if not, write to the Free Software Foundation,
18   * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA   * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19   */   */
20    #ifdef HAVE_CONFIG_H
21  #include <windows.h>  #include <config.h>
22  #include <stdio.h>  #endif
23  #include <mapi.h>  
24    #include <windows.h>
25  extern HINSTANCE glob_hinst;  #include <windows.h>
26    #include <stdio.h>
27  #include "../resource.h"  #include <mapi.h>
28  #include "wptTypes.h"  
29  #include "wptErrors.h"  extern HINSTANCE glob_hinst;
30  #include "wptW32API.h"  
31  #include "wptGPG.h"  #include "../resource.h"
32    #include "wptTypes.h"
33    #include "wptErrors.h"
34  static LPMAPILOGON          mapi_logon = NULL;  #include "wptW32API.h"
35  static LPMAPILOGOFF         mapi_logoff = NULL;      #include "wptGPG.h"
36  static LPMAPISENDDOCUMENTS  mapi_send_documents = NULL;  
37  static LPMAPISENDMAIL       mapi_send_mail = NULL;  
38  static HINSTANCE            hlib = NULL;  static LPMAPILOGON          mapi_logon = NULL;
39  static int                  init = 0;  static LPMAPILOGOFF         mapi_logoff = NULL;    
40    static LPMAPISENDDOCUMENTS  mapi_send_documents = NULL;
41  #define load_one_fnc(cast, hlib, name) (cast)GetProcAddress ((hlib), name)  static LPMAPISENDMAIL       mapi_send_mail = NULL;
42    static HINSTANCE            hlib = NULL;
43    static int                  init = 0;
44  int  
45  mapi_init (void)  #define load_one_fnc(cast, hlib, name) (cast)GetProcAddress ((hlib), name)
46  {  
47      if (init)  
48          return 0;  int
49    mapi_init (void)
50      hlib = LoadLibrary ("MAPI32.DLL");  {
51      if (!hlib)      if (init)
52          return -1;          return 0;
53    
54      mapi_logon = load_one_fnc (LPMAPILOGON, hlib, "MAPILogon");      hlib = LoadLibrary ("MAPI32.DLL");
55      mapi_logoff = load_one_fnc (LPMAPILOGOFF, hlib, "MAPILogoff");      if (!hlib)
56      mapi_send_documents = load_one_fnc (LPMAPISENDDOCUMENTS, hlib, "MAPISendDocuments");          return -1;
57      mapi_send_mail = load_one_fnc (LPMAPISENDMAIL, hlib, "MAPISendMail");  
58      if (!mapi_logon || !mapi_logoff || !mapi_send_documents || !mapi_send_mail)      mapi_logon = load_one_fnc (LPMAPILOGON, hlib, "MAPILogon");
59          return -1;      mapi_logoff = load_one_fnc (LPMAPILOGOFF, hlib, "MAPILogoff");
60      init = 1;      mapi_send_documents = load_one_fnc (LPMAPISENDDOCUMENTS, hlib, "MAPISendDocuments");
61        mapi_send_mail = load_one_fnc (LPMAPISENDMAIL, hlib, "MAPISendMail");
62      return 0;      if (!mapi_logon || !mapi_logoff || !mapi_send_documents || !mapi_send_mail)
63  } /* mapi_init */          return -1;
64        init = 1;
65    
66  void      return 0;
67  mapi_deinit (void)  } /* mapi_init */
68  {  
69      if (hlib) {  
70          FreeLibrary (hlib);  void
71          hlib = NULL;  mapi_deinit (void)
72          init = 0;  {
73      }      if (hlib) {
74  } /* mapi_deinit */          FreeLibrary (hlib);
75            hlib = NULL;
76            init = 0;
77  int      }
78  mapi_send_ascfile (char * ascfile)  } /* mapi_deinit */
79  {  
80      LHANDLE hd;  #if 0 /* low:priority XXX port the code */
81      int rc;  int
82    mapi_send_ascfile (char *ascfile)
83      if (!init)  {
84          return 0;      LHANDLE hd;
85        int rc;
86      rc = mapi_logon (0, NULL, NULL, MAPI_LOGON_UI, 0, &hd);  
87      if (rc != SUCCESS_SUCCESS) {      if (!init)
88          MessageBox (NULL, _("MAPI Login failed."), "MAPI", MB_ICONWARNING|MB_OK);          return 0;
89          goto fail;  
90      }      rc = mapi_logon (0, NULL, NULL, MAPI_LOGON_UI, 0, &hd);
91      rc = mapi_send_documents (0, ";", ascfile, NULL, 0);      if (rc != SUCCESS_SUCCESS) {
92      if (rc == MAPI_E_USER_ABORT)          MessageBox (NULL, _("MAPI Login failed."), "MAPI", MB_ICONWARNING|MB_OK);
93          rc = SUCCESS_SUCCESS;          goto fail;
94      if (rc != SUCCESS_SUCCESS)      }
95          MessageBox (NULL, _("Could not sent mail."), "MAPI", MB_ICONERROR|MB_OK);      rc = mapi_send_documents (0, ";", ascfile, NULL, 0);
96        if (rc == MAPI_E_USER_ABORT)
97  fail:          rc = SUCCESS_SUCCESS;
98      mapi_logoff (hd, 0, 0, 0);      if (rc != SUCCESS_SUCCESS)
99      return rc;          MessageBox (NULL, _("Could not sent mail."), "MAPI", MB_ICONERROR|MB_OK);
100  }  
101    fail:
102        mapi_logoff (hd, 0, 0, 0);
103  int      return rc;
104  mapi_send_pubkey (const char * keyid, char * keyfile)  }
105  {  
106      LHANDLE hd;  
107      const char * fmt;  int
108      char * keyinf = NULL;  mapi_send_pubkey (const char *keyid, char *keyfile)
109      int rc;  {
110        LHANDLE hd;
111      if (!init)      const char * fmt;
112          return 0;      char * keyinf = NULL;
113        int rc;
114      fmt = _("GPG Public Key of %s");  
115      keyinf = new char[strlen (fmt) + strlen (keyid) + 2];      if (!init)
116      if (!keyinf)          return 0;
117          BUG (0);  
118      sprintf (keyinf, fmt, keyid);      fmt = _("GPG Public Key of %s");
119      rc = mapi_logon (0, NULL, NULL, MAPI_LOGON_UI, 0, &hd);      keyinf = new char[strlen (fmt) + strlen (keyid) + 2];
120      if (rc != SUCCESS_SUCCESS) {      if (!keyinf)
121          MessageBox (NULL, _("MAPI Login failed."), "MAPI", MB_ICONWARNING|MB_OK);          BUG (0);
122          goto fail;      sprintf (keyinf, fmt, keyid);
123      }      rc = mapi_logon (0, NULL, NULL, MAPI_LOGON_UI, 0, &hd);
124      rc = mapi_send_documents (0, ";", keyfile, keyinf, 0);      if (rc != SUCCESS_SUCCESS) {
125      if (rc == MAPI_E_USER_ABORT)          MessageBox (NULL, _("MAPI Login failed."), "MAPI", MB_ICONWARNING|MB_OK);
126          rc = SUCCESS_SUCCESS;          goto fail;
127      if (rc != SUCCESS_SUCCESS)      }
128          MessageBox (NULL, _("Could not sent mail."), "MAPI", MB_ICONERROR|MB_OK);      rc = mapi_send_documents (0, ";", keyfile, keyinf, 0);
129        if (rc == MAPI_E_USER_ABORT)
130  fail:          rc = SUCCESS_SUCCESS;
131      mapi_logoff (hd, 0, 0, 0);      if (rc != SUCCESS_SUCCESS)
132      free_if_alloc (keyinf);          MessageBox (NULL, _("Could not sent mail."), "MAPI", MB_ICONERROR|MB_OK);
133      return rc;  
134  } /* mapi_send_pubkey */  fail:
135        mapi_logoff (hd, 0, 0, 0);
136        free_if_alloc (keyinf);
137  static void      return rc;
138  free_mapi_msg (MapiMessage * msg)  } /* mapi_send_pubkey */
139  {  
140      if (!msg)  
141          return;  static void
142      safe_free (msg->lpszSubject);  free_mapi_msg (MapiMessage * msg)
143      safe_free (msg->lpszNoteText);  {
144      safe_free (msg);      if (!msg)
145  } /* free_mapi_msg */          return;
146        safe_free (msg->lpszSubject);
147        safe_free (msg->lpszNoteText);
148  static void      safe_free (msg);
149  free_recip_tab (MapiRecipDesc * recip, size_t n)  } /* free_mapi_msg */
150  {  
151      size_t i;  
152    static void
153      if (!recip)  free_recip_tab (MapiRecipDesc *recip, size_t n)
154          return;  {
155      if (!n)      size_t i;
156          return;  
157      for (i=0; i < n; i++)      if (!recip)
158          safe_free (recip[i].lpszName);          return;
159      safe_free (recip);      if (!n)
160  } /* free_recip_tab */          return;
161        for (i=0; i < n; i++)
162            safe_free (recip[i].lpszName);
163  static void      safe_free (recip);
164  free_files_tab (MapiFileDesc * files, size_t n)  } /* free_recip_tab */
165  {  
166      size_t i;  
167    static void
168      if (!files)  free_files_tab (MapiFileDesc * files, size_t n)
169          return;  {
170      if (!n)      size_t i;
171          return;  
172      for (i=0; i < n; i++) {      if (!files)
173          safe_free (files[i].lpszFileName);          return;
174          safe_free (files[i].lpszPathName);      if (!n)
175      }          return;
176      safe_free (files);      for (i=0; i < n; i++) {
177  } /* free_files_tab */          safe_free (files[i].lpszFileName);
178            safe_free (files[i].lpszPathName);
179        }
180        safe_free (files);
181  static gpgme_recipients_t  } /* free_files_tab */
182  conv_recipients (gpgme_recipients_t rset)  
183  {  
184      gpgme_recipients_t r;  
185      gpgme_error_t rc;  static gpgme_recipients_t
186      void * ctx=NULL;  conv_recipients (gpgme_recipients_t rset)
187      const char * s;  {
188        gpgme_recipients_t r;
189      /* we need to convert the recipients to email addresses so      gpgme_error_t rc;
190         GPG can handle them. */      void * ctx=NULL;
191      rc = gpgme_recipients_new (&r);      const char * s;
192      if (rc)  
193          return NULL;      /* we need to convert the recipients to email addresses so
194      gpgme_recipients_enum_open (rset, &ctx);         GPG can handle them. */
195        rc = gpgme_recipients_new (&r);
196      while ((s=gpgme_recipients_enum_read (rset, &ctx))) {      if (rc)
197          char * p, * q, * buf;          return NULL;
198          if (!(p = strchr (s, '<')) || !(q = strchr (s, '>')))      gpgme_recipients_enum_open (rset, &ctx);
199              continue;  
200          buf = (char * )calloc (1, (q-s)-(p-s)+2);      while ((s=gpgme_recipients_enum_read (rset, &ctx))) {
201          strncpy (buf, s+(p-s)+1, (q-s)-(p-s)-1);          char * p, * q, * buf;
202          gpgme_recipients_add_name (r, buf);          if (!(p = strchr (s, '<')) || !(q = strchr (s, '>')))
203          safe_free (buf);              continue;
204      }          buf = (char * )calloc (1, (q-s)-(p-s)+2);
205      return r;          if (!buf)
206  } /* conv_recipients */              BUG (0);
207            strncpy (buf, s+(p-s)+1, (q-s)-(p-s)-1);
208            gpgme_recipients_add_name (r, buf);
209  static char *          safe_free (buf);
210  secure_attachment (gpgme_recipients_t rset, const char * fname)      }
211  {      return r;
212      char tmpdir[512+32], * p;  } /* conv_recipients */
213      gpgme_recipients_t addrs;  
214      gpgme_ctx_t ctx;  
215      gpgme_error_t rc;  static char *
216    secure_attachment (gpgme_recipients_t rset, const char *fname)
217      if (strlen (fname) > 200)  {
218          BUG (0);      char tmpdir[512+32], * p;
219      GetTempPath (sizeof tmpdir-200, tmpdir);      gpgme_recipients_t addrs;
220      p = strrchr (fname, '\\');      gpgme_ctx_t ctx;
221      if (!p)      gpgme_error_t rc;
222          strcat (tmpdir, fname);  
223      else      if (strlen (fname) > 200)
224          strcat (tmpdir, fname+(p-fname)+1);          BUG (0);
225      strcat (tmpdir, ".asc");      GetTempPath (sizeof tmpdir-200, tmpdir);
226        p = strrchr (fname, '\\');
227      rc = gpgme_new (&ctx);      if (!p)
228      if (rc)          strcat (tmpdir, fname);
229          return NULL;      else
230      gpgme_control (ctx, GPGME_CTRL_ARMOR, 1);          strcat (tmpdir, fname+(p-fname)+1);
231      gpgme_control (ctx, GPGME_CTRL_FORCETRUST, 1);      strcat (tmpdir, ".asc");
232      addrs = conv_recipients (rset);  
233      if (!addrs) {      rc = gpgme_new (&ctx);
234          msg_box (NULL, _("No valid mail addresses found."), _("Secure Attachment"), MB_ERR);      if (rc)
235          gpgme_release (NULL);          return NULL;
236          return NULL;      gpgme_set_armor (ctx, 1);
237      }      addrs = conv_recipients (rset);
238      rc = gpgme_op_file_encrypt (ctx, addrs, fname, tmpdir);      if (!addrs) {
239      if (rc)          msg_box (NULL, _("No valid mail addresses found."), _("Secure Attachment"), MB_ERR);
240          log_box (_("Secure Attachment"), MB_ERR, _("Could not encrypt '%s'"), fname);          gpgme_release (NULL);
241      gpgme_recipients_release (addrs);          return NULL;
242      gpgme_release (ctx);      }
243      return strdup (tmpdir);      rc = gpgme_op_file_encrypt (ctx, addrs, fname, tmpdir);
244  } /* secure_attachment */      if (rc)
245            log_box (_("Secure Attachment"), MB_ERR, _("Could not encrypt '%s'"), fname);
246        gpgme_recipients_release (addrs);
247  static char *      gpgme_release (ctx);
248  secure_message (gpgme_recipients_t rset, const char * data)      return strdup (tmpdir);
249  {  } /* secure_attachment */
250      gpgme_recipients_t addrs;  
251      gpgme_error_t rc;  
252      gpgme_data_t in, out;  static gpgme_error_t
253      gpgme_ctx_t ctx;  secure_message (gpgme_recipients_t rset, const char *data,
254      char * p;                  char *enc_msg, size_t *r_enclen)
255      size_t n=0;  {
256        gpgme_recipients_t addrs;
257      rc = gpgme_new (&ctx);      gpgme_error_t rc;
258      if (rc)      gpgme_data_t in, out;
259          return NULL;      gpgme_ctx_t ctx;
260      gpgme_control (ctx, GPGME_CTRL_ARMOR, 1);      char * p;
261      gpgme_control (ctx, GPGME_CTRL_FORCETRUST, 1);      size_t n=0;
262    
263      addrs = conv_recipients (rset);      rc = gpgme_new (&ctx);
264      rc = gpgme_data_new_from_mem (&in, data, strlen (data), 1);      if (rc)
265      if (rc) {          return NULL;
266          gpgme_release (ctx);      gpgme_set_armor (ctx, 1);
267          return NULL;  
268      }      addrs = conv_recipients (rset);
269      gpgme_data_new (&out);      rc = gpgme_data_new_from_mem (&in, data, strlen (data), 1);
270            if (rc) {
271      rc = gpgme_op_encrypt (ctx, addrs, in, out);          gpgme_release (ctx);
272      if (rc)          return rc;
273          log_box (_("Secure Message"), MB_ERR, "Could not encrypt the data");      }
274        gpgme_data_new (&out);
275      p = gpgme_data_release_and_return_string (out);      rc = gpgme_op_encrypt (ctx, addrs, GPGME_ENCRYPT_ALWAYS_TRUST, in, out);
276        if (rc)
277      gpgme_data_release (in);          log_box (_("Secure Message"), MB_ERR, "Could not encrypt the data");
278      gpgme_release (ctx);  
279      gpgme_recipients_release (addrs);      *r_enc_msg = gpgme_data_release_and_get_mem (&n);
280        *r_enclen = n;
281      return p;  
282  } /* secure_message */      gpgme_data_release (in);
283        gpgme_release (ctx);
284        gpgme_recipients_release (addrs);
285  int  
286  mapi_send_message (gpgme_recipients_t rset, const char * msgtxt,      return rc;
287                     const char * subject, const char ** files, size_t nfiles)  } /* secure_message */
288  {  
289      LHANDLE hd;  
290      MapiMessage * msg;  int
291      MapiRecipDesc * recip;  mapi_send_message (gpgme_recipients_t rset, const char * msgtxt,
292      MapiFileDesc * attch;                     const char * subject, const char **files, size_t nfiles)
293      char * p;  {
294      const char * s;      LHANDLE hd;
295      void * ctx=NULL;      MapiMessage * msg;
296      size_t n, i=0;      MapiRecipDesc * recip;
297      int rc;      MapiFileDesc * attch;
298        char * p;
299      if (!init)      const char * s;
300          return 0;      void * ctx=NULL;
301        size_t n, i=0, encmsg_len=0;
302      rc = mapi_logon (0, NULL, NULL, MAPI_LOGON_UI, 0, &hd);      int rc;
303      if (rc != SUCCESS_SUCCESS) {  
304          MessageBox (NULL, "MAPI Login failed.", "MAPI", MB_ICONWARNING|MB_OK);      if (!init)
305          return rc;          return 0;
306      }  
307        rc = mapi_logon (0, NULL, NULL, MAPI_LOGON_UI, 0, &hd);
308      msg = (MapiMessage *)calloc (1, sizeof * msg);      if (rc != SUCCESS_SUCCESS) {
309      p = msg->lpszSubject = strdup (subject);          MessageBox (NULL, "MAPI Login failed.", "MAPI", MB_ICONWARNING|MB_OK);
310      if (!p)          return rc;
311          BUG (0);      }
312      p = msg->lpszNoteText = secure_message (rset, msgtxt);  
313      if (!p)      msg = (MapiMessage *)calloc (1, sizeof * msg);
314          BUG (0);      if (!msg)
315      n = msg->nRecipCount = gpgme_recipients_count (rset);          BUG (0);
316      recip = (MapiRecipDesc *)calloc (n+1, sizeof * recip);      p = msg->lpszSubject = strdup (subject);
317            if (!p)
318      gpgme_recipients_enum_open (rset, &ctx);          BUG (0);
319      while ((s = gpgme_recipients_enum_read (rset, &ctx))) {      p = msg->lpszNoteText = secure_message (rset, msgtxt, &p, &encmsg_len);
320          if (!i)      if (!p)
321              recip[i].ulRecipClass = MAPI_TO;          BUG (0);
322          else      n = msg->nRecipCount = gpgme_recipients_count (rset);
323              recip[i].ulRecipClass = MAPI_CC;          recip = (MapiRecipDesc *)calloc (n+1, sizeof * recip);
324          p = recip[i].lpszName = strdup (s);      if (!recip)
325          if (!p)          BUG (0);
326              BUG (0);      
327          i++;      gpgme_recipients_enum_open (rset, &ctx);
328      }      while ((s = gpgme_recipients_enum_read (rset, &ctx))) {
329      msg->lpRecips = recip;          if (!i)
330                recip[i].ulRecipClass = MAPI_TO;
331      if (nfiles) {          else
332          msg->nFileCount = nfiles;              recip[i].ulRecipClass = MAPI_CC;    
333          attch = (MapiFileDesc *)calloc (nfiles+1, sizeof * attch);          p = recip[i].lpszName = strdup (s);
334          for (i=0; i < nfiles; i++) {          if (!p)
335              char * p = secure_attachment (rset, *files);              BUG (0);
336              if (!p)          i++;
337                  continue;      }
338              attch[i].lpszFileName = strdup (*files);              msg->lpRecips = recip;
339              attch[i].lpszPathName = strdup (p);  
340              files++;      if (nfiles) {
341              safe_free (p);          msg->nFileCount = nfiles;
342          }          attch = (MapiFileDesc *)calloc (nfiles+1, sizeof * attch);
343          msg->lpFiles = attch;          if (!attch)
344      }              BUG (0);
345            for (i=0; i < nfiles; i++) {
346      rc = mapi_send_mail (hd, 0, msg, 0, 0);              char * p = secure_attachment (rset, *files);
347      if (rc == MAPI_E_USER_ABORT)              if (!p)
348          rc = SUCCESS_SUCCESS;                  continue;
349      if (rc != SUCCESS_SUCCESS)              attch[i].lpszFileName = strdup (*files);        
350          MessageBox (NULL, _("Could not sent mail."), "MAPI", MB_ERR);              attch[i].lpszPathName = strdup (p);
351                files++;
352      free_recip_tab (recip, n);              safe_free (p);
353      free_files_tab (attch, nfiles);          }
354      free_mapi_msg (msg);          msg->lpFiles = attch;
355      mapi_logoff (hd, 0, 0, 0);      }
356    
357      return 0;      rc = mapi_send_mail (hd, 0, msg, 0, 0);
358  } /* mapi_send_message */      if (rc == MAPI_E_USER_ABORT)
359            rc = SUCCESS_SUCCESS;
360        if (rc != SUCCESS_SUCCESS)
361  static int          MessageBox (NULL, _("Could not sent mail."), "MAPI", MB_ERR);
362  add_recipient (gpgme_recipients_t * r_rset, const char * addr)  
363  {      free_recip_tab (recip, n);
364      gpgme_keycache_t pub = keycache_get_ctx (1);      free_files_tab (attch, nfiles);
365      gpgme_key_t key;      free_mapi_msg (msg);
366      gpgme_error_t rc;      gpgme_free (p);
367      const char * s;      mapi_logoff (hd, 0, 0, 0);
368    
369      if (!*r_rset)      return 0;
370          gpgme_recipients_new (&(*r_rset));  } /* mapi_send_message */
371      rc = gpgme_keycache_find_key (pub, addr, 0, &key);  
372      if (rc) {  
373          log_box (_("Add Recipient"), MB_ERR, _("Could not find key for '%s'"), addr);  static int
374          return -1;  add_recipient (gpgme_recipients_t * r_rset, const char * addr)
375      }  {
376      s = gpgme_key_get_string_attr (key, GPGME_ATTR_USERID, NULL, 0);      gpg_keycache_t pub = keycache_get_ctx (1);
377      if (s)      gpgme_key_t key;
378          gpgme_recipients_add_name (*r_rset, s);      gpgme_error_t rc;
379      return 0;      const char * s;
380  } /* add_recipient */  
381        if (!*r_rset)
382            gpgme_recipients_new (&(*r_rset));
383  static int      rc = gpgme_keycache_find_key (pub, addr, 0, &key);
384  add_all_recipients (HWND dlg, int itemid, gpgme_recipients_t * r_rset)      if (rc) {
385  {              log_box (_("Add Recipient"), MB_ERR, _("Could not find key for '%s'"), addr);
386      char buf[1024], * p;          return -1;
387      int n=0;      }
388        s = key->uids->uid;
389      n = GetDlgItemText (dlg, itemid, buf, sizeof buf-10);      if (s)
390      if (!n)          gpgme_recipients_add_name (*r_rset, s);
391          return -1;      return 0;
392      p = strtok (buf, ";,");  } /* add_recipient */
393      while (p != NULL) {  
394          add_recipient (&*r_rset, p);  
395          p = strtok (NULL, ";,");  static int
396      }  add_all_recipients (HWND dlg, int itemid, gpgme_recipients_t * r_rset)
397      return 0;  {    
398  } /* add_all_recipients */      char buf[1024], * p;
399        int n=0;
400    
401  BOOL CALLBACK      n = GetDlgItemText (dlg, itemid, buf, sizeof buf-10);
402  winpt_mail_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)      if (!n)
403  {          return -1;
404      static gpgme_recipients_t rset=NULL;      p = strtok (buf, ";,");
405      char subject[128];      while (p != NULL) {
406      char * msgbuf;          add_recipient (&*r_rset, p);
407      int n;          p = strtok (NULL, ";,");
408        }
409      switch (msg) {      return 0;
410      case WM_INITDIALOG:  } /* add_all_recipients */
411          center_window (dlg);  
412          SetForegroundWindow (dlg);  
413          break;  BOOL CALLBACK
414    winpt_mail_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
415      case WM_COMMAND:  {
416          switch (LOWORD (wparam)) {      static gpgme_recipients_t rset=NULL;
417          case IDOK:      char subject[128];
418              add_all_recipients (dlg, IDC_PMAIL_TO, &rset);      char * msgbuf;
419              add_all_recipients (dlg, IDC_PMAIL_CC, &rset);      int n;
420              if (!gpgme_recipients_count (rset)) {  
421                  msg_box (dlg, _("Please enter a recipient."), _("Mail"), MB_ERR);      switch (msg) {
422                  return FALSE;      case WM_INITDIALOG:
423              }          center_window (dlg, NULL);
424              n=GetDlgItemText (dlg, IDC_PMAIL_SUBJECT, subject, sizeof subject-1);          SetForegroundWindow (dlg);
425              if (!n)          break;
426                  strcpy (subject, "");  
427              n = SendDlgItemMessage (dlg, IDC_PMAIL_MSG, WM_GETTEXTLENGTH, 0, 0);      case WM_COMMAND:
428              if (!n) {          switch (LOWORD (wparam)) {
429                  msg_box (dlg, _("Please enter a message."), _("Mail"), MB_ERR);          case IDOK:
430                  return FALSE;              add_all_recipients (dlg, IDC_PMAIL_TO, &rset);
431              }              add_all_recipients (dlg, IDC_PMAIL_CC, &rset);
432              msgbuf = (char * )calloc (1, n+2);              if (!gpgme_recipients_count (rset)) {
433              GetDlgItemText (dlg, IDC_PMAIL_MSG, msgbuf, n+1);                  msg_box (dlg, _("Please enter a recipient."), _("Mail"), MB_ERR);
434              mapi_send_message (rset, msgbuf, subject, NULL, 0);                  return FALSE;
435              safe_free (msgbuf);              }
436              EndDialog (dlg, TRUE);              n=GetDlgItemText (dlg, IDC_PMAIL_SUBJECT, subject, sizeof subject-1);
437              break;              if (!n)
438                    strcpy (subject, "");
439          case IDCANCEL:              n = SendDlgItemMessage (dlg, IDC_PMAIL_MSG, WM_GETTEXTLENGTH, 0, 0);
440              EndDialog (dlg, FALSE);              if (!n) {
441              break;                  msg_box (dlg, _("Please enter a message."), _("Mail"), MB_ERR);
442          }                  return FALSE;
443          break;              }
444      }              msgbuf = (char * )calloc (1, n+2);
445                if (!msgbuf)
446      return FALSE;                  BUG (0);
447  } /* winpt_mail_proc */              GetDlgItemText (dlg, IDC_PMAIL_MSG, msgbuf, n+1);
448                mapi_send_message (rset, msgbuf, subject, NULL, 0);
449                safe_free (msgbuf);
450                EndDialog (dlg, TRUE);
451                break;
452    
453            case IDCANCEL:
454                EndDialog (dlg, FALSE);
455                break;
456            }
457            break;
458        }
459    
460        return FALSE;
461    } /* winpt_mail_proc */
462    #endif

Legend:
Removed from v.5  
changed lines
  Added in v.36

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26