mfplay: Implement GetCharacteristics().
[wine/zf.git] / dlls / inetcomm / mimeole.c
blob9f2c3b8364793216835ba794fe714052448dbfba
1 /*
2 * MIME OLE Interfaces
4 * Copyright 2006 Robert Shearman for CodeWeavers
5 * Copyright 2007 Huw Davies for CodeWeavers
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library 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 GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #define COBJMACROS
23 #define NONAMELESSUNION
25 #include <stdarg.h>
26 #include <stdio.h>
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winternl.h"
31 #include "winuser.h"
32 #include "objbase.h"
33 #include "ole2.h"
34 #include "mimeole.h"
35 #include "propvarutil.h"
37 #include "wine/heap.h"
38 #include "wine/list.h"
39 #include "wine/debug.h"
41 #include "inetcomm_private.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(inetcomm);
45 typedef struct
47 LPCSTR name;
48 DWORD id;
49 DWORD flags; /* MIMEPROPFLAGS */
50 VARTYPE default_vt;
51 } property_t;
53 typedef struct
55 struct list entry;
56 property_t prop;
57 } property_list_entry_t;
59 static const property_t default_props[] =
61 {"X-Newsgroup", PID_HDR_NEWSGROUP, 0, VT_LPSTR},
62 {"Newsgroups", PID_HDR_NEWSGROUPS, 0, VT_LPSTR},
63 {"References", PID_HDR_REFS, 0, VT_LPSTR},
64 {"Subject", PID_HDR_SUBJECT, 0, VT_LPSTR},
65 {"From", PID_HDR_FROM, MPF_ADDRESS, VT_LPSTR},
66 {"Message-ID", PID_HDR_MESSAGEID, 0, VT_LPSTR},
67 {"Return-Path", PID_HDR_RETURNPATH, MPF_ADDRESS, VT_LPSTR},
68 {"Rr", PID_HDR_RR, 0, VT_LPSTR},
69 {"Return-Receipt-To", PID_HDR_RETRCPTO, MPF_ADDRESS, VT_LPSTR},
70 {"Apparently-To", PID_HDR_APPARTO, MPF_ADDRESS, VT_LPSTR},
71 {"Date", PID_HDR_DATE, 0, VT_LPSTR},
72 {"Received", PID_HDR_RECEIVED, 0, VT_LPSTR},
73 {"Reply-To", PID_HDR_REPLYTO, MPF_ADDRESS, VT_LPSTR},
74 {"X-Mailer", PID_HDR_XMAILER, 0, VT_LPSTR},
75 {"Bcc", PID_HDR_BCC, MPF_ADDRESS, VT_LPSTR},
76 {"MIME-Version", PID_HDR_MIMEVER, MPF_MIME, VT_LPSTR},
77 {"Content-Type", PID_HDR_CNTTYPE, MPF_MIME | MPF_HASPARAMS, VT_LPSTR},
78 {"Content-Transfer-Encoding", PID_HDR_CNTXFER, MPF_MIME, VT_LPSTR},
79 {"Content-ID", PID_HDR_CNTID, MPF_MIME, VT_LPSTR},
80 {"Content-Description", PID_HDR_CNTDESC, MPF_MIME, VT_LPSTR},
81 {"Content-Disposition", PID_HDR_CNTDISP, MPF_MIME | MPF_HASPARAMS, VT_LPSTR},
82 {"Content-Base", PID_HDR_CNTBASE, MPF_MIME, VT_LPSTR},
83 {"Content-Location", PID_HDR_CNTLOC, MPF_MIME, VT_LPSTR},
84 {"To", PID_HDR_TO, MPF_ADDRESS, VT_LPSTR},
85 {"Path", PID_HDR_PATH, 0, VT_LPSTR},
86 {"Followup-To", PID_HDR_FOLLOWUPTO, 0, VT_LPSTR},
87 {"Expires", PID_HDR_EXPIRES, 0, VT_LPSTR},
88 {"Cc", PID_HDR_CC, MPF_ADDRESS, VT_LPSTR},
89 {"Control", PID_HDR_CONTROL, 0, VT_LPSTR},
90 {"Distribution", PID_HDR_DISTRIB, 0, VT_LPSTR},
91 {"Keywords", PID_HDR_KEYWORDS, 0, VT_LPSTR},
92 {"Summary", PID_HDR_SUMMARY, 0, VT_LPSTR},
93 {"Approved", PID_HDR_APPROVED, 0, VT_LPSTR},
94 {"Lines", PID_HDR_LINES, 0, VT_LPSTR},
95 {"Xref", PID_HDR_XREF, 0, VT_LPSTR},
96 {"Organization", PID_HDR_ORG, 0, VT_LPSTR},
97 {"X-Newsreader", PID_HDR_XNEWSRDR, 0, VT_LPSTR},
98 {"X-Priority", PID_HDR_XPRI, 0, VT_LPSTR},
99 {"X-MSMail-Priority", PID_HDR_XMSPRI, 0, VT_LPSTR},
100 {"par:content-disposition:filename", PID_PAR_FILENAME, 0, VT_LPSTR},
101 {"par:content-type:boundary", PID_PAR_BOUNDARY, 0, VT_LPSTR},
102 {"par:content-type:charset", PID_PAR_CHARSET, 0, VT_LPSTR},
103 {"par:content-type:name", PID_PAR_NAME, 0, VT_LPSTR},
104 {"att:filename", PID_ATT_FILENAME, 0, VT_LPSTR},
105 {"att:pri-content-type", PID_ATT_PRITYPE, 0, VT_LPSTR},
106 {"att:sub-content-type", PID_ATT_SUBTYPE, 0, VT_LPSTR},
107 {"att:illegal-lines", PID_ATT_ILLEGAL, 0, VT_LPSTR},
108 {"att:rendered", PID_ATT_RENDERED, 0, VT_LPSTR},
109 {"att:sent-time", PID_ATT_SENTTIME, 0, VT_LPSTR},
110 {"att:priority", PID_ATT_PRIORITY, 0, VT_LPSTR},
111 {"Comment", PID_HDR_COMMENT, 0, VT_LPSTR},
112 {"Encoding", PID_HDR_ENCODING, 0, VT_LPSTR},
113 {"Encrypted", PID_HDR_ENCRYPTED, 0, VT_LPSTR},
114 {"X-Offsets", PID_HDR_OFFSETS, 0, VT_LPSTR},
115 {"X-Unsent", PID_HDR_XUNSENT, 0, VT_LPSTR},
116 {"X-ArticleId", PID_HDR_ARTICLEID, 0, VT_LPSTR},
117 {"Sender", PID_HDR_SENDER, MPF_ADDRESS, VT_LPSTR},
118 {"att:athena-server", PID_ATT_SERVER, 0, VT_LPSTR},
119 {"att:athena-account-id", PID_ATT_ACCOUNT, 0, VT_LPSTR},
120 {"att:athena-pop3-uidl", PID_ATT_UIDL, 0, VT_LPSTR},
121 {"att:athena-store-msgid", PID_ATT_STOREMSGID, 0, VT_LPSTR},
122 {"att:athena-user-name", PID_ATT_USERNAME, 0, VT_LPSTR},
123 {"att:athena-forward-to", PID_ATT_FORWARDTO, 0, VT_LPSTR},
124 {"att:athena-store-fdrid", PID_ATT_STOREFOLDERID,0, VT_LPSTR},
125 {"att:athena-ghosted", PID_ATT_GHOSTED, 0, VT_LPSTR},
126 {"att:athena-uncachedsize", PID_ATT_UNCACHEDSIZE, 0, VT_LPSTR},
127 {"att:athena-combined", PID_ATT_COMBINED, 0, VT_LPSTR},
128 {"att:auto-inlined", PID_ATT_AUTOINLINED, 0, VT_LPSTR},
129 {"Disposition-Notification-To", PID_HDR_DISP_NOTIFICATION_TO, 0, VT_LPSTR},
130 {"par:Content-Type:reply-type", PID_PAR_REPLYTYPE, 0, VT_LPSTR},
131 {"par:Content-Type:format", PID_PAR_FORMAT , 0, VT_LPSTR},
132 {"att:format", PID_ATT_FORMAT , 0, VT_LPSTR},
133 {"In-Reply-To", PID_HDR_INREPLYTO, 0, VT_LPSTR},
134 {"att:athena-account-name", PID_ATT_ACCOUNTNAME, 0, VT_LPSTR},
135 {NULL, 0, 0, 0}
138 typedef struct
140 struct list entry;
141 char *name;
142 char *value;
143 } param_t;
145 typedef struct
147 struct list entry;
148 const property_t *prop;
149 PROPVARIANT value;
150 struct list params;
151 } header_t;
153 typedef struct MimeBody
155 IMimeBody IMimeBody_iface;
156 LONG ref;
158 HBODY handle;
160 struct list headers;
161 struct list new_props; /* FIXME: This should be in a PropertySchema */
162 DWORD next_prop_id;
163 char *content_pri_type;
164 char *content_sub_type;
165 ENCODINGTYPE encoding;
166 void *data;
167 IID data_iid;
168 BODYOFFSETS body_offsets;
169 } MimeBody;
171 typedef struct
173 IStream IStream_iface;
174 LONG ref;
175 IStream *base;
176 ULARGE_INTEGER pos, start, length;
177 } sub_stream_t;
179 static inline sub_stream_t *impl_from_IStream(IStream *iface)
181 return CONTAINING_RECORD(iface, sub_stream_t, IStream_iface);
184 static HRESULT WINAPI sub_stream_QueryInterface(IStream *iface, REFIID riid, void **ppv)
186 sub_stream_t *This = impl_from_IStream(iface);
188 TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), ppv);
189 *ppv = NULL;
191 if(IsEqualIID(riid, &IID_IUnknown) ||
192 IsEqualIID(riid, &IID_ISequentialStream) ||
193 IsEqualIID(riid, &IID_IStream))
195 IStream_AddRef(iface);
196 *ppv = iface;
197 return S_OK;
199 return E_NOINTERFACE;
202 static ULONG WINAPI sub_stream_AddRef(IStream *iface)
204 sub_stream_t *This = impl_from_IStream(iface);
205 LONG ref = InterlockedIncrement(&This->ref);
207 TRACE("(%p) ref=%d\n", This, ref);
209 return ref;
212 static ULONG WINAPI sub_stream_Release(IStream *iface)
214 sub_stream_t *This = impl_from_IStream(iface);
215 LONG ref = InterlockedDecrement(&This->ref);
217 TRACE("(%p) ref=%d\n", This, ref);
219 if(!ref)
221 IStream_Release(This->base);
222 HeapFree(GetProcessHeap(), 0, This);
224 return ref;
227 static HRESULT WINAPI sub_stream_Read(
228 IStream* iface,
229 void *pv,
230 ULONG cb,
231 ULONG *pcbRead)
233 sub_stream_t *This = impl_from_IStream(iface);
234 HRESULT hr;
235 LARGE_INTEGER tmp_pos;
237 TRACE("(%p, %d, %p)\n", pv, cb, pcbRead);
239 tmp_pos.QuadPart = This->pos.QuadPart + This->start.QuadPart;
240 IStream_Seek(This->base, tmp_pos, STREAM_SEEK_SET, NULL);
242 if(This->pos.QuadPart + cb > This->length.QuadPart)
243 cb = This->length.QuadPart - This->pos.QuadPart;
245 hr = IStream_Read(This->base, pv, cb, pcbRead);
247 This->pos.QuadPart += *pcbRead;
249 return hr;
252 static HRESULT WINAPI sub_stream_Write(
253 IStream* iface,
254 const void *pv,
255 ULONG cb,
256 ULONG *pcbWritten)
258 FIXME("stub\n");
259 return E_NOTIMPL;
262 static HRESULT WINAPI sub_stream_Seek(
263 IStream* iface,
264 LARGE_INTEGER dlibMove,
265 DWORD dwOrigin,
266 ULARGE_INTEGER *plibNewPosition)
268 sub_stream_t *This = impl_from_IStream(iface);
269 LARGE_INTEGER new_pos;
271 TRACE("(%08x.%08x, %x, %p)\n", dlibMove.u.HighPart, dlibMove.u.LowPart, dwOrigin, plibNewPosition);
273 switch(dwOrigin)
275 case STREAM_SEEK_SET:
276 new_pos = dlibMove;
277 break;
278 case STREAM_SEEK_CUR:
279 new_pos.QuadPart = This->pos.QuadPart + dlibMove.QuadPart;
280 break;
281 case STREAM_SEEK_END:
282 new_pos.QuadPart = This->length.QuadPart + dlibMove.QuadPart;
283 break;
284 default:
285 return STG_E_INVALIDFUNCTION;
288 if(new_pos.QuadPart < 0) new_pos.QuadPart = 0;
289 else if(new_pos.QuadPart > This->length.QuadPart) new_pos.QuadPart = This->length.QuadPart;
291 This->pos.QuadPart = new_pos.QuadPart;
293 if(plibNewPosition) *plibNewPosition = This->pos;
294 return S_OK;
297 static HRESULT WINAPI sub_stream_SetSize(
298 IStream* iface,
299 ULARGE_INTEGER libNewSize)
301 FIXME("stub\n");
302 return E_NOTIMPL;
305 static HRESULT WINAPI sub_stream_CopyTo(
306 IStream* iface,
307 IStream *pstm,
308 ULARGE_INTEGER cb,
309 ULARGE_INTEGER *pcbRead,
310 ULARGE_INTEGER *pcbWritten)
312 HRESULT hr = S_OK;
313 BYTE tmpBuffer[128];
314 ULONG bytesRead, bytesWritten, copySize;
315 ULARGE_INTEGER totalBytesRead;
316 ULARGE_INTEGER totalBytesWritten;
318 TRACE("(%p)->(%p, %d, %p, %p)\n", iface, pstm, cb.u.LowPart, pcbRead, pcbWritten);
320 totalBytesRead.QuadPart = 0;
321 totalBytesWritten.QuadPart = 0;
323 while ( cb.QuadPart > 0 )
325 if ( cb.QuadPart >= sizeof(tmpBuffer) )
326 copySize = sizeof(tmpBuffer);
327 else
328 copySize = cb.u.LowPart;
330 hr = IStream_Read(iface, tmpBuffer, copySize, &bytesRead);
331 if (FAILED(hr)) break;
333 totalBytesRead.QuadPart += bytesRead;
335 if (bytesRead)
337 hr = IStream_Write(pstm, tmpBuffer, bytesRead, &bytesWritten);
338 if (FAILED(hr)) break;
339 totalBytesWritten.QuadPart += bytesWritten;
342 if (bytesRead != copySize)
343 cb.QuadPart = 0;
344 else
345 cb.QuadPart -= bytesRead;
348 if (pcbRead) pcbRead->QuadPart = totalBytesRead.QuadPart;
349 if (pcbWritten) pcbWritten->QuadPart = totalBytesWritten.QuadPart;
351 return hr;
354 static HRESULT WINAPI sub_stream_Commit(
355 IStream* iface,
356 DWORD grfCommitFlags)
358 FIXME("stub\n");
359 return E_NOTIMPL;
362 static HRESULT WINAPI sub_stream_Revert(
363 IStream* iface)
365 FIXME("stub\n");
366 return E_NOTIMPL;
369 static HRESULT WINAPI sub_stream_LockRegion(
370 IStream* iface,
371 ULARGE_INTEGER libOffset,
372 ULARGE_INTEGER cb,
373 DWORD dwLockType)
375 FIXME("stub\n");
376 return E_NOTIMPL;
379 static HRESULT WINAPI sub_stream_UnlockRegion(
380 IStream* iface,
381 ULARGE_INTEGER libOffset,
382 ULARGE_INTEGER cb,
383 DWORD dwLockType)
385 FIXME("stub\n");
386 return E_NOTIMPL;
389 static HRESULT WINAPI sub_stream_Stat(
390 IStream* iface,
391 STATSTG *pstatstg,
392 DWORD grfStatFlag)
394 sub_stream_t *This = impl_from_IStream(iface);
395 FIXME("(%p)->(%p, %08x)\n", This, pstatstg, grfStatFlag);
396 memset(pstatstg, 0, sizeof(*pstatstg));
397 pstatstg->cbSize = This->length;
398 return S_OK;
401 static HRESULT WINAPI sub_stream_Clone(
402 IStream* iface,
403 IStream **ppstm)
405 FIXME("stub\n");
406 return E_NOTIMPL;
409 static struct IStreamVtbl sub_stream_vtbl =
411 sub_stream_QueryInterface,
412 sub_stream_AddRef,
413 sub_stream_Release,
414 sub_stream_Read,
415 sub_stream_Write,
416 sub_stream_Seek,
417 sub_stream_SetSize,
418 sub_stream_CopyTo,
419 sub_stream_Commit,
420 sub_stream_Revert,
421 sub_stream_LockRegion,
422 sub_stream_UnlockRegion,
423 sub_stream_Stat,
424 sub_stream_Clone
427 static HRESULT create_sub_stream(IStream *stream, ULARGE_INTEGER start, ULARGE_INTEGER length, IStream **out)
429 sub_stream_t *This;
431 *out = NULL;
432 This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
433 if(!This) return E_OUTOFMEMORY;
435 This->IStream_iface.lpVtbl = &sub_stream_vtbl;
436 This->ref = 1;
437 This->start = start;
438 This->length = length;
439 This->pos.QuadPart = 0;
440 IStream_AddRef(stream);
441 This->base = stream;
443 *out = &This->IStream_iface;
444 return S_OK;
447 static HRESULT get_stream_size(IStream *stream, ULARGE_INTEGER *size)
449 STATSTG statstg = {NULL};
450 LARGE_INTEGER zero;
451 HRESULT hres;
453 hres = IStream_Stat(stream, &statstg, STATFLAG_NONAME);
454 if(SUCCEEDED(hres)) {
455 *size = statstg.cbSize;
456 return S_OK;
459 zero.QuadPart = 0;
460 return IStream_Seek(stream, zero, STREAM_SEEK_END, size);
463 static inline MimeBody *impl_from_IMimeBody(IMimeBody *iface)
465 return CONTAINING_RECORD(iface, MimeBody, IMimeBody_iface);
468 typedef struct propschema
470 IMimePropertySchema IMimePropertySchema_iface;
471 LONG ref;
472 } propschema;
474 static inline propschema *impl_from_IMimePropertySchema(IMimePropertySchema *iface)
476 return CONTAINING_RECORD(iface, propschema, IMimePropertySchema_iface);
479 static LPSTR strdupA(LPCSTR str)
481 char *ret;
482 int len = strlen(str);
483 ret = HeapAlloc(GetProcessHeap(), 0, len + 1);
484 memcpy(ret, str, len + 1);
485 return ret;
488 #define PARSER_BUF_SIZE 1024
490 /*****************************************************
491 * copy_headers_to_buf [internal]
493 * Copies the headers into a '\0' terminated memory block and leave
494 * the stream's current position set to after the blank line.
496 static HRESULT copy_headers_to_buf(IStream *stm, char **ptr)
498 char *buf = NULL;
499 DWORD size = PARSER_BUF_SIZE, offset = 0, last_end = 0;
500 HRESULT hr;
501 BOOL done = FALSE;
503 *ptr = NULL;
507 char *end;
508 DWORD read;
510 if(!buf)
511 buf = HeapAlloc(GetProcessHeap(), 0, size + 1);
512 else
514 size *= 2;
515 buf = HeapReAlloc(GetProcessHeap(), 0, buf, size + 1);
517 if(!buf)
519 hr = E_OUTOFMEMORY;
520 goto fail;
523 hr = IStream_Read(stm, buf + offset, size - offset, &read);
524 if(FAILED(hr)) goto fail;
526 offset += read;
527 buf[offset] = '\0';
529 if(read == 0) done = TRUE;
531 while(!done && (end = strstr(buf + last_end, "\r\n")))
533 DWORD new_end = end - buf + 2;
534 if(new_end - last_end == 2)
536 LARGE_INTEGER off;
537 off.QuadPart = (LONGLONG)new_end - offset;
538 IStream_Seek(stm, off, STREAM_SEEK_CUR, NULL);
539 buf[new_end] = '\0';
540 done = TRUE;
542 else
543 last_end = new_end;
545 } while(!done);
547 *ptr = buf;
548 return S_OK;
550 fail:
551 HeapFree(GetProcessHeap(), 0, buf);
552 return hr;
555 static header_t *read_prop(MimeBody *body, char **ptr)
557 char *colon = strchr(*ptr, ':');
558 const property_t *prop;
559 header_t *ret;
561 if(!colon) return NULL;
563 *colon = '\0';
565 for(prop = default_props; prop->name; prop++)
567 if(!lstrcmpiA(*ptr, prop->name))
569 TRACE("%s: found match with default property id %d\n", *ptr, prop->id);
570 break;
574 if(!prop->name)
576 property_list_entry_t *prop_entry;
577 LIST_FOR_EACH_ENTRY(prop_entry, &body->new_props, property_list_entry_t, entry)
579 if(!lstrcmpiA(*ptr, prop_entry->prop.name))
581 TRACE("%s: found match with already added new property id %d\n", *ptr, prop_entry->prop.id);
582 prop = &prop_entry->prop;
583 break;
586 if(!prop->name)
588 prop_entry = HeapAlloc(GetProcessHeap(), 0, sizeof(*prop_entry));
589 prop_entry->prop.name = strdupA(*ptr);
590 prop_entry->prop.id = body->next_prop_id++;
591 prop_entry->prop.flags = 0;
592 prop_entry->prop.default_vt = VT_LPSTR;
593 list_add_tail(&body->new_props, &prop_entry->entry);
594 prop = &prop_entry->prop;
595 TRACE("%s: allocating new prop id %d\n", *ptr, prop_entry->prop.id);
599 ret = HeapAlloc(GetProcessHeap(), 0, sizeof(*ret));
600 ret->prop = prop;
601 PropVariantInit(&ret->value);
602 list_init(&ret->params);
603 *ptr = colon + 1;
605 return ret;
608 static void unfold_header(char *header, int len)
610 char *start = header, *cp = header;
612 do {
613 while(*cp == ' ' || *cp == '\t')
615 cp++;
616 len--;
618 if(cp != start)
619 memmove(start, cp, len + 1);
621 cp = strstr(start, "\r\n");
622 len -= (cp - start);
623 start = cp;
624 *start = ' ';
625 start++;
626 len--;
627 cp += 2;
628 } while(*cp == ' ' || *cp == '\t');
630 *(start - 1) = '\0';
633 static char *unquote_string(const char *str)
635 BOOL quoted = FALSE;
636 char *ret, *cp;
638 while(*str == ' ' || *str == '\t') str++;
640 if(*str == '"')
642 quoted = TRUE;
643 str++;
645 ret = strdupA(str);
646 for(cp = ret; *cp; cp++)
648 if(*cp == '\\')
649 memmove(cp, cp + 1, strlen(cp + 1) + 1);
650 else if(*cp == '"')
652 if(!quoted)
654 WARN("quote in unquoted string\n");
656 else
658 *cp = '\0';
659 break;
663 return ret;
666 static void add_param(header_t *header, const char *p)
668 const char *key = p, *value, *cp = p;
669 param_t *param;
670 char *name;
672 TRACE("got param %s\n", p);
674 while (*key == ' ' || *key == '\t' ) key++;
676 cp = strchr(key, '=');
677 if(!cp)
679 WARN("malformed parameter - skipping\n");
680 return;
683 name = HeapAlloc(GetProcessHeap(), 0, cp - key + 1);
684 memcpy(name, key, cp - key);
685 name[cp - key] = '\0';
687 value = cp + 1;
689 param = HeapAlloc(GetProcessHeap(), 0, sizeof(*param));
690 param->name = name;
691 param->value = unquote_string(value);
692 list_add_tail(&header->params, &param->entry);
695 static void split_params(header_t *header, char *value)
697 char *cp = value, *start = value;
698 BOOL in_quotes = FALSE, done_value = FALSE;
700 while(*cp)
702 if(!in_quotes && *cp == ';')
704 *cp = '\0';
705 if(done_value) add_param(header, start);
706 done_value = TRUE;
707 start = cp + 1;
709 else if(*cp == '"')
710 in_quotes = !in_quotes;
711 cp++;
713 if(done_value) add_param(header, start);
716 static void read_value(header_t *header, char **cur)
718 char *end = *cur, *value;
719 DWORD len;
721 do {
722 end = strstr(end, "\r\n");
723 end += 2;
724 } while(*end == ' ' || *end == '\t');
726 len = end - *cur;
727 value = HeapAlloc(GetProcessHeap(), 0, len + 1);
728 memcpy(value, *cur, len);
729 value[len] = '\0';
731 unfold_header(value, len);
732 TRACE("value %s\n", debugstr_a(value));
734 if(header->prop->flags & MPF_HASPARAMS)
736 split_params(header, value);
737 TRACE("value w/o params %s\n", debugstr_a(value));
740 header->value.vt = VT_LPSTR;
741 header->value.pszVal = value;
743 *cur = end;
746 static void init_content_type(MimeBody *body, header_t *header)
748 char *slash;
749 DWORD len;
751 slash = strchr(header->value.pszVal, '/');
752 if(!slash)
754 WARN("malformed context type value\n");
755 return;
757 len = slash - header->value.pszVal;
758 body->content_pri_type = HeapAlloc(GetProcessHeap(), 0, len + 1);
759 memcpy(body->content_pri_type, header->value.pszVal, len);
760 body->content_pri_type[len] = '\0';
761 body->content_sub_type = strdupA(slash + 1);
764 static void init_content_encoding(MimeBody *body, header_t *header)
766 const char *encoding = header->value.pszVal;
768 if(!stricmp(encoding, "base64"))
769 body->encoding = IET_BASE64;
770 else if(!stricmp(encoding, "quoted-printable"))
771 body->encoding = IET_QP;
772 else if(!stricmp(encoding, "7bit"))
773 body->encoding = IET_7BIT;
774 else if(!stricmp(encoding, "8bit"))
775 body->encoding = IET_8BIT;
776 else
777 FIXME("unknown encoding %s\n", debugstr_a(encoding));
780 static HRESULT parse_headers(MimeBody *body, IStream *stm)
782 char *header_buf, *cur_header_ptr;
783 HRESULT hr;
784 header_t *header;
786 hr = copy_headers_to_buf(stm, &header_buf);
787 if(FAILED(hr)) return hr;
789 cur_header_ptr = header_buf;
790 while((header = read_prop(body, &cur_header_ptr)))
792 read_value(header, &cur_header_ptr);
793 list_add_tail(&body->headers, &header->entry);
795 switch(header->prop->id) {
796 case PID_HDR_CNTTYPE:
797 init_content_type(body, header);
798 break;
799 case PID_HDR_CNTXFER:
800 init_content_encoding(body, header);
801 break;
805 HeapFree(GetProcessHeap(), 0, header_buf);
806 return hr;
809 static void empty_param_list(struct list *list)
811 param_t *param, *cursor2;
813 LIST_FOR_EACH_ENTRY_SAFE(param, cursor2, list, param_t, entry)
815 list_remove(&param->entry);
816 HeapFree(GetProcessHeap(), 0, param->name);
817 HeapFree(GetProcessHeap(), 0, param->value);
818 HeapFree(GetProcessHeap(), 0, param);
822 static void free_header(header_t *header)
824 list_remove(&header->entry);
825 PropVariantClear(&header->value);
826 empty_param_list(&header->params);
827 heap_free(header);
830 static void empty_header_list(struct list *list)
832 header_t *header, *cursor2;
834 LIST_FOR_EACH_ENTRY_SAFE(header, cursor2, list, header_t, entry)
836 free_header(header);
840 static void empty_new_prop_list(struct list *list)
842 property_list_entry_t *prop, *cursor2;
844 LIST_FOR_EACH_ENTRY_SAFE(prop, cursor2, list, property_list_entry_t, entry)
846 list_remove(&prop->entry);
847 HeapFree(GetProcessHeap(), 0, (char *)prop->prop.name);
848 HeapFree(GetProcessHeap(), 0, prop);
852 static void release_data(REFIID riid, void *data)
854 if(!data) return;
856 if(IsEqualIID(riid, &IID_IStream))
857 IStream_Release((IStream *)data);
858 else
859 FIXME("Unhandled data format %s\n", debugstr_guid(riid));
862 static HRESULT find_prop(MimeBody *body, const char *name, header_t **prop)
864 header_t *header;
866 *prop = NULL;
868 LIST_FOR_EACH_ENTRY(header, &body->headers, header_t, entry)
870 if(ISPIDSTR(name))
872 if(STRTOPID(name) == header->prop->id)
874 *prop = header;
875 return S_OK;
878 else if(!lstrcmpiA(name, header->prop->name))
880 *prop = header;
881 return S_OK;
885 return MIME_E_NOT_FOUND;
888 static const property_t *find_default_prop(const char *name)
890 const property_t *prop_def = NULL;
892 for(prop_def = default_props; prop_def->name; prop_def++)
894 if(ISPIDSTR(name))
896 if(STRTOPID(name) == prop_def->id)
898 break;
901 else if(!lstrcmpiA(name, prop_def->name))
903 break;
907 if(prop_def->id)
908 TRACE("%s: found match with default property id %d\n", prop_def->name, prop_def->id);
909 else
910 prop_def = NULL;
912 return prop_def;
915 static HRESULT WINAPI MimeBody_QueryInterface(IMimeBody* iface,
916 REFIID riid,
917 void** ppvObject)
919 TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppvObject);
921 *ppvObject = NULL;
923 if (IsEqualIID(riid, &IID_IUnknown) ||
924 IsEqualIID(riid, &IID_IPersist) ||
925 IsEqualIID(riid, &IID_IPersistStreamInit) ||
926 IsEqualIID(riid, &IID_IMimePropertySet) ||
927 IsEqualIID(riid, &IID_IMimeBody))
929 *ppvObject = iface;
932 if(*ppvObject)
934 IUnknown_AddRef((IUnknown*)*ppvObject);
935 return S_OK;
938 FIXME("no interface for %s\n", debugstr_guid(riid));
939 return E_NOINTERFACE;
942 static ULONG WINAPI MimeBody_AddRef(IMimeBody *iface)
944 MimeBody *This = impl_from_IMimeBody(iface);
945 LONG ref = InterlockedIncrement(&This->ref);
947 TRACE("(%p) ref=%d\n", This, ref);
949 return ref;
952 static ULONG WINAPI MimeBody_Release(IMimeBody *iface)
954 MimeBody *This = impl_from_IMimeBody(iface);
955 LONG ref = InterlockedDecrement(&This->ref);
957 TRACE("(%p) ref=%d\n", This, ref);
959 if (!ref)
961 empty_header_list(&This->headers);
962 empty_new_prop_list(&This->new_props);
964 HeapFree(GetProcessHeap(), 0, This->content_pri_type);
965 HeapFree(GetProcessHeap(), 0, This->content_sub_type);
967 release_data(&This->data_iid, This->data);
969 HeapFree(GetProcessHeap(), 0, This);
972 return ref;
975 static HRESULT WINAPI MimeBody_GetClassID(
976 IMimeBody* iface,
977 CLSID* pClassID)
979 MimeBody *This = impl_from_IMimeBody(iface);
981 TRACE("(%p)->(%p)\n", This, pClassID);
983 if(!pClassID)
984 return E_INVALIDARG;
986 *pClassID = IID_IMimeBody;
987 return S_OK;
990 static HRESULT WINAPI MimeBody_IsDirty(
991 IMimeBody* iface)
993 MimeBody *This = impl_from_IMimeBody(iface);
994 FIXME("(%p)->() stub\n", This);
995 return E_NOTIMPL;
998 static HRESULT WINAPI MimeBody_Load(IMimeBody *iface, IStream *pStm)
1000 MimeBody *This = impl_from_IMimeBody(iface);
1001 TRACE("(%p)->(%p)\n", This, pStm);
1002 return parse_headers(This, pStm);
1005 static HRESULT WINAPI MimeBody_Save(IMimeBody *iface, IStream *pStm, BOOL fClearDirty)
1007 MimeBody *This = impl_from_IMimeBody(iface);
1008 FIXME("(%p)->(%p, %d)\n", This, pStm, fClearDirty);
1009 return E_NOTIMPL;
1012 static HRESULT WINAPI MimeBody_GetSizeMax(
1013 IMimeBody* iface,
1014 ULARGE_INTEGER* pcbSize)
1016 MimeBody *This = impl_from_IMimeBody(iface);
1017 FIXME("(%p)->(%p) stub\n", This, pcbSize);
1018 return E_NOTIMPL;
1021 static HRESULT WINAPI MimeBody_InitNew(
1022 IMimeBody* iface)
1024 MimeBody *This = impl_from_IMimeBody(iface);
1025 TRACE("(%p)->()\n", This);
1026 return S_OK;
1029 static HRESULT WINAPI MimeBody_GetPropInfo(
1030 IMimeBody* iface,
1031 LPCSTR pszName,
1032 LPMIMEPROPINFO pInfo)
1034 MimeBody *This = impl_from_IMimeBody(iface);
1035 header_t *header;
1036 HRESULT hr;
1037 DWORD supported = PIM_PROPID | PIM_VTDEFAULT;
1039 TRACE("(%p)->(%s, %p) semi-stub\n", This, debugstr_a(pszName), pInfo);
1041 if(!pszName || !pInfo)
1042 return E_INVALIDARG;
1044 TRACE("mask 0x%04x\n", pInfo->dwMask);
1046 if(pInfo->dwMask & ~supported)
1047 FIXME("Unsupported mask flags 0x%04x\n", pInfo->dwMask & ~supported);
1049 hr = find_prop(This, pszName, &header);
1050 if(hr == S_OK)
1052 if(pInfo->dwMask & PIM_CHARSET)
1053 pInfo->hCharset = 0;
1054 if(pInfo->dwMask & PIM_FLAGS)
1055 pInfo->dwFlags = 0x00000000;
1056 if(pInfo->dwMask & PIM_ROWNUMBER)
1057 pInfo->dwRowNumber = 0;
1058 if(pInfo->dwMask & PIM_ENCODINGTYPE)
1059 pInfo->ietEncoding = 0;
1060 if(pInfo->dwMask & PIM_VALUES)
1061 pInfo->cValues = 0;
1062 if(pInfo->dwMask & PIM_PROPID)
1063 pInfo->dwPropId = header->prop->id;
1064 if(pInfo->dwMask & PIM_VTDEFAULT)
1065 pInfo->vtDefault = header->prop->default_vt;
1066 if(pInfo->dwMask & PIM_VTCURRENT)
1067 pInfo->vtCurrent = 0;
1070 return hr;
1073 static HRESULT WINAPI MimeBody_SetPropInfo(
1074 IMimeBody* iface,
1075 LPCSTR pszName,
1076 LPCMIMEPROPINFO pInfo)
1078 MimeBody *This = impl_from_IMimeBody(iface);
1079 FIXME("(%p)->(%s, %p) stub\n", This, debugstr_a(pszName), pInfo);
1080 return E_NOTIMPL;
1083 static HRESULT WINAPI MimeBody_GetProp(
1084 IMimeBody* iface,
1085 LPCSTR pszName,
1086 DWORD dwFlags,
1087 LPPROPVARIANT pValue)
1089 MimeBody *This = impl_from_IMimeBody(iface);
1090 header_t *header;
1091 HRESULT hr;
1093 TRACE("(%p)->(%s, 0x%x, %p)\n", This, debugstr_a(pszName), dwFlags, pValue);
1095 if(!pszName || !pValue)
1096 return E_INVALIDARG;
1098 if(!ISPIDSTR(pszName) && !lstrcmpiA(pszName, "att:pri-content-type"))
1100 PropVariantClear(pValue);
1101 pValue->vt = VT_LPSTR;
1102 pValue->pszVal = strdupA(This->content_pri_type);
1103 return S_OK;
1106 hr = find_prop(This, pszName, &header);
1107 if(hr == S_OK)
1109 TRACE("type %d->%d\n", header->value.vt, pValue->vt);
1111 hr = PropVariantChangeType(pValue, &header->value, 0, pValue->vt);
1112 if(FAILED(hr))
1113 FIXME("Conversion not currently supported (%d->%d)\n", header->value.vt, pValue->vt);
1116 return hr;
1119 static HRESULT WINAPI MimeBody_SetProp(
1120 IMimeBody* iface,
1121 LPCSTR pszName,
1122 DWORD dwFlags,
1123 LPCPROPVARIANT pValue)
1125 MimeBody *This = impl_from_IMimeBody(iface);
1126 header_t *header;
1127 HRESULT hr;
1129 TRACE("(%p)->(%s, 0x%x, %p)\n", This, debugstr_a(pszName), dwFlags, pValue);
1131 if(!pszName || !pValue)
1132 return E_INVALIDARG;
1134 hr = find_prop(This, pszName, &header);
1135 if(hr != S_OK)
1137 property_list_entry_t *prop_entry;
1138 const property_t *prop = NULL;
1140 LIST_FOR_EACH_ENTRY(prop_entry, &This->new_props, property_list_entry_t, entry)
1142 if(ISPIDSTR(pszName))
1144 if(STRTOPID(pszName) == prop_entry->prop.id)
1146 TRACE("Found match with already added new property id %d\n", prop_entry->prop.id);
1147 prop = &prop_entry->prop;
1148 break;
1151 else if(!lstrcmpiA(pszName, prop_entry->prop.name))
1153 TRACE("Found match with already added new property id %d\n", prop_entry->prop.id);
1154 prop = &prop_entry->prop;
1155 break;
1159 header = HeapAlloc(GetProcessHeap(), 0, sizeof(*header));
1160 if(!header)
1161 return E_OUTOFMEMORY;
1163 if(!prop)
1165 const property_t *prop_def = NULL;
1166 prop_entry = HeapAlloc(GetProcessHeap(), 0, sizeof(*prop_entry));
1167 if(!prop_entry)
1169 HeapFree(GetProcessHeap(), 0, header);
1170 return E_OUTOFMEMORY;
1173 prop_def = find_default_prop(pszName);
1174 if(prop_def)
1176 prop_entry->prop.name = strdupA(prop_def->name);
1177 prop_entry->prop.id = prop_def->id;
1179 else
1181 if(ISPIDSTR(pszName))
1183 HeapFree(GetProcessHeap(), 0, prop_entry);
1184 HeapFree(GetProcessHeap(), 0, header);
1185 return MIME_E_NOT_FOUND;
1188 prop_entry->prop.name = strdupA(pszName);
1189 prop_entry->prop.id = This->next_prop_id++;
1192 prop_entry->prop.flags = 0;
1193 prop_entry->prop.default_vt = pValue->vt;
1194 list_add_tail(&This->new_props, &prop_entry->entry);
1195 prop = &prop_entry->prop;
1196 TRACE("Allocating new prop id %d\n", prop_entry->prop.id);
1199 header->prop = prop;
1200 PropVariantInit(&header->value);
1201 list_init(&header->params);
1202 list_add_tail(&This->headers, &header->entry);
1205 PropVariantCopy(&header->value, pValue);
1207 return S_OK;
1210 static HRESULT WINAPI MimeBody_AppendProp(
1211 IMimeBody* iface,
1212 LPCSTR pszName,
1213 DWORD dwFlags,
1214 LPPROPVARIANT pValue)
1216 MimeBody *This = impl_from_IMimeBody(iface);
1217 FIXME("(%p)->(%s, 0x%x, %p) stub\n", This, debugstr_a(pszName), dwFlags, pValue);
1218 return E_NOTIMPL;
1221 static HRESULT WINAPI MimeBody_DeleteProp(
1222 IMimeBody* iface,
1223 LPCSTR pszName)
1225 MimeBody *This = impl_from_IMimeBody(iface);
1226 header_t *cursor;
1227 BOOL found;
1229 TRACE("(%p)->(%s) stub\n", This, debugstr_a(pszName));
1231 LIST_FOR_EACH_ENTRY(cursor, &This->headers, header_t, entry)
1233 if(ISPIDSTR(pszName))
1234 found = STRTOPID(pszName) == cursor->prop->id;
1235 else
1236 found = !lstrcmpiA(pszName, cursor->prop->name);
1238 if(found)
1240 free_header(cursor);
1241 return S_OK;
1245 return MIME_E_NOT_FOUND;
1248 static HRESULT WINAPI MimeBody_CopyProps(
1249 IMimeBody* iface,
1250 ULONG cNames,
1251 LPCSTR* prgszName,
1252 IMimePropertySet* pPropertySet)
1254 MimeBody *This = impl_from_IMimeBody(iface);
1255 FIXME("(%p)->(%d, %p, %p) stub\n", This, cNames, prgszName, pPropertySet);
1256 return E_NOTIMPL;
1259 static HRESULT WINAPI MimeBody_MoveProps(
1260 IMimeBody* iface,
1261 ULONG cNames,
1262 LPCSTR* prgszName,
1263 IMimePropertySet* pPropertySet)
1265 MimeBody *This = impl_from_IMimeBody(iface);
1266 FIXME("(%p)->(%d, %p, %p) stub\n", This, cNames, prgszName, pPropertySet);
1267 return E_NOTIMPL;
1270 static HRESULT WINAPI MimeBody_DeleteExcept(
1271 IMimeBody* iface,
1272 ULONG cNames,
1273 LPCSTR* prgszName)
1275 MimeBody *This = impl_from_IMimeBody(iface);
1276 FIXME("(%p)->(%d, %p) stub\n", This, cNames, prgszName);
1277 return E_NOTIMPL;
1280 static HRESULT WINAPI MimeBody_QueryProp(
1281 IMimeBody* iface,
1282 LPCSTR pszName,
1283 LPCSTR pszCriteria,
1284 boolean fSubString,
1285 boolean fCaseSensitive)
1287 MimeBody *This = impl_from_IMimeBody(iface);
1288 FIXME("(%p)->(%s, %s, %d, %d) stub\n", This, debugstr_a(pszName), debugstr_a(pszCriteria), fSubString, fCaseSensitive);
1289 return E_NOTIMPL;
1292 static HRESULT WINAPI MimeBody_GetCharset(
1293 IMimeBody* iface,
1294 LPHCHARSET phCharset)
1296 MimeBody *This = impl_from_IMimeBody(iface);
1297 FIXME("(%p)->(%p) stub\n", This, phCharset);
1298 *phCharset = NULL;
1299 return S_OK;
1302 static HRESULT WINAPI MimeBody_SetCharset(
1303 IMimeBody* iface,
1304 HCHARSET hCharset,
1305 CSETAPPLYTYPE applytype)
1307 MimeBody *This = impl_from_IMimeBody(iface);
1308 FIXME("(%p)->(%p, %d) stub\n", This, hCharset, applytype);
1309 return E_NOTIMPL;
1312 static HRESULT WINAPI MimeBody_GetParameters(
1313 IMimeBody* iface,
1314 LPCSTR pszName,
1315 ULONG* pcParams,
1316 LPMIMEPARAMINFO* pprgParam)
1318 MimeBody *This = impl_from_IMimeBody(iface);
1319 HRESULT hr;
1320 header_t *header;
1322 TRACE("(%p)->(%s, %p, %p)\n", iface, debugstr_a(pszName), pcParams, pprgParam);
1324 *pprgParam = NULL;
1325 *pcParams = 0;
1327 hr = find_prop(This, pszName, &header);
1328 if(hr != S_OK) return hr;
1330 *pcParams = list_count(&header->params);
1331 if(*pcParams)
1333 IMimeAllocator *alloc;
1334 param_t *param;
1335 MIMEPARAMINFO *info;
1337 MimeOleGetAllocator(&alloc);
1339 *pprgParam = info = IMimeAllocator_Alloc(alloc, *pcParams * sizeof(**pprgParam));
1340 LIST_FOR_EACH_ENTRY(param, &header->params, param_t, entry)
1342 int len;
1344 len = strlen(param->name) + 1;
1345 info->pszName = IMimeAllocator_Alloc(alloc, len);
1346 memcpy(info->pszName, param->name, len);
1347 len = strlen(param->value) + 1;
1348 info->pszData = IMimeAllocator_Alloc(alloc, len);
1349 memcpy(info->pszData, param->value, len);
1350 info++;
1352 IMimeAllocator_Release(alloc);
1354 return S_OK;
1357 static HRESULT WINAPI MimeBody_IsContentType(
1358 IMimeBody* iface,
1359 LPCSTR pszPriType,
1360 LPCSTR pszSubType)
1362 MimeBody *This = impl_from_IMimeBody(iface);
1364 TRACE("(%p)->(%s, %s)\n", This, debugstr_a(pszPriType), debugstr_a(pszSubType));
1365 if(pszPriType)
1367 const char *pri = This->content_pri_type;
1368 if(!pri) pri = "text";
1369 if(lstrcmpiA(pri, pszPriType)) return S_FALSE;
1372 if(pszSubType)
1374 const char *sub = This->content_sub_type;
1375 if(!sub) sub = "plain";
1376 if(lstrcmpiA(sub, pszSubType)) return S_FALSE;
1379 return S_OK;
1382 static HRESULT WINAPI MimeBody_BindToObject(
1383 IMimeBody* iface,
1384 REFIID riid,
1385 void** ppvObject)
1387 MimeBody *This = impl_from_IMimeBody(iface);
1388 FIXME("(%p)->(%s, %p) stub\n", This, debugstr_guid(riid), ppvObject);
1389 return E_NOTIMPL;
1392 static HRESULT WINAPI MimeBody_Clone(
1393 IMimeBody* iface,
1394 IMimePropertySet** ppPropertySet)
1396 MimeBody *This = impl_from_IMimeBody(iface);
1397 FIXME("(%p)->(%p) stub\n", This, ppPropertySet);
1398 return E_NOTIMPL;
1401 static HRESULT WINAPI MimeBody_SetOption(
1402 IMimeBody* iface,
1403 const TYPEDID oid,
1404 LPCPROPVARIANT pValue)
1406 MimeBody *This = impl_from_IMimeBody(iface);
1407 HRESULT hr = E_NOTIMPL;
1408 TRACE("(%p)->(%08x, %p)\n", This, oid, pValue);
1410 if(pValue->vt != TYPEDID_TYPE(oid))
1412 WARN("Called with vartype %04x and oid %08x\n", pValue->vt, oid);
1413 return E_INVALIDARG;
1416 switch(oid)
1418 case OID_SECURITY_HWND_OWNER:
1419 FIXME("OID_SECURITY_HWND_OWNER (value %08x): ignoring\n", pValue->ulVal);
1420 hr = S_OK;
1421 break;
1422 case OID_TRANSMIT_BODY_ENCODING:
1423 FIXME("OID_TRANSMIT_BODY_ENCODING (value %08x): ignoring\n", pValue->ulVal);
1424 hr = S_OK;
1425 break;
1426 default:
1427 FIXME("Unhandled oid %08x\n", oid);
1430 return hr;
1433 static HRESULT WINAPI MimeBody_GetOption(
1434 IMimeBody* iface,
1435 const TYPEDID oid,
1436 LPPROPVARIANT pValue)
1438 MimeBody *This = impl_from_IMimeBody(iface);
1439 FIXME("(%p)->(%08x, %p): stub\n", This, oid, pValue);
1440 return E_NOTIMPL;
1443 static HRESULT WINAPI MimeBody_EnumProps(
1444 IMimeBody* iface,
1445 DWORD dwFlags,
1446 IMimeEnumProperties** ppEnum)
1448 MimeBody *This = impl_from_IMimeBody(iface);
1449 FIXME("(%p)->(0x%x, %p) stub\n", This, dwFlags, ppEnum);
1450 return E_NOTIMPL;
1453 static HRESULT WINAPI MimeBody_IsType(
1454 IMimeBody* iface,
1455 IMSGBODYTYPE bodytype)
1457 MimeBody *This = impl_from_IMimeBody(iface);
1459 TRACE("(%p)->(%d)\n", This, bodytype);
1460 switch(bodytype)
1462 case IBT_EMPTY:
1463 return This->data ? S_FALSE : S_OK;
1464 default:
1465 FIXME("Unimplemented bodytype %d - returning S_OK\n", bodytype);
1467 return S_OK;
1470 static HRESULT WINAPI MimeBody_SetDisplayName(
1471 IMimeBody* iface,
1472 LPCSTR pszDisplay)
1474 MimeBody *This = impl_from_IMimeBody(iface);
1475 FIXME("(%p)->(%s) stub\n", This, debugstr_a(pszDisplay));
1476 return E_NOTIMPL;
1479 static HRESULT WINAPI MimeBody_GetDisplayName(
1480 IMimeBody* iface,
1481 LPSTR* ppszDisplay)
1483 MimeBody *This = impl_from_IMimeBody(iface);
1484 FIXME("(%p)->(%p) stub\n", This, ppszDisplay);
1485 return E_NOTIMPL;
1488 static HRESULT WINAPI MimeBody_GetOffsets(
1489 IMimeBody* iface,
1490 LPBODYOFFSETS pOffsets)
1492 MimeBody *This = impl_from_IMimeBody(iface);
1493 TRACE("(%p)->(%p)\n", This, pOffsets);
1495 *pOffsets = This->body_offsets;
1497 if(This->body_offsets.cbBodyEnd == 0) return MIME_E_NO_DATA;
1498 return S_OK;
1501 static HRESULT WINAPI MimeBody_GetCurrentEncoding(
1502 IMimeBody* iface,
1503 ENCODINGTYPE* pietEncoding)
1505 MimeBody *This = impl_from_IMimeBody(iface);
1507 TRACE("(%p)->(%p)\n", This, pietEncoding);
1509 *pietEncoding = This->encoding;
1510 return S_OK;
1513 static HRESULT WINAPI MimeBody_SetCurrentEncoding(
1514 IMimeBody* iface,
1515 ENCODINGTYPE ietEncoding)
1517 MimeBody *This = impl_from_IMimeBody(iface);
1519 TRACE("(%p)->(%d)\n", This, ietEncoding);
1521 This->encoding = ietEncoding;
1522 return S_OK;
1525 static HRESULT WINAPI MimeBody_GetEstimatedSize(
1526 IMimeBody* iface,
1527 ENCODINGTYPE ietEncoding,
1528 ULONG* pcbSize)
1530 MimeBody *This = impl_from_IMimeBody(iface);
1531 FIXME("(%p)->(%d, %p) stub\n", This, ietEncoding, pcbSize);
1532 return E_NOTIMPL;
1535 static HRESULT WINAPI MimeBody_GetDataHere(
1536 IMimeBody* iface,
1537 ENCODINGTYPE ietEncoding,
1538 IStream* pStream)
1540 MimeBody *This = impl_from_IMimeBody(iface);
1541 FIXME("(%p)->(%d, %p) stub\n", This, ietEncoding, pStream);
1542 return E_NOTIMPL;
1545 static const signed char base64_decode_table[] =
1547 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x00 */
1548 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x10 */
1549 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, /* 0x20 */
1550 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, /* 0x30 */
1551 -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, /* 0x40 */
1552 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, /* 0x50 */
1553 -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, /* 0x60 */
1554 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1 /* 0x70 */
1557 static HRESULT decode_base64(IStream *input, IStream **ret_stream)
1559 const unsigned char *ptr, *end;
1560 unsigned char buf[1024];
1561 LARGE_INTEGER pos;
1562 unsigned char *ret;
1563 unsigned char in[4];
1564 IStream *output;
1565 DWORD size;
1566 int n = 0;
1567 HRESULT hres;
1569 pos.QuadPart = 0;
1570 hres = IStream_Seek(input, pos, STREAM_SEEK_SET, NULL);
1571 if(FAILED(hres))
1572 return hres;
1574 hres = CreateStreamOnHGlobal(NULL, TRUE, &output);
1575 if(FAILED(hres))
1576 return hres;
1578 while(1) {
1579 hres = IStream_Read(input, buf, sizeof(buf), &size);
1580 if(FAILED(hres) || !size)
1581 break;
1583 ptr = ret = buf;
1584 end = buf + size;
1586 while(1) {
1587 /* skip invalid chars */
1588 while(ptr < end && (*ptr >= ARRAY_SIZE(base64_decode_table)
1589 || base64_decode_table[*ptr] == -1))
1590 ptr++;
1591 if(ptr == end)
1592 break;
1594 in[n++] = base64_decode_table[*ptr++];
1595 switch(n) {
1596 case 2:
1597 *ret++ = in[0] << 2 | in[1] >> 4;
1598 continue;
1599 case 3:
1600 *ret++ = in[1] << 4 | in[2] >> 2;
1601 continue;
1602 case 4:
1603 *ret++ = ((in[2] << 6) & 0xc0) | in[3];
1604 n = 0;
1608 if(ret > buf) {
1609 hres = IStream_Write(output, buf, ret - buf, NULL);
1610 if(FAILED(hres))
1611 break;
1615 if(SUCCEEDED(hres))
1616 hres = IStream_Seek(output, pos, STREAM_SEEK_SET, NULL);
1617 if(FAILED(hres)) {
1618 IStream_Release(output);
1619 return hres;
1622 *ret_stream = output;
1623 return S_OK;
1626 static int hex_digit(char c)
1628 if('0' <= c && c <= '9')
1629 return c - '0';
1630 if('A' <= c && c <= 'F')
1631 return c - 'A' + 10;
1632 if('a' <= c && c <= 'f')
1633 return c - 'a' + 10;
1634 return -1;
1637 static HRESULT decode_qp(IStream *input, IStream **ret_stream)
1639 const unsigned char *ptr, *end;
1640 unsigned char *ret, prev = 0;
1641 unsigned char buf[1024];
1642 LARGE_INTEGER pos;
1643 IStream *output;
1644 DWORD size;
1645 int n = -1;
1646 HRESULT hres;
1648 pos.QuadPart = 0;
1649 hres = IStream_Seek(input, pos, STREAM_SEEK_SET, NULL);
1650 if(FAILED(hres))
1651 return hres;
1653 hres = CreateStreamOnHGlobal(NULL, TRUE, &output);
1654 if(FAILED(hres))
1655 return hres;
1657 while(1) {
1658 hres = IStream_Read(input, buf, sizeof(buf), &size);
1659 if(FAILED(hres) || !size)
1660 break;
1662 ptr = ret = buf;
1663 end = buf + size;
1665 while(ptr < end) {
1666 unsigned char byte = *ptr++;
1668 switch(n) {
1669 case -1:
1670 if(byte == '=')
1671 n = 0;
1672 else
1673 *ret++ = byte;
1674 continue;
1675 case 0:
1676 prev = byte;
1677 n = 1;
1678 continue;
1679 case 1:
1680 if(prev != '\r' || byte != '\n') {
1681 int h1 = hex_digit(prev), h2 = hex_digit(byte);
1682 if(h1 != -1 && h2 != -1)
1683 *ret++ = (h1 << 4) | h2;
1684 else
1685 *ret++ = '=';
1687 n = -1;
1688 continue;
1692 if(ret > buf) {
1693 hres = IStream_Write(output, buf, ret - buf, NULL);
1694 if(FAILED(hres))
1695 break;
1699 if(SUCCEEDED(hres))
1700 hres = IStream_Seek(output, pos, STREAM_SEEK_SET, NULL);
1701 if(FAILED(hres)) {
1702 IStream_Release(output);
1703 return hres;
1706 *ret_stream = output;
1707 return S_OK;
1710 static HRESULT WINAPI MimeBody_GetData(
1711 IMimeBody* iface,
1712 ENCODINGTYPE ietEncoding,
1713 IStream** ppStream)
1715 MimeBody *This = impl_from_IMimeBody(iface);
1716 ULARGE_INTEGER start, size;
1717 HRESULT hres;
1719 TRACE("(%p)->(%d %p)\n", This, ietEncoding, ppStream);
1721 if(This->encoding != ietEncoding) {
1722 switch(This->encoding) {
1723 case IET_BASE64:
1724 hres = decode_base64(This->data, ppStream);
1725 break;
1726 case IET_QP:
1727 hres = decode_qp(This->data, ppStream);
1728 break;
1729 default:
1730 FIXME("Decoding %d is not supported.\n", This->encoding);
1731 hres = S_FALSE;
1733 if(ietEncoding != IET_BINARY)
1734 FIXME("Encoding %d is not supported.\n", ietEncoding);
1735 if(hres != S_FALSE)
1736 return hres;
1739 start.QuadPart = 0;
1740 hres = get_stream_size(This->data, &size);
1741 if(SUCCEEDED(hres))
1742 hres = create_sub_stream(This->data, start, size, ppStream);
1743 return hres;
1746 static HRESULT WINAPI MimeBody_SetData(
1747 IMimeBody* iface,
1748 ENCODINGTYPE ietEncoding,
1749 LPCSTR pszPriType,
1750 LPCSTR pszSubType,
1751 REFIID riid,
1752 LPVOID pvObject)
1754 MimeBody *This = impl_from_IMimeBody(iface);
1755 TRACE("(%p)->(%d, %s, %s, %s %p)\n", This, ietEncoding, debugstr_a(pszPriType), debugstr_a(pszSubType),
1756 debugstr_guid(riid), pvObject);
1758 if(IsEqualIID(riid, &IID_IStream))
1759 IStream_AddRef((IStream *)pvObject);
1760 else
1762 FIXME("Unhandled object type %s\n", debugstr_guid(riid));
1763 return E_INVALIDARG;
1766 if(This->data)
1767 release_data(&This->data_iid, This->data);
1769 This->data_iid = *riid;
1770 This->data = pvObject;
1772 IMimeBody_SetCurrentEncoding(iface, ietEncoding);
1774 /* FIXME: Update the content type.
1775 If pszPriType == NULL use 'application'
1776 If pszSubType == NULL use 'octet-stream' */
1778 return S_OK;
1781 static HRESULT WINAPI MimeBody_EmptyData(
1782 IMimeBody* iface)
1784 MimeBody *This = impl_from_IMimeBody(iface);
1785 FIXME("(%p)->() stub\n", This);
1786 return E_NOTIMPL;
1789 static HRESULT WINAPI MimeBody_CopyTo(
1790 IMimeBody* iface,
1791 IMimeBody* pBody)
1793 MimeBody *This = impl_from_IMimeBody(iface);
1794 FIXME("(%p)->(%p) stub\n", This, pBody);
1795 return E_NOTIMPL;
1798 static HRESULT WINAPI MimeBody_GetTransmitInfo(
1799 IMimeBody* iface,
1800 LPTRANSMITINFO pTransmitInfo)
1802 MimeBody *This = impl_from_IMimeBody(iface);
1803 FIXME("(%p)->(%p) stub\n", This, pTransmitInfo);
1804 return E_NOTIMPL;
1807 static HRESULT WINAPI MimeBody_SaveToFile(
1808 IMimeBody* iface,
1809 ENCODINGTYPE ietEncoding,
1810 LPCSTR pszFilePath)
1812 MimeBody *This = impl_from_IMimeBody(iface);
1813 FIXME("(%p)->(%d, %s) stub\n", This, ietEncoding, debugstr_a(pszFilePath));
1814 return E_NOTIMPL;
1817 static HRESULT WINAPI MimeBody_GetHandle(
1818 IMimeBody* iface,
1819 LPHBODY phBody)
1821 MimeBody *This = impl_from_IMimeBody(iface);
1822 TRACE("(%p)->(%p)\n", iface, phBody);
1824 if(!phBody)
1825 return E_INVALIDARG;
1827 *phBody = This->handle;
1828 return This->handle ? S_OK : MIME_E_NO_DATA;
1831 static IMimeBodyVtbl body_vtbl =
1833 MimeBody_QueryInterface,
1834 MimeBody_AddRef,
1835 MimeBody_Release,
1836 MimeBody_GetClassID,
1837 MimeBody_IsDirty,
1838 MimeBody_Load,
1839 MimeBody_Save,
1840 MimeBody_GetSizeMax,
1841 MimeBody_InitNew,
1842 MimeBody_GetPropInfo,
1843 MimeBody_SetPropInfo,
1844 MimeBody_GetProp,
1845 MimeBody_SetProp,
1846 MimeBody_AppendProp,
1847 MimeBody_DeleteProp,
1848 MimeBody_CopyProps,
1849 MimeBody_MoveProps,
1850 MimeBody_DeleteExcept,
1851 MimeBody_QueryProp,
1852 MimeBody_GetCharset,
1853 MimeBody_SetCharset,
1854 MimeBody_GetParameters,
1855 MimeBody_IsContentType,
1856 MimeBody_BindToObject,
1857 MimeBody_Clone,
1858 MimeBody_SetOption,
1859 MimeBody_GetOption,
1860 MimeBody_EnumProps,
1861 MimeBody_IsType,
1862 MimeBody_SetDisplayName,
1863 MimeBody_GetDisplayName,
1864 MimeBody_GetOffsets,
1865 MimeBody_GetCurrentEncoding,
1866 MimeBody_SetCurrentEncoding,
1867 MimeBody_GetEstimatedSize,
1868 MimeBody_GetDataHere,
1869 MimeBody_GetData,
1870 MimeBody_SetData,
1871 MimeBody_EmptyData,
1872 MimeBody_CopyTo,
1873 MimeBody_GetTransmitInfo,
1874 MimeBody_SaveToFile,
1875 MimeBody_GetHandle
1878 static HRESULT MimeBody_set_offsets(MimeBody *body, const BODYOFFSETS *offsets)
1880 TRACE("setting offsets to %d, %d, %d, %d\n", offsets->cbBoundaryStart,
1881 offsets->cbHeaderStart, offsets->cbBodyStart, offsets->cbBodyEnd);
1883 body->body_offsets = *offsets;
1884 return S_OK;
1887 #define FIRST_CUSTOM_PROP_ID 0x100
1889 static MimeBody *mimebody_create(void)
1891 MimeBody *This;
1892 BODYOFFSETS body_offsets;
1894 This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
1895 if (!This)
1896 return NULL;
1898 This->IMimeBody_iface.lpVtbl = &body_vtbl;
1899 This->ref = 1;
1900 This->handle = NULL;
1901 list_init(&This->headers);
1902 list_init(&This->new_props);
1903 This->next_prop_id = FIRST_CUSTOM_PROP_ID;
1904 This->content_pri_type = NULL;
1905 This->content_sub_type = NULL;
1906 This->encoding = IET_7BIT;
1907 This->data = NULL;
1908 This->data_iid = IID_NULL;
1910 body_offsets.cbBoundaryStart = body_offsets.cbHeaderStart = 0;
1911 body_offsets.cbBodyStart = body_offsets.cbBodyEnd = 0;
1912 MimeBody_set_offsets(This, &body_offsets);
1914 return This;
1917 HRESULT MimeBody_create(IUnknown *outer, void **ppv)
1919 MimeBody *mb;
1921 if(outer)
1922 return CLASS_E_NOAGGREGATION;
1924 if ((mb = mimebody_create()))
1926 *ppv = &mb->IMimeBody_iface;
1927 return S_OK;
1929 else
1931 *ppv = NULL;
1932 return E_OUTOFMEMORY;
1936 typedef struct body_t
1938 struct list entry;
1939 DWORD index;
1940 MimeBody *mime_body;
1942 struct body_t *parent;
1943 struct list children;
1944 } body_t;
1946 typedef struct MimeMessage
1948 IMimeMessage IMimeMessage_iface;
1949 LONG ref;
1950 IStream *stream;
1952 struct list body_tree;
1953 DWORD next_index;
1954 } MimeMessage;
1956 static inline MimeMessage *impl_from_IMimeMessage(IMimeMessage *iface)
1958 return CONTAINING_RECORD(iface, MimeMessage, IMimeMessage_iface);
1961 static HRESULT WINAPI MimeMessage_QueryInterface(IMimeMessage *iface, REFIID riid, void **ppv)
1963 TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppv);
1965 if (IsEqualIID(riid, &IID_IUnknown) ||
1966 IsEqualIID(riid, &IID_IPersist) ||
1967 IsEqualIID(riid, &IID_IPersistStreamInit) ||
1968 IsEqualIID(riid, &IID_IMimeMessageTree) ||
1969 IsEqualIID(riid, &IID_IMimeMessage))
1971 *ppv = iface;
1972 IMimeMessage_AddRef(iface);
1973 return S_OK;
1976 FIXME("no interface for %s\n", debugstr_guid(riid));
1977 *ppv = NULL;
1978 return E_NOINTERFACE;
1981 static ULONG WINAPI MimeMessage_AddRef(IMimeMessage *iface)
1983 MimeMessage *This = impl_from_IMimeMessage(iface);
1984 ULONG ref = InterlockedIncrement(&This->ref);
1986 TRACE("(%p) ref=%d\n", This, ref);
1988 return ref;
1991 static void empty_body_list(struct list *list)
1993 body_t *body, *cursor2;
1994 LIST_FOR_EACH_ENTRY_SAFE(body, cursor2, list, body_t, entry)
1996 empty_body_list(&body->children);
1997 list_remove(&body->entry);
1998 IMimeBody_Release(&body->mime_body->IMimeBody_iface);
1999 HeapFree(GetProcessHeap(), 0, body);
2003 static ULONG WINAPI MimeMessage_Release(IMimeMessage *iface)
2005 MimeMessage *This = impl_from_IMimeMessage(iface);
2006 ULONG ref = InterlockedDecrement(&This->ref);
2008 TRACE("(%p) ref=%d\n", This, ref);
2010 if (!ref)
2012 empty_body_list(&This->body_tree);
2014 if(This->stream) IStream_Release(This->stream);
2015 HeapFree(GetProcessHeap(), 0, This);
2018 return ref;
2021 /*** IPersist methods ***/
2022 static HRESULT WINAPI MimeMessage_GetClassID(
2023 IMimeMessage *iface,
2024 CLSID *pClassID)
2026 FIXME("(%p)->(%p)\n", iface, pClassID);
2027 return E_NOTIMPL;
2030 /*** IPersistStreamInit methods ***/
2031 static HRESULT WINAPI MimeMessage_IsDirty(
2032 IMimeMessage *iface)
2034 FIXME("(%p)->()\n", iface);
2035 return E_NOTIMPL;
2038 static body_t *new_body_entry(MimeBody *mime_body, DWORD index, body_t *parent)
2040 body_t *body = HeapAlloc(GetProcessHeap(), 0, sizeof(*body));
2041 if(body)
2043 body->mime_body = mime_body;
2044 body->index = index;
2045 list_init(&body->children);
2046 body->parent = parent;
2048 mime_body->handle = UlongToHandle(body->index);
2050 return body;
2053 typedef struct
2055 struct list entry;
2056 BODYOFFSETS offsets;
2057 } offset_entry_t;
2059 static HRESULT create_body_offset_list(IStream *stm, const char *boundary, struct list *body_offsets)
2061 HRESULT hr;
2062 DWORD read, boundary_start;
2063 int boundary_len = strlen(boundary);
2064 char *buf, *ptr, *overlap;
2065 DWORD start = 0, overlap_no;
2066 offset_entry_t *cur_body = NULL;
2067 BOOL is_first_line = TRUE;
2068 ULARGE_INTEGER cur;
2069 LARGE_INTEGER zero;
2071 list_init(body_offsets);
2073 overlap_no = boundary_len + 5;
2075 overlap = buf = HeapAlloc(GetProcessHeap(), 0, overlap_no + PARSER_BUF_SIZE + 1);
2077 zero.QuadPart = 0;
2078 hr = IStream_Seek(stm, zero, STREAM_SEEK_CUR, &cur);
2079 start = cur.u.LowPart;
2081 do {
2082 hr = IStream_Read(stm, overlap, PARSER_BUF_SIZE, &read);
2083 if(FAILED(hr)) goto end;
2084 if(read == 0) break;
2085 overlap[read] = '\0';
2087 ptr = buf;
2088 while(1) {
2089 if(is_first_line) {
2090 is_first_line = FALSE;
2091 }else {
2092 ptr = strstr(ptr, "\r\n");
2093 if(!ptr)
2094 break;
2095 ptr += 2;
2098 boundary_start = start + ptr - buf;
2100 if(*ptr == '-' && *(ptr + 1) == '-' && !memcmp(ptr + 2, boundary, boundary_len)) {
2101 ptr += boundary_len + 2;
2103 if(*ptr == '\r' && *(ptr + 1) == '\n')
2105 ptr += 2;
2106 if(cur_body)
2108 cur_body->offsets.cbBodyEnd = boundary_start - 2;
2109 list_add_tail(body_offsets, &cur_body->entry);
2111 cur_body = HeapAlloc(GetProcessHeap(), 0, sizeof(*cur_body));
2112 cur_body->offsets.cbBoundaryStart = boundary_start;
2113 cur_body->offsets.cbHeaderStart = start + ptr - buf;
2115 else if(*ptr == '-' && *(ptr + 1) == '-')
2117 if(cur_body)
2119 cur_body->offsets.cbBodyEnd = boundary_start - 2;
2120 list_add_tail(body_offsets, &cur_body->entry);
2121 goto end;
2127 if(overlap == buf) /* 1st iteration */
2129 memmove(buf, buf + PARSER_BUF_SIZE - overlap_no, overlap_no);
2130 overlap = buf + overlap_no;
2131 start += read - overlap_no;
2133 else
2135 memmove(buf, buf + PARSER_BUF_SIZE, overlap_no);
2136 start += read;
2138 } while(1);
2140 end:
2141 HeapFree(GetProcessHeap(), 0, buf);
2142 return hr;
2145 static body_t *create_sub_body(MimeMessage *msg, IStream *pStm, BODYOFFSETS *offset, body_t *parent)
2147 ULARGE_INTEGER start, length;
2148 MimeBody *mime_body;
2149 HRESULT hr;
2150 body_t *body;
2151 LARGE_INTEGER pos;
2153 pos.QuadPart = offset->cbHeaderStart;
2154 IStream_Seek(pStm, pos, STREAM_SEEK_SET, NULL);
2156 mime_body = mimebody_create();
2157 IMimeBody_Load(&mime_body->IMimeBody_iface, pStm);
2159 pos.QuadPart = 0;
2160 hr = IStream_Seek(pStm, pos, STREAM_SEEK_CUR, &start);
2161 offset->cbBodyStart = start.QuadPart;
2162 if (parent) MimeBody_set_offsets(mime_body, offset);
2164 length.QuadPart = offset->cbBodyEnd - offset->cbBodyStart;
2165 create_sub_stream(pStm, start, length, (IStream**)&mime_body->data);
2166 mime_body->data_iid = IID_IStream;
2168 body = new_body_entry(mime_body, msg->next_index++, parent);
2170 if(IMimeBody_IsContentType(&mime_body->IMimeBody_iface, "multipart", NULL) == S_OK)
2172 MIMEPARAMINFO *param_info;
2173 ULONG count, i;
2174 IMimeAllocator *alloc;
2176 hr = IMimeBody_GetParameters(&mime_body->IMimeBody_iface, "Content-Type", &count,
2177 &param_info);
2178 if(hr != S_OK || count == 0) return body;
2180 MimeOleGetAllocator(&alloc);
2182 for(i = 0; i < count; i++)
2184 if(!lstrcmpiA(param_info[i].pszName, "boundary"))
2186 struct list offset_list;
2187 offset_entry_t *cur, *cursor2;
2188 hr = create_body_offset_list(pStm, param_info[i].pszData, &offset_list);
2189 LIST_FOR_EACH_ENTRY_SAFE(cur, cursor2, &offset_list, offset_entry_t, entry)
2191 body_t *sub_body;
2193 sub_body = create_sub_body(msg, pStm, &cur->offsets, body);
2194 list_add_tail(&body->children, &sub_body->entry);
2195 list_remove(&cur->entry);
2196 HeapFree(GetProcessHeap(), 0, cur);
2198 break;
2201 IMimeAllocator_FreeParamInfoArray(alloc, count, param_info, TRUE);
2202 IMimeAllocator_Release(alloc);
2204 return body;
2207 static HRESULT WINAPI MimeMessage_Load(IMimeMessage *iface, IStream *pStm)
2209 MimeMessage *This = impl_from_IMimeMessage(iface);
2210 body_t *root_body;
2211 BODYOFFSETS offsets;
2212 ULARGE_INTEGER cur;
2213 LARGE_INTEGER zero;
2215 TRACE("(%p)->(%p)\n", iface, pStm);
2217 if(This->stream)
2219 FIXME("already loaded a message\n");
2220 return E_FAIL;
2223 empty_body_list(&This->body_tree);
2225 IStream_AddRef(pStm);
2226 This->stream = pStm;
2227 offsets.cbBoundaryStart = offsets.cbHeaderStart = 0;
2228 offsets.cbBodyStart = offsets.cbBodyEnd = 0;
2230 root_body = create_sub_body(This, pStm, &offsets, NULL);
2232 zero.QuadPart = 0;
2233 IStream_Seek(pStm, zero, STREAM_SEEK_END, &cur);
2234 offsets.cbBodyEnd = cur.u.LowPart;
2235 MimeBody_set_offsets(root_body->mime_body, &offsets);
2237 list_add_head(&This->body_tree, &root_body->entry);
2239 return S_OK;
2242 static HRESULT WINAPI MimeMessage_Save(IMimeMessage *iface, IStream *pStm, BOOL fClearDirty)
2244 FIXME("(%p)->(%p, %s)\n", iface, pStm, fClearDirty ? "TRUE" : "FALSE");
2245 return E_NOTIMPL;
2248 static HRESULT WINAPI MimeMessage_GetSizeMax(
2249 IMimeMessage *iface,
2250 ULARGE_INTEGER *pcbSize)
2252 FIXME("(%p)->(%p)\n", iface, pcbSize);
2253 return E_NOTIMPL;
2256 static HRESULT WINAPI MimeMessage_InitNew(
2257 IMimeMessage *iface)
2259 FIXME("(%p)->()\n", iface);
2260 return E_NOTIMPL;
2263 /*** IMimeMessageTree methods ***/
2264 static HRESULT WINAPI MimeMessage_GetMessageSource(IMimeMessage *iface, IStream **ppStream,
2265 DWORD dwFlags)
2267 MimeMessage *This = impl_from_IMimeMessage(iface);
2269 FIXME("(%p)->(%p, 0x%x)\n", iface, ppStream, dwFlags);
2271 IStream_AddRef(This->stream);
2272 *ppStream = This->stream;
2273 return S_OK;
2276 static HRESULT WINAPI MimeMessage_GetMessageSize(
2277 IMimeMessage *iface,
2278 ULONG *pcbSize,
2279 DWORD dwFlags)
2281 FIXME("(%p)->(%p, 0x%x)\n", iface, pcbSize, dwFlags);
2282 return E_NOTIMPL;
2285 static HRESULT WINAPI MimeMessage_LoadOffsetTable(
2286 IMimeMessage *iface,
2287 IStream *pStream)
2289 FIXME("(%p)->(%p)\n", iface, pStream);
2290 return E_NOTIMPL;
2293 static HRESULT WINAPI MimeMessage_SaveOffsetTable(
2294 IMimeMessage *iface,
2295 IStream *pStream,
2296 DWORD dwFlags)
2298 FIXME("(%p)->(%p, 0x%x)\n", iface, pStream, dwFlags);
2299 return E_NOTIMPL;
2303 static HRESULT WINAPI MimeMessage_GetFlags(
2304 IMimeMessage *iface,
2305 DWORD *pdwFlags)
2307 FIXME("(%p)->(%p)\n", iface, pdwFlags);
2308 return E_NOTIMPL;
2311 static HRESULT WINAPI MimeMessage_Commit(
2312 IMimeMessage *iface,
2313 DWORD dwFlags)
2315 FIXME("(%p)->(0x%x)\n", iface, dwFlags);
2316 return S_OK;
2320 static HRESULT WINAPI MimeMessage_HandsOffStorage(
2321 IMimeMessage *iface)
2323 FIXME("(%p)->()\n", iface);
2324 return E_NOTIMPL;
2327 static HRESULT find_body(struct list *list, HBODY hbody, body_t **body)
2329 body_t *cur;
2330 HRESULT hr;
2332 if(hbody == HBODY_ROOT)
2334 *body = LIST_ENTRY(list_head(list), body_t, entry);
2335 return S_OK;
2338 LIST_FOR_EACH_ENTRY(cur, list, body_t, entry)
2340 if(cur->index == HandleToUlong(hbody))
2342 *body = cur;
2343 return S_OK;
2345 hr = find_body(&cur->children, hbody, body);
2346 if(hr == S_OK) return S_OK;
2348 return S_FALSE;
2351 static HRESULT WINAPI MimeMessage_BindToObject(IMimeMessage *iface, const HBODY hBody, REFIID riid,
2352 void **ppvObject)
2354 MimeMessage *This = impl_from_IMimeMessage(iface);
2355 HRESULT hr;
2356 body_t *body;
2358 TRACE("(%p)->(%p, %s, %p)\n", iface, hBody, debugstr_guid(riid), ppvObject);
2360 hr = find_body(&This->body_tree, hBody, &body);
2362 if(hr != S_OK) return hr;
2364 if(IsEqualIID(riid, &IID_IMimeBody))
2366 IMimeBody_AddRef(&body->mime_body->IMimeBody_iface);
2367 *ppvObject = &body->mime_body->IMimeBody_iface;
2368 return S_OK;
2371 return E_NOINTERFACE;
2374 static HRESULT WINAPI MimeMessage_SaveBody(
2375 IMimeMessage *iface,
2376 HBODY hBody,
2377 DWORD dwFlags,
2378 IStream *pStream)
2380 FIXME("(%p)->(%p, 0x%x, %p)\n", iface, hBody, dwFlags, pStream);
2381 return E_NOTIMPL;
2384 static HRESULT get_body(MimeMessage *msg, BODYLOCATION location, HBODY pivot, body_t **out)
2386 body_t *root = LIST_ENTRY(list_head(&msg->body_tree), body_t, entry);
2387 body_t *body;
2388 HRESULT hr;
2389 struct list *list;
2391 if(location == IBL_ROOT)
2393 *out = root;
2394 return S_OK;
2397 hr = find_body(&msg->body_tree, pivot, &body);
2399 if(hr == S_OK)
2401 switch(location)
2403 case IBL_PARENT:
2404 if(body->parent)
2405 *out = body->parent;
2406 else
2407 hr = MIME_E_NOT_FOUND;
2408 break;
2410 case IBL_FIRST:
2411 list = list_head(&body->children);
2412 if(list)
2413 *out = LIST_ENTRY(list, body_t, entry);
2414 else
2415 hr = MIME_E_NOT_FOUND;
2416 break;
2418 case IBL_LAST:
2419 list = list_tail(&body->children);
2420 if(list)
2421 *out = LIST_ENTRY(list, body_t, entry);
2422 else
2423 hr = MIME_E_NOT_FOUND;
2424 break;
2426 case IBL_NEXT:
2427 list = list_next(&body->parent->children, &body->entry);
2428 if(list)
2429 *out = LIST_ENTRY(list, body_t, entry);
2430 else
2431 hr = MIME_E_NOT_FOUND;
2432 break;
2434 case IBL_PREVIOUS:
2435 list = list_prev(&body->parent->children, &body->entry);
2436 if(list)
2437 *out = LIST_ENTRY(list, body_t, entry);
2438 else
2439 hr = MIME_E_NOT_FOUND;
2440 break;
2442 default:
2443 hr = E_FAIL;
2444 break;
2448 return hr;
2452 static HRESULT WINAPI MimeMessage_InsertBody(
2453 IMimeMessage *iface,
2454 BODYLOCATION location,
2455 HBODY hPivot,
2456 LPHBODY phBody)
2458 FIXME("(%p)->(%d, %p, %p)\n", iface, location, hPivot, phBody);
2459 return E_NOTIMPL;
2462 static HRESULT WINAPI MimeMessage_GetBody(IMimeMessage *iface, BODYLOCATION location, HBODY hPivot,
2463 HBODY *phBody)
2465 MimeMessage *This = impl_from_IMimeMessage(iface);
2466 body_t *body;
2467 HRESULT hr;
2469 TRACE("(%p)->(%d, %p, %p)\n", iface, location, hPivot, phBody);
2471 if(!phBody)
2472 return E_INVALIDARG;
2474 *phBody = NULL;
2476 hr = get_body(This, location, hPivot, &body);
2478 if(hr == S_OK) *phBody = UlongToHandle(body->index);
2480 return hr;
2483 static HRESULT WINAPI MimeMessage_DeleteBody(
2484 IMimeMessage *iface,
2485 HBODY hBody,
2486 DWORD dwFlags)
2488 FIXME("(%p)->(%p, %08x)\n", iface, hBody, dwFlags);
2489 return E_NOTIMPL;
2492 static HRESULT WINAPI MimeMessage_MoveBody(
2493 IMimeMessage *iface,
2494 HBODY hBody,
2495 BODYLOCATION location)
2497 FIXME("(%p)->(%d)\n", iface, location);
2498 return E_NOTIMPL;
2501 static void count_children(body_t *body, boolean recurse, ULONG *count)
2503 body_t *child;
2505 LIST_FOR_EACH_ENTRY(child, &body->children, body_t, entry)
2507 (*count)++;
2508 if(recurse) count_children(child, recurse, count);
2512 static HRESULT WINAPI MimeMessage_CountBodies(IMimeMessage *iface, HBODY hParent, boolean fRecurse,
2513 ULONG *pcBodies)
2515 HRESULT hr;
2516 MimeMessage *This = impl_from_IMimeMessage(iface);
2517 body_t *body;
2519 TRACE("(%p)->(%p, %s, %p)\n", iface, hParent, fRecurse ? "TRUE" : "FALSE", pcBodies);
2521 hr = find_body(&This->body_tree, hParent, &body);
2522 if(hr != S_OK) return hr;
2524 *pcBodies = 1;
2525 count_children(body, fRecurse, pcBodies);
2527 return S_OK;
2530 static HRESULT find_next(MimeMessage *This, body_t *body, FINDBODY *find, HBODY *out)
2532 struct list *ptr;
2533 HBODY next;
2535 for (;;)
2537 if (!body) ptr = list_head( &This->body_tree );
2538 else
2540 ptr = list_head( &body->children );
2541 while (!ptr)
2543 if (!body->parent) return MIME_E_NOT_FOUND;
2544 if (!(ptr = list_next( &body->parent->children, &body->entry ))) body = body->parent;
2548 body = LIST_ENTRY( ptr, body_t, entry );
2549 next = UlongToHandle( body->index );
2550 find->dwReserved = body->index;
2551 if (IMimeBody_IsContentType(&body->mime_body->IMimeBody_iface, find->pszPriType,
2552 find->pszSubType) == S_OK)
2554 *out = next;
2555 return S_OK;
2558 return MIME_E_NOT_FOUND;
2561 static HRESULT WINAPI MimeMessage_FindFirst(IMimeMessage *iface, FINDBODY *pFindBody, HBODY *phBody)
2563 MimeMessage *This = impl_from_IMimeMessage(iface);
2565 TRACE("(%p)->(%p, %p)\n", iface, pFindBody, phBody);
2567 pFindBody->dwReserved = 0;
2568 return find_next(This, NULL, pFindBody, phBody);
2571 static HRESULT WINAPI MimeMessage_FindNext(IMimeMessage *iface, FINDBODY *pFindBody, HBODY *phBody)
2573 MimeMessage *This = impl_from_IMimeMessage(iface);
2574 body_t *body;
2575 HRESULT hr;
2577 TRACE("(%p)->(%p, %p)\n", iface, pFindBody, phBody);
2579 hr = find_body( &This->body_tree, UlongToHandle( pFindBody->dwReserved ), &body );
2580 if (hr != S_OK) return MIME_E_NOT_FOUND;
2581 return find_next(This, body, pFindBody, phBody);
2584 static HRESULT WINAPI MimeMessage_ResolveURL(
2585 IMimeMessage *iface,
2586 HBODY hRelated,
2587 LPCSTR pszBase,
2588 LPCSTR pszURL,
2589 DWORD dwFlags,
2590 LPHBODY phBody)
2592 FIXME("(%p)->(%p, %s, %s, 0x%x, %p)\n", iface, hRelated, pszBase, pszURL, dwFlags, phBody);
2593 return E_NOTIMPL;
2596 static HRESULT WINAPI MimeMessage_ToMultipart(
2597 IMimeMessage *iface,
2598 HBODY hBody,
2599 LPCSTR pszSubType,
2600 LPHBODY phMultipart)
2602 FIXME("(%p)->(%p, %s, %p)\n", iface, hBody, pszSubType, phMultipart);
2603 return E_NOTIMPL;
2606 static HRESULT WINAPI MimeMessage_GetBodyOffsets(
2607 IMimeMessage *iface,
2608 HBODY hBody,
2609 LPBODYOFFSETS pOffsets)
2611 FIXME("(%p)->(%p, %p)\n", iface, hBody, pOffsets);
2612 return E_NOTIMPL;
2615 static HRESULT WINAPI MimeMessage_GetCharset(
2616 IMimeMessage *iface,
2617 LPHCHARSET phCharset)
2619 FIXME("(%p)->(%p)\n", iface, phCharset);
2620 *phCharset = NULL;
2621 return S_OK;
2624 static HRESULT WINAPI MimeMessage_SetCharset(
2625 IMimeMessage *iface,
2626 HCHARSET hCharset,
2627 CSETAPPLYTYPE applytype)
2629 FIXME("(%p)->(%p, %d)\n", iface, hCharset, applytype);
2630 return E_NOTIMPL;
2633 static HRESULT WINAPI MimeMessage_IsBodyType(
2634 IMimeMessage *iface,
2635 HBODY hBody,
2636 IMSGBODYTYPE bodytype)
2638 HRESULT hr;
2639 IMimeBody *mime_body;
2640 TRACE("(%p)->(%p, %d)\n", iface, hBody, bodytype);
2642 hr = IMimeMessage_BindToObject(iface, hBody, &IID_IMimeBody, (void**)&mime_body);
2643 if(hr != S_OK) return hr;
2645 hr = IMimeBody_IsType(mime_body, bodytype);
2646 MimeBody_Release(mime_body);
2647 return hr;
2650 static HRESULT WINAPI MimeMessage_IsContentType(
2651 IMimeMessage *iface,
2652 HBODY hBody,
2653 LPCSTR pszPriType,
2654 LPCSTR pszSubType)
2656 HRESULT hr;
2657 IMimeBody *mime_body;
2658 TRACE("(%p)->(%p, %s, %s)\n", iface, hBody, debugstr_a(pszPriType),
2659 debugstr_a(pszSubType));
2661 hr = IMimeMessage_BindToObject(iface, hBody, &IID_IMimeBody, (void**)&mime_body);
2662 if(FAILED(hr)) return hr;
2664 hr = IMimeBody_IsContentType(mime_body, pszPriType, pszSubType);
2665 IMimeBody_Release(mime_body);
2666 return hr;
2669 static HRESULT WINAPI MimeMessage_QueryBodyProp(
2670 IMimeMessage *iface,
2671 HBODY hBody,
2672 LPCSTR pszName,
2673 LPCSTR pszCriteria,
2674 boolean fSubString,
2675 boolean fCaseSensitive)
2677 FIXME("(%p)->(%p, %s, %s, %s, %s)\n", iface, hBody, pszName, pszCriteria, fSubString ? "TRUE" : "FALSE", fCaseSensitive ? "TRUE" : "FALSE");
2678 return E_NOTIMPL;
2681 static HRESULT WINAPI MimeMessage_GetBodyProp(
2682 IMimeMessage *iface,
2683 HBODY hBody,
2684 LPCSTR pszName,
2685 DWORD dwFlags,
2686 LPPROPVARIANT pValue)
2688 HRESULT hr;
2689 IMimeBody *mime_body;
2691 TRACE("(%p)->(%p, %s, 0x%x, %p)\n", iface, hBody, pszName, dwFlags, pValue);
2693 hr = IMimeMessage_BindToObject(iface, hBody, &IID_IMimeBody, (void**)&mime_body);
2694 if(hr != S_OK) return hr;
2696 hr = IMimeBody_GetProp(mime_body, pszName, dwFlags, pValue);
2697 IMimeBody_Release(mime_body);
2699 return hr;
2702 static HRESULT WINAPI MimeMessage_SetBodyProp(
2703 IMimeMessage *iface,
2704 HBODY hBody,
2705 LPCSTR pszName,
2706 DWORD dwFlags,
2707 LPCPROPVARIANT pValue)
2709 FIXME("(%p)->(%p, %s, 0x%x, %p)\n", iface, hBody, pszName, dwFlags, pValue);
2710 return E_NOTIMPL;
2713 static HRESULT WINAPI MimeMessage_DeleteBodyProp(
2714 IMimeMessage *iface,
2715 HBODY hBody,
2716 LPCSTR pszName)
2718 FIXME("(%p)->(%p, %s)\n", iface, hBody, pszName);
2719 return E_NOTIMPL;
2722 static HRESULT WINAPI MimeMessage_SetOption(
2723 IMimeMessage *iface,
2724 const TYPEDID oid,
2725 LPCPROPVARIANT pValue)
2727 HRESULT hr = S_OK;
2728 TRACE("(%p)->(%08x, %p)\n", iface, oid, pValue);
2730 /* Message ID is checked before type.
2731 * OID 0x4D -> 0x56 and 0x58 aren't defined but will filtered out later.
2733 if(TYPEDID_ID(oid) < TYPEDID_ID(OID_ALLOW_8BIT_HEADER) || TYPEDID_ID(oid) > TYPEDID_ID(OID_SECURITY_2KEY_CERT_BAG_64))
2735 WARN("oid (%08x) out of range\n", oid);
2736 return MIME_E_INVALID_OPTION_ID;
2739 if(pValue->vt != TYPEDID_TYPE(oid))
2741 WARN("Called with vartype %04x and oid %08x\n", pValue->vt, oid);
2742 return S_OK;
2745 switch(oid)
2747 case OID_HIDE_TNEF_ATTACHMENTS:
2748 FIXME("OID_HIDE_TNEF_ATTACHMENTS (value %d): ignoring\n", pValue->boolVal);
2749 break;
2750 case OID_SHOW_MACBINARY:
2751 FIXME("OID_SHOW_MACBINARY (value %d): ignoring\n", pValue->boolVal);
2752 break;
2753 case OID_SAVEBODY_KEEPBOUNDARY:
2754 FIXME("OID_SAVEBODY_KEEPBOUNDARY (value %d): ignoring\n", pValue->boolVal);
2755 break;
2756 case OID_CLEANUP_TREE_ON_SAVE:
2757 FIXME("OID_CLEANUP_TREE_ON_SAVE (value %d): ignoring\n", pValue->boolVal);
2758 break;
2759 default:
2760 FIXME("Unhandled oid %08x\n", oid);
2761 hr = MIME_E_INVALID_OPTION_ID;
2764 return hr;
2767 static HRESULT WINAPI MimeMessage_GetOption(
2768 IMimeMessage *iface,
2769 const TYPEDID oid,
2770 LPPROPVARIANT pValue)
2772 FIXME("(%p)->(%08x, %p)\n", iface, oid, pValue);
2773 return E_NOTIMPL;
2776 /*** IMimeMessage methods ***/
2777 static HRESULT WINAPI MimeMessage_CreateWebPage(
2778 IMimeMessage *iface,
2779 IStream *pRootStm,
2780 LPWEBPAGEOPTIONS pOptions,
2781 IMimeMessageCallback *pCallback,
2782 IMoniker **ppMoniker)
2784 FIXME("(%p)->(%p, %p, %p, %p)\n", iface, pRootStm, pOptions, pCallback, ppMoniker);
2785 *ppMoniker = NULL;
2786 return E_NOTIMPL;
2789 static HRESULT WINAPI MimeMessage_GetProp(
2790 IMimeMessage *iface,
2791 LPCSTR pszName,
2792 DWORD dwFlags,
2793 LPPROPVARIANT pValue)
2795 FIXME("(%p)->(%s, 0x%x, %p)\n", iface, pszName, dwFlags, pValue);
2796 return E_NOTIMPL;
2799 static HRESULT WINAPI MimeMessage_SetProp(
2800 IMimeMessage *iface,
2801 LPCSTR pszName,
2802 DWORD dwFlags,
2803 LPCPROPVARIANT pValue)
2805 FIXME("(%p)->(%s, 0x%x, %p)\n", iface, pszName, dwFlags, pValue);
2806 return E_NOTIMPL;
2809 static HRESULT WINAPI MimeMessage_DeleteProp(
2810 IMimeMessage *iface,
2811 LPCSTR pszName)
2813 FIXME("(%p)->(%s)\n", iface, pszName);
2814 return E_NOTIMPL;
2817 static HRESULT WINAPI MimeMessage_QueryProp(
2818 IMimeMessage *iface,
2819 LPCSTR pszName,
2820 LPCSTR pszCriteria,
2821 boolean fSubString,
2822 boolean fCaseSensitive)
2824 FIXME("(%p)->(%s, %s, %s, %s)\n", iface, pszName, pszCriteria, fSubString ? "TRUE" : "FALSE", fCaseSensitive ? "TRUE" : "FALSE");
2825 return E_NOTIMPL;
2828 static HRESULT WINAPI MimeMessage_GetTextBody(
2829 IMimeMessage *iface,
2830 DWORD dwTxtType,
2831 ENCODINGTYPE ietEncoding,
2832 IStream **pStream,
2833 LPHBODY phBody)
2835 HRESULT hr;
2836 HBODY hbody;
2837 FINDBODY find_struct;
2838 IMimeBody *mime_body;
2839 static char text[] = "text";
2840 static char plain[] = "plain";
2841 static char html[] = "html";
2843 TRACE("(%p)->(%d, %d, %p, %p)\n", iface, dwTxtType, ietEncoding, pStream, phBody);
2845 find_struct.pszPriType = text;
2847 switch(dwTxtType)
2849 case TXT_PLAIN:
2850 find_struct.pszSubType = plain;
2851 break;
2852 case TXT_HTML:
2853 find_struct.pszSubType = html;
2854 break;
2855 default:
2856 return MIME_E_INVALID_TEXT_TYPE;
2859 hr = IMimeMessage_FindFirst(iface, &find_struct, &hbody);
2860 if(hr != S_OK)
2862 TRACE("not found hr %08x\n", hr);
2863 *phBody = NULL;
2864 return hr;
2867 IMimeMessage_BindToObject(iface, hbody, &IID_IMimeBody, (void**)&mime_body);
2869 IMimeBody_GetData(mime_body, ietEncoding, pStream);
2870 *phBody = hbody;
2871 IMimeBody_Release(mime_body);
2872 return hr;
2875 static HRESULT WINAPI MimeMessage_SetTextBody(
2876 IMimeMessage *iface,
2877 DWORD dwTxtType,
2878 ENCODINGTYPE ietEncoding,
2879 HBODY hAlternative,
2880 IStream *pStream,
2881 LPHBODY phBody)
2883 FIXME("(%p)->(%d, %d, %p, %p, %p)\n", iface, dwTxtType, ietEncoding, hAlternative, pStream, phBody);
2884 return E_NOTIMPL;
2887 static HRESULT WINAPI MimeMessage_AttachObject(
2888 IMimeMessage *iface,
2889 REFIID riid,
2890 void *pvObject,
2891 LPHBODY phBody)
2893 FIXME("(%p)->(%s, %p, %p)\n", iface, debugstr_guid(riid), pvObject, phBody);
2894 return E_NOTIMPL;
2897 static HRESULT WINAPI MimeMessage_AttachFile(
2898 IMimeMessage *iface,
2899 LPCSTR pszFilePath,
2900 IStream *pstmFile,
2901 LPHBODY phBody)
2903 FIXME("(%p)->(%s, %p, %p)\n", iface, pszFilePath, pstmFile, phBody);
2904 return E_NOTIMPL;
2907 static HRESULT WINAPI MimeMessage_AttachURL(
2908 IMimeMessage *iface,
2909 LPCSTR pszBase,
2910 LPCSTR pszURL,
2911 DWORD dwFlags,
2912 IStream *pstmURL,
2913 LPSTR *ppszCIDURL,
2914 LPHBODY phBody)
2916 FIXME("(%p)->(%s, %s, 0x%x, %p, %p, %p)\n", iface, pszBase, pszURL, dwFlags, pstmURL, ppszCIDURL, phBody);
2917 return E_NOTIMPL;
2920 static HRESULT WINAPI MimeMessage_GetAttachments(
2921 IMimeMessage *iface,
2922 ULONG *pcAttach,
2923 LPHBODY *pprghAttach)
2925 HRESULT hr;
2926 FINDBODY find_struct;
2927 HBODY hbody;
2928 LPHBODY array;
2929 ULONG size = 10;
2931 TRACE("(%p)->(%p, %p)\n", iface, pcAttach, pprghAttach);
2933 *pcAttach = 0;
2934 array = CoTaskMemAlloc(size * sizeof(HBODY));
2936 find_struct.pszPriType = find_struct.pszSubType = NULL;
2937 hr = IMimeMessage_FindFirst(iface, &find_struct, &hbody);
2938 while(hr == S_OK)
2940 hr = IMimeMessage_IsContentType(iface, hbody, "multipart", NULL);
2941 TRACE("IsCT rets %08x %d\n", hr, *pcAttach);
2942 if(hr != S_OK)
2944 if(*pcAttach + 1 > size)
2946 size *= 2;
2947 array = CoTaskMemRealloc(array, size * sizeof(HBODY));
2949 array[*pcAttach] = hbody;
2950 (*pcAttach)++;
2952 hr = IMimeMessage_FindNext(iface, &find_struct, &hbody);
2955 *pprghAttach = array;
2956 return S_OK;
2959 static HRESULT WINAPI MimeMessage_GetAddressTable(
2960 IMimeMessage *iface,
2961 IMimeAddressTable **ppTable)
2963 FIXME("(%p)->(%p)\n", iface, ppTable);
2964 return E_NOTIMPL;
2967 static HRESULT WINAPI MimeMessage_GetSender(
2968 IMimeMessage *iface,
2969 LPADDRESSPROPS pAddress)
2971 FIXME("(%p)->(%p)\n", iface, pAddress);
2972 return E_NOTIMPL;
2975 static HRESULT WINAPI MimeMessage_GetAddressTypes(
2976 IMimeMessage *iface,
2977 DWORD dwAdrTypes,
2978 DWORD dwProps,
2979 LPADDRESSLIST pList)
2981 FIXME("(%p)->(%d, %d, %p)\n", iface, dwAdrTypes, dwProps, pList);
2982 return E_NOTIMPL;
2985 static HRESULT WINAPI MimeMessage_GetAddressFormat(
2986 IMimeMessage *iface,
2987 DWORD dwAdrTypes,
2988 ADDRESSFORMAT format,
2989 LPSTR *ppszFormat)
2991 FIXME("(%p)->(%d, %d, %p)\n", iface, dwAdrTypes, format, ppszFormat);
2992 return E_NOTIMPL;
2995 static HRESULT WINAPI MimeMessage_EnumAddressTypes(
2996 IMimeMessage *iface,
2997 DWORD dwAdrTypes,
2998 DWORD dwProps,
2999 IMimeEnumAddressTypes **ppEnum)
3001 FIXME("(%p)->(%d, %d, %p)\n", iface, dwAdrTypes, dwProps, ppEnum);
3002 return E_NOTIMPL;
3005 static HRESULT WINAPI MimeMessage_SplitMessage(
3006 IMimeMessage *iface,
3007 ULONG cbMaxPart,
3008 IMimeMessageParts **ppParts)
3010 FIXME("(%p)->(%d, %p)\n", iface, cbMaxPart, ppParts);
3011 return E_NOTIMPL;
3014 static HRESULT WINAPI MimeMessage_GetRootMoniker(
3015 IMimeMessage *iface,
3016 IMoniker **ppMoniker)
3018 FIXME("(%p)->(%p)\n", iface, ppMoniker);
3019 return E_NOTIMPL;
3022 static const IMimeMessageVtbl MimeMessageVtbl =
3024 MimeMessage_QueryInterface,
3025 MimeMessage_AddRef,
3026 MimeMessage_Release,
3027 MimeMessage_GetClassID,
3028 MimeMessage_IsDirty,
3029 MimeMessage_Load,
3030 MimeMessage_Save,
3031 MimeMessage_GetSizeMax,
3032 MimeMessage_InitNew,
3033 MimeMessage_GetMessageSource,
3034 MimeMessage_GetMessageSize,
3035 MimeMessage_LoadOffsetTable,
3036 MimeMessage_SaveOffsetTable,
3037 MimeMessage_GetFlags,
3038 MimeMessage_Commit,
3039 MimeMessage_HandsOffStorage,
3040 MimeMessage_BindToObject,
3041 MimeMessage_SaveBody,
3042 MimeMessage_InsertBody,
3043 MimeMessage_GetBody,
3044 MimeMessage_DeleteBody,
3045 MimeMessage_MoveBody,
3046 MimeMessage_CountBodies,
3047 MimeMessage_FindFirst,
3048 MimeMessage_FindNext,
3049 MimeMessage_ResolveURL,
3050 MimeMessage_ToMultipart,
3051 MimeMessage_GetBodyOffsets,
3052 MimeMessage_GetCharset,
3053 MimeMessage_SetCharset,
3054 MimeMessage_IsBodyType,
3055 MimeMessage_IsContentType,
3056 MimeMessage_QueryBodyProp,
3057 MimeMessage_GetBodyProp,
3058 MimeMessage_SetBodyProp,
3059 MimeMessage_DeleteBodyProp,
3060 MimeMessage_SetOption,
3061 MimeMessage_GetOption,
3062 MimeMessage_CreateWebPage,
3063 MimeMessage_GetProp,
3064 MimeMessage_SetProp,
3065 MimeMessage_DeleteProp,
3066 MimeMessage_QueryProp,
3067 MimeMessage_GetTextBody,
3068 MimeMessage_SetTextBody,
3069 MimeMessage_AttachObject,
3070 MimeMessage_AttachFile,
3071 MimeMessage_AttachURL,
3072 MimeMessage_GetAttachments,
3073 MimeMessage_GetAddressTable,
3074 MimeMessage_GetSender,
3075 MimeMessage_GetAddressTypes,
3076 MimeMessage_GetAddressFormat,
3077 MimeMessage_EnumAddressTypes,
3078 MimeMessage_SplitMessage,
3079 MimeMessage_GetRootMoniker,
3082 HRESULT MimeMessage_create(IUnknown *outer, void **obj)
3084 MimeMessage *This;
3085 MimeBody *mime_body;
3086 body_t *root_body;
3088 TRACE("(%p, %p)\n", outer, obj);
3090 if (outer)
3092 FIXME("outer unknown not supported yet\n");
3093 return E_NOTIMPL;
3096 *obj = NULL;
3098 This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
3099 if (!This) return E_OUTOFMEMORY;
3101 This->IMimeMessage_iface.lpVtbl = &MimeMessageVtbl;
3102 This->ref = 1;
3103 This->stream = NULL;
3104 list_init(&This->body_tree);
3105 This->next_index = 1;
3107 mime_body = mimebody_create();
3108 root_body = new_body_entry(mime_body, This->next_index++, NULL);
3109 list_add_head(&This->body_tree, &root_body->entry);
3111 *obj = &This->IMimeMessage_iface;
3112 return S_OK;
3115 /***********************************************************************
3116 * MimeOleCreateMessage (INETCOMM.@)
3118 HRESULT WINAPI MimeOleCreateMessage(IUnknown *pUnkOuter, IMimeMessage **ppMessage)
3120 TRACE("(%p, %p)\n", pUnkOuter, ppMessage);
3121 return MimeMessage_create(NULL, (void **)ppMessage);
3124 /***********************************************************************
3125 * MimeOleSetCompatMode (INETCOMM.@)
3127 HRESULT WINAPI MimeOleSetCompatMode(DWORD dwMode)
3129 FIXME("(0x%x)\n", dwMode);
3130 return S_OK;
3133 /***********************************************************************
3134 * MimeOleCreateVirtualStream (INETCOMM.@)
3136 HRESULT WINAPI MimeOleCreateVirtualStream(IStream **ppStream)
3138 HRESULT hr;
3139 FIXME("(%p)\n", ppStream);
3141 hr = CreateStreamOnHGlobal(NULL, TRUE, ppStream);
3142 return hr;
3145 typedef struct MimeSecurity
3147 IMimeSecurity IMimeSecurity_iface;
3148 LONG ref;
3149 } MimeSecurity;
3151 static inline MimeSecurity *impl_from_IMimeSecurity(IMimeSecurity *iface)
3153 return CONTAINING_RECORD(iface, MimeSecurity, IMimeSecurity_iface);
3156 static HRESULT WINAPI MimeSecurity_QueryInterface(IMimeSecurity *iface, REFIID riid, void **ppv)
3158 TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppv);
3160 if (IsEqualIID(riid, &IID_IUnknown) ||
3161 IsEqualIID(riid, &IID_IMimeSecurity))
3163 *ppv = iface;
3164 IMimeSecurity_AddRef(iface);
3165 return S_OK;
3168 FIXME("no interface for %s\n", debugstr_guid(riid));
3169 *ppv = NULL;
3170 return E_NOINTERFACE;
3173 static ULONG WINAPI MimeSecurity_AddRef(IMimeSecurity *iface)
3175 MimeSecurity *This = impl_from_IMimeSecurity(iface);
3176 LONG ref = InterlockedIncrement(&This->ref);
3178 TRACE("(%p) ref=%d\n", This, ref);
3180 return ref;
3183 static ULONG WINAPI MimeSecurity_Release(IMimeSecurity *iface)
3185 MimeSecurity *This = impl_from_IMimeSecurity(iface);
3186 LONG ref = InterlockedDecrement(&This->ref);
3188 TRACE("(%p) ref=%d\n", This, ref);
3190 if (!ref)
3191 HeapFree(GetProcessHeap(), 0, This);
3193 return ref;
3196 static HRESULT WINAPI MimeSecurity_InitNew(
3197 IMimeSecurity* iface)
3199 FIXME("(%p)->(): stub\n", iface);
3200 return S_OK;
3203 static HRESULT WINAPI MimeSecurity_CheckInit(
3204 IMimeSecurity* iface)
3206 FIXME("(%p)->(): stub\n", iface);
3207 return E_NOTIMPL;
3210 static HRESULT WINAPI MimeSecurity_EncodeMessage(
3211 IMimeSecurity* iface,
3212 IMimeMessageTree* pTree,
3213 DWORD dwFlags)
3215 FIXME("(%p)->(%p, %08x): stub\n", iface, pTree, dwFlags);
3216 return E_NOTIMPL;
3219 static HRESULT WINAPI MimeSecurity_EncodeBody(
3220 IMimeSecurity* iface,
3221 IMimeMessageTree* pTree,
3222 HBODY hEncodeRoot,
3223 DWORD dwFlags)
3225 FIXME("(%p)->(%p, %p, %08x): stub\n", iface, pTree, hEncodeRoot, dwFlags);
3226 return E_NOTIMPL;
3229 static HRESULT WINAPI MimeSecurity_DecodeMessage(
3230 IMimeSecurity* iface,
3231 IMimeMessageTree* pTree,
3232 DWORD dwFlags)
3234 FIXME("(%p)->(%p, %08x): stub\n", iface, pTree, dwFlags);
3235 return E_NOTIMPL;
3238 static HRESULT WINAPI MimeSecurity_DecodeBody(
3239 IMimeSecurity* iface,
3240 IMimeMessageTree* pTree,
3241 HBODY hDecodeRoot,
3242 DWORD dwFlags)
3244 FIXME("(%p)->(%p, %p, %08x): stub\n", iface, pTree, hDecodeRoot, dwFlags);
3245 return E_NOTIMPL;
3248 static HRESULT WINAPI MimeSecurity_EnumCertificates(
3249 IMimeSecurity* iface,
3250 HCAPICERTSTORE hc,
3251 DWORD dwUsage,
3252 PCX509CERT pPrev,
3253 PCX509CERT* ppCert)
3255 FIXME("(%p)->(%p, %08x, %p, %p): stub\n", iface, hc, dwUsage, pPrev, ppCert);
3256 return E_NOTIMPL;
3259 static HRESULT WINAPI MimeSecurity_GetCertificateName(
3260 IMimeSecurity* iface,
3261 const PCX509CERT pX509Cert,
3262 const CERTNAMETYPE cn,
3263 LPSTR* ppszName)
3265 FIXME("(%p)->(%p, %08x, %p): stub\n", iface, pX509Cert, cn, ppszName);
3266 return E_NOTIMPL;
3269 static HRESULT WINAPI MimeSecurity_GetMessageType(
3270 IMimeSecurity* iface,
3271 const HWND hwndParent,
3272 IMimeBody* pBody,
3273 DWORD* pdwSecType)
3275 FIXME("(%p)->(%p, %p, %p): stub\n", iface, hwndParent, pBody, pdwSecType);
3276 return E_NOTIMPL;
3279 static HRESULT WINAPI MimeSecurity_GetCertData(
3280 IMimeSecurity* iface,
3281 const PCX509CERT pX509Cert,
3282 const CERTDATAID dataid,
3283 LPPROPVARIANT pValue)
3285 FIXME("(%p)->(%p, %x, %p): stub\n", iface, pX509Cert, dataid, pValue);
3286 return E_NOTIMPL;
3290 static const IMimeSecurityVtbl MimeSecurityVtbl =
3292 MimeSecurity_QueryInterface,
3293 MimeSecurity_AddRef,
3294 MimeSecurity_Release,
3295 MimeSecurity_InitNew,
3296 MimeSecurity_CheckInit,
3297 MimeSecurity_EncodeMessage,
3298 MimeSecurity_EncodeBody,
3299 MimeSecurity_DecodeMessage,
3300 MimeSecurity_DecodeBody,
3301 MimeSecurity_EnumCertificates,
3302 MimeSecurity_GetCertificateName,
3303 MimeSecurity_GetMessageType,
3304 MimeSecurity_GetCertData
3307 HRESULT MimeSecurity_create(IUnknown *outer, void **obj)
3309 MimeSecurity *This;
3311 *obj = NULL;
3313 if (outer) return CLASS_E_NOAGGREGATION;
3315 This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
3316 if (!This) return E_OUTOFMEMORY;
3318 This->IMimeSecurity_iface.lpVtbl = &MimeSecurityVtbl;
3319 This->ref = 1;
3321 *obj = &This->IMimeSecurity_iface;
3322 return S_OK;
3325 /***********************************************************************
3326 * MimeOleCreateSecurity (INETCOMM.@)
3328 HRESULT WINAPI MimeOleCreateSecurity(IMimeSecurity **ppSecurity)
3330 return MimeSecurity_create(NULL, (void **)ppSecurity);
3333 static HRESULT WINAPI MimeAlloc_QueryInterface(
3334 IMimeAllocator* iface,
3335 REFIID riid,
3336 void **obj)
3338 TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), obj);
3340 if (IsEqualIID(riid, &IID_IUnknown) ||
3341 IsEqualIID(riid, &IID_IMalloc) ||
3342 IsEqualIID(riid, &IID_IMimeAllocator))
3344 *obj = iface;
3345 IMimeAllocator_AddRef(iface);
3346 return S_OK;
3349 FIXME("no interface for %s\n", debugstr_guid(riid));
3350 *obj = NULL;
3351 return E_NOINTERFACE;
3354 static ULONG WINAPI MimeAlloc_AddRef(
3355 IMimeAllocator* iface)
3357 return 2;
3360 static ULONG WINAPI MimeAlloc_Release(
3361 IMimeAllocator* iface)
3363 return 1;
3366 static LPVOID WINAPI MimeAlloc_Alloc(
3367 IMimeAllocator* iface,
3368 SIZE_T cb)
3370 return CoTaskMemAlloc(cb);
3373 static LPVOID WINAPI MimeAlloc_Realloc(
3374 IMimeAllocator* iface,
3375 LPVOID pv,
3376 SIZE_T cb)
3378 return CoTaskMemRealloc(pv, cb);
3381 static void WINAPI MimeAlloc_Free(
3382 IMimeAllocator* iface,
3383 LPVOID pv)
3385 CoTaskMemFree(pv);
3388 static SIZE_T WINAPI MimeAlloc_GetSize(
3389 IMimeAllocator* iface,
3390 LPVOID pv)
3392 FIXME("stub\n");
3393 return 0;
3396 static int WINAPI MimeAlloc_DidAlloc(
3397 IMimeAllocator* iface,
3398 LPVOID pv)
3400 FIXME("stub\n");
3401 return 0;
3404 static void WINAPI MimeAlloc_HeapMinimize(
3405 IMimeAllocator* iface)
3407 FIXME("stub\n");
3408 return;
3411 static HRESULT WINAPI MimeAlloc_FreeParamInfoArray(
3412 IMimeAllocator* iface,
3413 ULONG cParams,
3414 LPMIMEPARAMINFO prgParam,
3415 boolean fFreeArray)
3417 ULONG i;
3418 TRACE("(%p)->(%d, %p, %d)\n", iface, cParams, prgParam, fFreeArray);
3420 for(i = 0; i < cParams; i++)
3422 IMimeAllocator_Free(iface, prgParam[i].pszName);
3423 IMimeAllocator_Free(iface, prgParam[i].pszData);
3425 if(fFreeArray) IMimeAllocator_Free(iface, prgParam);
3426 return S_OK;
3429 static HRESULT WINAPI MimeAlloc_FreeAddressList(
3430 IMimeAllocator* iface,
3431 LPADDRESSLIST pList)
3433 FIXME("stub\n");
3434 return E_NOTIMPL;
3437 static HRESULT WINAPI MimeAlloc_FreeAddressProps(
3438 IMimeAllocator* iface,
3439 LPADDRESSPROPS pAddress)
3441 FIXME("stub\n");
3442 return E_NOTIMPL;
3445 static HRESULT WINAPI MimeAlloc_ReleaseObjects(
3446 IMimeAllocator* iface,
3447 ULONG cObjects,
3448 IUnknown **prgpUnknown,
3449 boolean fFreeArray)
3451 FIXME("stub\n");
3452 return E_NOTIMPL;
3456 static HRESULT WINAPI MimeAlloc_FreeEnumHeaderRowArray(
3457 IMimeAllocator* iface,
3458 ULONG cRows,
3459 LPENUMHEADERROW prgRow,
3460 boolean fFreeArray)
3462 FIXME("stub\n");
3463 return E_NOTIMPL;
3466 static HRESULT WINAPI MimeAlloc_FreeEnumPropertyArray(
3467 IMimeAllocator* iface,
3468 ULONG cProps,
3469 LPENUMPROPERTY prgProp,
3470 boolean fFreeArray)
3472 FIXME("stub\n");
3473 return E_NOTIMPL;
3476 static HRESULT WINAPI MimeAlloc_FreeThumbprint(
3477 IMimeAllocator* iface,
3478 THUMBBLOB *pthumbprint)
3480 FIXME("stub\n");
3481 return E_NOTIMPL;
3485 static HRESULT WINAPI MimeAlloc_PropVariantClear(
3486 IMimeAllocator* iface,
3487 LPPROPVARIANT pProp)
3489 FIXME("stub\n");
3490 return E_NOTIMPL;
3493 static IMimeAllocatorVtbl mime_alloc_vtbl =
3495 MimeAlloc_QueryInterface,
3496 MimeAlloc_AddRef,
3497 MimeAlloc_Release,
3498 MimeAlloc_Alloc,
3499 MimeAlloc_Realloc,
3500 MimeAlloc_Free,
3501 MimeAlloc_GetSize,
3502 MimeAlloc_DidAlloc,
3503 MimeAlloc_HeapMinimize,
3504 MimeAlloc_FreeParamInfoArray,
3505 MimeAlloc_FreeAddressList,
3506 MimeAlloc_FreeAddressProps,
3507 MimeAlloc_ReleaseObjects,
3508 MimeAlloc_FreeEnumHeaderRowArray,
3509 MimeAlloc_FreeEnumPropertyArray,
3510 MimeAlloc_FreeThumbprint,
3511 MimeAlloc_PropVariantClear
3514 static IMimeAllocator mime_allocator =
3516 &mime_alloc_vtbl
3519 HRESULT MimeAllocator_create(IUnknown *outer, void **obj)
3521 if(outer) return CLASS_E_NOAGGREGATION;
3523 *obj = &mime_allocator;
3524 return S_OK;
3527 HRESULT WINAPI MimeOleGetAllocator(IMimeAllocator **alloc)
3529 return MimeAllocator_create(NULL, (void**)alloc);
3532 HRESULT VirtualStream_create(IUnknown *outer, void **obj)
3534 FIXME("(%p, %p)\n", outer, obj);
3536 *obj = NULL;
3537 if (outer) return CLASS_E_NOAGGREGATION;
3539 return MimeOleCreateVirtualStream((IStream **)obj);
3542 /* IMimePropertySchema Interface */
3543 static HRESULT WINAPI propschema_QueryInterface(IMimePropertySchema *iface, REFIID riid, void **out)
3545 propschema *This = impl_from_IMimePropertySchema(iface);
3546 TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), out);
3548 *out = NULL;
3550 if (IsEqualIID(riid, &IID_IUnknown) ||
3551 IsEqualIID(riid, &IID_IMimePropertySchema))
3553 *out = iface;
3555 else
3557 FIXME("no interface for %s\n", debugstr_guid(riid));
3558 return E_NOINTERFACE;
3561 IMimePropertySchema_AddRef(iface);
3562 return S_OK;
3565 static ULONG WINAPI propschema_AddRef(IMimePropertySchema *iface)
3567 propschema *This = impl_from_IMimePropertySchema(iface);
3568 LONG ref = InterlockedIncrement(&This->ref);
3570 TRACE("(%p) ref=%d\n", This, ref);
3572 return ref;
3575 static ULONG WINAPI propschema_Release(IMimePropertySchema *iface)
3577 propschema *This = impl_from_IMimePropertySchema(iface);
3578 LONG ref = InterlockedDecrement(&This->ref);
3580 TRACE("(%p) ref=%d\n", This, ref);
3582 if (!ref)
3584 HeapFree(GetProcessHeap(), 0, This);
3587 return ref;
3590 static HRESULT WINAPI propschema_RegisterProperty(IMimePropertySchema *iface, const char *name, DWORD flags,
3591 DWORD rownumber, VARTYPE vtdefault, DWORD *propid)
3593 propschema *This = impl_from_IMimePropertySchema(iface);
3594 FIXME("(%p)->(%s, %x, %d, %d, %p) stub\n", This, debugstr_a(name), flags, rownumber, vtdefault, propid);
3595 return E_NOTIMPL;
3598 static HRESULT WINAPI propschema_ModifyProperty(IMimePropertySchema *iface, const char *name, DWORD flags,
3599 DWORD rownumber, VARTYPE vtdefault)
3601 propschema *This = impl_from_IMimePropertySchema(iface);
3602 FIXME("(%p)->(%s, %x, %d, %d) stub\n", This, debugstr_a(name), flags, rownumber, vtdefault);
3603 return S_OK;
3606 static HRESULT WINAPI propschema_GetPropertyId(IMimePropertySchema *iface, const char *name, DWORD *propid)
3608 propschema *This = impl_from_IMimePropertySchema(iface);
3609 FIXME("(%p)->(%s, %p) stub\n", This, debugstr_a(name), propid);
3610 return E_NOTIMPL;
3613 static HRESULT WINAPI propschema_GetPropertyName(IMimePropertySchema *iface, DWORD propid, char **name)
3615 propschema *This = impl_from_IMimePropertySchema(iface);
3616 FIXME("(%p)->(%d, %p) stub\n", This, propid, name);
3617 return E_NOTIMPL;
3620 static HRESULT WINAPI propschema_RegisterAddressType(IMimePropertySchema *iface, const char *name, DWORD *adrtype)
3622 propschema *This = impl_from_IMimePropertySchema(iface);
3623 FIXME("(%p)->(%s, %p) stub\n", This, debugstr_a(name), adrtype);
3624 return E_NOTIMPL;
3627 static IMimePropertySchemaVtbl prop_schema_vtbl =
3629 propschema_QueryInterface,
3630 propschema_AddRef,
3631 propschema_Release,
3632 propschema_RegisterProperty,
3633 propschema_ModifyProperty,
3634 propschema_GetPropertyId,
3635 propschema_GetPropertyName,
3636 propschema_RegisterAddressType
3640 HRESULT WINAPI MimeOleGetPropertySchema(IMimePropertySchema **schema)
3642 propschema *This;
3644 TRACE("(%p) stub\n", schema);
3646 This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
3647 if (!This)
3648 return E_OUTOFMEMORY;
3650 This->IMimePropertySchema_iface.lpVtbl = &prop_schema_vtbl;
3651 This->ref = 1;
3653 *schema = &This->IMimePropertySchema_iface;
3655 return S_OK;
3658 HRESULT WINAPI MimeGetAddressFormatW(REFIID riid, void *object, DWORD addr_type,
3659 ADDRESSFORMAT addr_format, WCHAR **address)
3661 FIXME("(%s, %p, %d, %d, %p) stub\n", debugstr_guid(riid), object, addr_type, addr_format, address);
3663 return E_NOTIMPL;
3666 static HRESULT WINAPI mime_obj_QueryInterface(IUnknown *iface, REFIID riid, void **ppv)
3668 FIXME("(%s %p)\n", debugstr_guid(riid), ppv);
3669 *ppv = NULL;
3670 return E_NOINTERFACE;
3673 static ULONG WINAPI mime_obj_AddRef(IUnknown *iface)
3675 TRACE("\n");
3676 return 2;
3679 static ULONG WINAPI mime_obj_Release(IUnknown *iface)
3681 TRACE("\n");
3682 return 1;
3685 static const IUnknownVtbl mime_obj_vtbl = {
3686 mime_obj_QueryInterface,
3687 mime_obj_AddRef,
3688 mime_obj_Release
3691 static IUnknown mime_obj = { &mime_obj_vtbl };
3693 HRESULT WINAPI MimeOleObjectFromMoniker(BINDF bindf, IMoniker *moniker, IBindCtx *binding,
3694 REFIID riid, void **out, IMoniker **moniker_new)
3696 WCHAR *display_name, *mhtml_url;
3697 size_t len;
3698 HRESULT hres;
3700 WARN("(0x%08x, %p, %p, %s, %p, %p) semi-stub\n", bindf, moniker, binding, debugstr_guid(riid), out, moniker_new);
3702 if(!IsEqualGUID(&IID_IUnknown, riid)) {
3703 FIXME("Unsupported riid %s\n", debugstr_guid(riid));
3704 return E_NOINTERFACE;
3707 hres = IMoniker_GetDisplayName(moniker, NULL, NULL, &display_name);
3708 if(FAILED(hres))
3709 return hres;
3711 TRACE("display name %s\n", debugstr_w(display_name));
3713 len = lstrlenW(display_name);
3714 mhtml_url = heap_alloc(len*sizeof(WCHAR) + sizeof(L"mhtml:"));
3715 if(!mhtml_url)
3716 return E_OUTOFMEMORY;
3718 lstrcpyW(mhtml_url, L"mhtml:");
3719 lstrcatW(mhtml_url, display_name);
3720 HeapFree(GetProcessHeap(), 0, display_name);
3722 hres = CreateURLMoniker(NULL, mhtml_url, moniker_new);
3723 heap_free(mhtml_url);
3724 if(FAILED(hres))
3725 return hres;
3727 /* FIXME: We most likely should start binding here and return something more meaningful as mime object. */
3728 *out = &mime_obj;
3729 return S_OK;