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

Legend:
Removed from v.22  
changed lines
  Added in v.129

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26