[eterhack 4/4] winemapi: Add attachment support (eterbug #6747).

Alexander Morozov amorozov на etersoft.ru
Вт Янв 18 16:38:03 MSK 2011


---
 dlls/winemapi/sendmail.c |   43 +++++++++++++++++++++++++++++++++++--------
 1 files changed, 35 insertions(+), 8 deletions(-)

diff --git a/dlls/winemapi/sendmail.c b/dlls/winemapi/sendmail.c
index e4629bb..4a6d122 100644
--- a/dlls/winemapi/sendmail.c
+++ b/dlls/winemapi/sendmail.c
@@ -60,13 +60,15 @@ ULONG WINAPI MAPISendMail(LHANDLE session, ULONG_PTR uiparam,
 {
     ULONG ret = MAPI_E_FAILURE;
     unsigned int i, to_count = 0, cc_count = 0, bcc_count = 0;
-    unsigned int to_size = 0, cc_size = 0, bcc_size = 0, subj_size, body_size;
+    unsigned int to_size = 0, cc_size = 0, bcc_size = 0, subj_size, body_size,
+        attach_size;
 
-    char *to = NULL, *cc = NULL, *bcc = NULL;
+    char *to = NULL, *cc = NULL, *bcc = NULL, *attach = NULL, *p;
     const char *address, *subject, *body;
     static const char format[] =
-        "mailto:\"%s\"?subject=\"%s\"&cc=\"%s\"&bcc=\"%s\"&body=\"%s\"";
+        "mailto:\"%s\"?subject=\"%s\"&cc=\"%s\"&bcc=\"%s\"&body=\"%s\"%s";
     static const char smtp[] = "smtp:";
+    static const char attachment[] = "&attachment=\"%s\"";
     char *mailto = NULL, *escape = NULL;
     char empty_string[] = "";
     HRESULT res;
@@ -122,9 +124,6 @@ ULONG WINAPI MAPISendMail(LHANDLE session, ULONG_PTR uiparam,
             FIXME("Name resolution and entry identifiers not supported\n");
     }
 
-    if (message->nFileCount)
-        FIXME("Ignoring attachments\n");
-
     subject = message->lpszSubject ? message->lpszSubject : "";
     body = message->lpszNoteText ? message->lpszNoteText : "";
 
@@ -134,6 +133,17 @@ ULONG WINAPI MAPISendMail(LHANDLE session, ULONG_PTR uiparam,
     subj_size = lstrlenA(subject);
     body_size = lstrlenA(body);
 
+    attach_size = message->nFileCount * sizeof(attachment);
+    for (i = 0; i < message->nFileCount; i++)
+    {
+        TRACE("Attachment: %s\n", debugstr_a(message->lpFiles[i].lpszPathName));
+        attach_size += lstrlenA(message->lpFiles[i].lpszPathName);
+        if (message->lpFiles[i].flFlags ||
+            message->lpFiles[i].nPosition != -1L ||
+            message->lpFiles[i].lpszFileName)
+            FIXME("Some features of attachments not supported\n");
+    }
+
     ret = MAPI_E_INSUFFICIENT_MEMORY;
 
     if (to_size)
@@ -206,14 +216,30 @@ ULONG WINAPI MAPISendMail(LHANDLE session, ULONG_PTR uiparam,
         }
     }
     ret = MAPI_E_FAILURE;
-    size = sizeof(format) + to_size + cc_size + bcc_size + subj_size + body_size;
+    size = sizeof(format) + to_size + cc_size + bcc_size + subj_size +
+        body_size + attach_size;
+
+    if (attach_size)
+    {
+        attach = HeapAlloc(GetProcessHeap(), 0, attach_size);
+
+        if (!attach)
+            goto exit;
+
+        attach[0] = 0;
+        p = attach;
+
+        for (i = 0; i < message->nFileCount; i++)
+            p += sprintf(p, attachment, message->lpFiles[i].lpszPathName);
+    }
 
     mailto = HeapAlloc(GetProcessHeap(), 0, size);
 
     if (!mailto)
         goto exit;
 
-    sprintf(mailto, format, to ? to : "", subject, cc ? cc : "", bcc ? bcc : "", body);
+    sprintf(mailto, format, to ? to : "", subject, cc ? cc : "", bcc ? bcc : "",
+        body, attach ? attach : "");
 
     size = 1;
     res = UrlEscapeA(mailto, empty_string, &size, URL_ESCAPE_SPACES_ONLY);
@@ -240,6 +266,7 @@ exit:
     HeapFree(GetProcessHeap(), 0, to);
     HeapFree(GetProcessHeap(), 0, cc);
     HeapFree(GetProcessHeap(), 0, bcc);
+    HeapFree(GetProcessHeap(), 0, attach);
     HeapFree(GetProcessHeap(), 0, mailto);
     HeapFree(GetProcessHeap(), 0, escape);
 
-- 
1.7.3.4


------------e8Ehp0EWD5AyIg6qya9bPo
Content-Disposition: attachment; filename=0003-winebrowser-Add-attachment-support-eterbug-6747.txt
Content-Type: text/plain; name=0003-winebrowser-Add-attachment-support-eterbug-6747.txt
Content-Transfer-Encoding: 7bit



Подробная информация о списке рассылки Wine-patches