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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26