wevtapi: Add EvtOpenLog stub.
[wine.git] / dlls / inetcomm / mimeole.c
blobf0e186ca1f17349a90770b18c789b90701d9ad2d
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 "winuser.h"
31 #include "objbase.h"
32 #include "ole2.h"
33 #include "mimeole.h"
34 #include "propvarutil.h"
36 #include "wine/list.h"
37 #include "wine/debug.h"
38 #include "wine/unicode.h"
40 #include "inetcomm_private.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(inetcomm);
44 typedef struct
46 LPCSTR name;
47 DWORD id;
48 DWORD flags; /* MIMEPROPFLAGS */
49 VARTYPE default_vt;
50 } property_t;
52 typedef struct
54 struct list entry;
55 property_t prop;
56 } property_list_entry_t;
58 static const property_t default_props[] =
60 {"X-Newsgroup", PID_HDR_NEWSGROUP, 0, VT_LPSTR},
61 {"Newsgroups", PID_HDR_NEWSGROUPS, 0, VT_LPSTR},
62 {"References", PID_HDR_REFS, 0, VT_LPSTR},
63 {"Subject", PID_HDR_SUBJECT, 0, VT_LPSTR},
64 {"From", PID_HDR_FROM, MPF_ADDRESS, VT_LPSTR},
65 {"Message-ID", PID_HDR_MESSAGEID, 0, VT_LPSTR},
66 {"Return-Path", PID_HDR_RETURNPATH, MPF_ADDRESS, VT_LPSTR},
67 {"Rr", PID_HDR_RR, 0, VT_LPSTR},
68 {"Return-Receipt-To", PID_HDR_RETRCPTO, MPF_ADDRESS, VT_LPSTR},
69 {"Apparently-To", PID_HDR_APPARTO, MPF_ADDRESS, VT_LPSTR},
70 {"Date", PID_HDR_DATE, 0, VT_LPSTR},
71 {"Received", PID_HDR_RECEIVED, 0, VT_LPSTR},
72 {"Reply-To", PID_HDR_REPLYTO, MPF_ADDRESS, VT_LPSTR},
73 {"X-Mailer", PID_HDR_XMAILER, 0, VT_LPSTR},
74 {"Bcc", PID_HDR_BCC, MPF_ADDRESS, VT_LPSTR},
75 {"MIME-Version", PID_HDR_MIMEVER, MPF_MIME, VT_LPSTR},
76 {"Content-Type", PID_HDR_CNTTYPE, MPF_MIME | MPF_HASPARAMS, VT_LPSTR},
77 {"Content-Transfer-Encoding", PID_HDR_CNTXFER, MPF_MIME, VT_LPSTR},
78 {"Content-ID", PID_HDR_CNTID, MPF_MIME, VT_LPSTR},
79 {"Content-Description", PID_HDR_CNTDESC, MPF_MIME, VT_LPSTR},
80 {"Content-Disposition", PID_HDR_CNTDISP, MPF_MIME | MPF_HASPARAMS, VT_LPSTR},
81 {"Content-Base", PID_HDR_CNTBASE, MPF_MIME, VT_LPSTR},
82 {"Content-Location", PID_HDR_CNTLOC, MPF_MIME, VT_LPSTR},
83 {"To", PID_HDR_TO, MPF_ADDRESS, VT_LPSTR},
84 {"Path", PID_HDR_PATH, 0, VT_LPSTR},
85 {"Followup-To", PID_HDR_FOLLOWUPTO, 0, VT_LPSTR},
86 {"Expires", PID_HDR_EXPIRES, 0, VT_LPSTR},
87 {"Cc", PID_HDR_CC, MPF_ADDRESS, VT_LPSTR},
88 {"Control", PID_HDR_CONTROL, 0, VT_LPSTR},
89 {"Distribution", PID_HDR_DISTRIB, 0, VT_LPSTR},
90 {"Keywords", PID_HDR_KEYWORDS, 0, VT_LPSTR},
91 {"Summary", PID_HDR_SUMMARY, 0, VT_LPSTR},
92 {"Approved", PID_HDR_APPROVED, 0, VT_LPSTR},
93 {"Lines", PID_HDR_LINES, 0, VT_LPSTR},
94 {"Xref", PID_HDR_XREF, 0, VT_LPSTR},
95 {"Organization", PID_HDR_ORG, 0, VT_LPSTR},
96 {"X-Newsreader", PID_HDR_XNEWSRDR, 0, VT_LPSTR},
97 {"X-Priority", PID_HDR_XPRI, 0, VT_LPSTR},
98 {"X-MSMail-Priority", PID_HDR_XMSPRI, 0, VT_LPSTR},
99 {"par:content-disposition:filename", PID_PAR_FILENAME, 0, VT_LPSTR},
100 {"par:content-type:boundary", PID_PAR_BOUNDARY, 0, VT_LPSTR},
101 {"par:content-type:charset", PID_PAR_CHARSET, 0, VT_LPSTR},
102 {"par:content-type:name", PID_PAR_NAME, 0, VT_LPSTR},
103 {"att:filename", PID_ATT_FILENAME, 0, VT_LPSTR},
104 {"att:pri-content-type", PID_ATT_PRITYPE, 0, VT_LPSTR},
105 {"att:sub-content-type", PID_ATT_SUBTYPE, 0, VT_LPSTR},
106 {"att:illegal-lines", PID_ATT_ILLEGAL, 0, VT_LPSTR},
107 {"att:rendered", PID_ATT_RENDERED, 0, VT_LPSTR},
108 {"att:sent-time", PID_ATT_SENTTIME, 0, VT_LPSTR},
109 {"att:priority", PID_ATT_PRIORITY, 0, VT_LPSTR},
110 {"Comment", PID_HDR_COMMENT, 0, VT_LPSTR},
111 {"Encoding", PID_HDR_ENCODING, 0, VT_LPSTR},
112 {"Encrypted", PID_HDR_ENCRYPTED, 0, VT_LPSTR},
113 {"X-Offsets", PID_HDR_OFFSETS, 0, VT_LPSTR},
114 {"X-Unsent", PID_HDR_XUNSENT, 0, VT_LPSTR},
115 {"X-ArticleId", PID_HDR_ARTICLEID, 0, VT_LPSTR},
116 {"Sender", PID_HDR_SENDER, MPF_ADDRESS, VT_LPSTR},
117 {"att:athena-server", PID_ATT_SERVER, 0, VT_LPSTR},
118 {"att:athena-account-id", PID_ATT_ACCOUNT, 0, VT_LPSTR},
119 {"att:athena-pop3-uidl", PID_ATT_UIDL, 0, VT_LPSTR},
120 {"att:athena-store-msgid", PID_ATT_STOREMSGID, 0, VT_LPSTR},
121 {"att:athena-user-name", PID_ATT_USERNAME, 0, VT_LPSTR},
122 {"att:athena-forward-to", PID_ATT_FORWARDTO, 0, VT_LPSTR},
123 {"att:athena-store-fdrid", PID_ATT_STOREFOLDERID,0, VT_LPSTR},
124 {"att:athena-ghosted", PID_ATT_GHOSTED, 0, VT_LPSTR},
125 {"att:athena-uncachedsize", PID_ATT_UNCACHEDSIZE, 0, VT_LPSTR},
126 {"att:athena-combined", PID_ATT_COMBINED, 0, VT_LPSTR},
127 {"att:auto-inlined", PID_ATT_AUTOINLINED, 0, VT_LPSTR},
128 {"Disposition-Notification-To", PID_HDR_DISP_NOTIFICATION_TO, 0, VT_LPSTR},
129 {"par:Content-Type:reply-type", PID_PAR_REPLYTYPE, 0, VT_LPSTR},
130 {"par:Content-Type:format", PID_PAR_FORMAT , 0, VT_LPSTR},
131 {"att:format", PID_ATT_FORMAT , 0, VT_LPSTR},
132 {"In-Reply-To", PID_HDR_INREPLYTO, 0, VT_LPSTR},
133 {"att:athena-account-name", PID_ATT_ACCOUNTNAME, 0, VT_LPSTR},
134 {NULL, 0, 0, 0}
137 typedef struct
139 struct list entry;
140 char *name;
141 char *value;
142 } param_t;
144 typedef struct
146 struct list entry;
147 const property_t *prop;
148 PROPVARIANT value;
149 struct list params;
150 } header_t;
152 typedef struct MimeBody
154 IMimeBody IMimeBody_iface;
155 LONG ref;
157 HBODY handle;
159 struct list headers;
160 struct list new_props; /* FIXME: This should be in a PropertySchema */
161 DWORD next_prop_id;
162 char *content_pri_type;
163 char *content_sub_type;
164 ENCODINGTYPE encoding;
165 void *data;
166 IID data_iid;
167 BODYOFFSETS body_offsets;
168 } MimeBody;
170 typedef struct
172 IStream IStream_iface;
173 LONG ref;
174 IStream *base;
175 ULARGE_INTEGER pos, start, length;
176 } sub_stream_t;
178 static inline sub_stream_t *impl_from_IStream(IStream *iface)
180 return CONTAINING_RECORD(iface, sub_stream_t, IStream_iface);
183 static HRESULT WINAPI sub_stream_QueryInterface(IStream *iface, REFIID riid, void **ppv)
185 sub_stream_t *This = impl_from_IStream(iface);
187 TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), ppv);
188 *ppv = NULL;
190 if(IsEqualIID(riid, &IID_IUnknown) ||
191 IsEqualIID(riid, &IID_ISequentialStream) ||
192 IsEqualIID(riid, &IID_IStream))
194 IStream_AddRef(iface);
195 *ppv = iface;
196 return S_OK;
198 return E_NOINTERFACE;
201 static ULONG WINAPI sub_stream_AddRef(IStream *iface)
203 sub_stream_t *This = impl_from_IStream(iface);
204 LONG ref = InterlockedIncrement(&This->ref);
206 TRACE("(%p) ref=%d\n", This, ref);
208 return ref;
211 static ULONG WINAPI sub_stream_Release(IStream *iface)
213 sub_stream_t *This = impl_from_IStream(iface);
214 LONG ref = InterlockedDecrement(&This->ref);
216 TRACE("(%p) ref=%d\n", This, ref);
218 if(!ref)
220 IStream_Release(This->base);
221 HeapFree(GetProcessHeap(), 0, This);
223 return ref;
226 static HRESULT WINAPI sub_stream_Read(
227 IStream* iface,
228 void *pv,
229 ULONG cb,
230 ULONG *pcbRead)
232 sub_stream_t *This = impl_from_IStream(iface);
233 HRESULT hr;
234 LARGE_INTEGER tmp_pos;
236 TRACE("(%p, %d, %p)\n", pv, cb, pcbRead);
238 tmp_pos.QuadPart = This->pos.QuadPart + This->start.QuadPart;
239 IStream_Seek(This->base, tmp_pos, STREAM_SEEK_SET, NULL);
241 if(This->pos.QuadPart + cb > This->length.QuadPart)
242 cb = This->length.QuadPart - This->pos.QuadPart;
244 hr = IStream_Read(This->base, pv, cb, pcbRead);
246 This->pos.QuadPart += *pcbRead;
248 return hr;
251 static HRESULT WINAPI sub_stream_Write(
252 IStream* iface,
253 const void *pv,
254 ULONG cb,
255 ULONG *pcbWritten)
257 FIXME("stub\n");
258 return E_NOTIMPL;
261 static HRESULT WINAPI sub_stream_Seek(
262 IStream* iface,
263 LARGE_INTEGER dlibMove,
264 DWORD dwOrigin,
265 ULARGE_INTEGER *plibNewPosition)
267 sub_stream_t *This = impl_from_IStream(iface);
268 LARGE_INTEGER new_pos;
270 TRACE("(%08x.%08x, %x, %p)\n", dlibMove.u.HighPart, dlibMove.u.LowPart, dwOrigin, plibNewPosition);
272 switch(dwOrigin)
274 case STREAM_SEEK_SET:
275 new_pos = dlibMove;
276 break;
277 case STREAM_SEEK_CUR:
278 new_pos.QuadPart = This->pos.QuadPart + dlibMove.QuadPart;
279 break;
280 case STREAM_SEEK_END:
281 new_pos.QuadPart = This->length.QuadPart + dlibMove.QuadPart;
282 break;
283 default:
284 return STG_E_INVALIDFUNCTION;
287 if(new_pos.QuadPart < 0) new_pos.QuadPart = 0;
288 else if(new_pos.QuadPart > This->length.QuadPart) new_pos.QuadPart = This->length.QuadPart;
290 This->pos.QuadPart = new_pos.QuadPart;
292 if(plibNewPosition) *plibNewPosition = This->pos;
293 return S_OK;
296 static HRESULT WINAPI sub_stream_SetSize(
297 IStream* iface,
298 ULARGE_INTEGER libNewSize)
300 FIXME("stub\n");
301 return E_NOTIMPL;
304 static HRESULT WINAPI sub_stream_CopyTo(
305 IStream* iface,
306 IStream *pstm,
307 ULARGE_INTEGER cb,
308 ULARGE_INTEGER *pcbRead,
309 ULARGE_INTEGER *pcbWritten)
311 HRESULT hr = S_OK;
312 BYTE tmpBuffer[128];
313 ULONG bytesRead, bytesWritten, copySize;
314 ULARGE_INTEGER totalBytesRead;
315 ULARGE_INTEGER totalBytesWritten;
317 TRACE("(%p)->(%p, %d, %p, %p)\n", iface, pstm, cb.u.LowPart, pcbRead, pcbWritten);
319 totalBytesRead.QuadPart = 0;
320 totalBytesWritten.QuadPart = 0;
322 while ( cb.QuadPart > 0 )
324 if ( cb.QuadPart >= sizeof(tmpBuffer) )
325 copySize = sizeof(tmpBuffer);
326 else
327 copySize = cb.u.LowPart;
329 hr = IStream_Read(iface, tmpBuffer, copySize, &bytesRead);
330 if (FAILED(hr)) break;
332 totalBytesRead.QuadPart += bytesRead;
334 if (bytesRead)
336 hr = IStream_Write(pstm, tmpBuffer, bytesRead, &bytesWritten);
337 if (FAILED(hr)) break;
338 totalBytesWritten.QuadPart += bytesWritten;
341 if (bytesRead != copySize)
342 cb.QuadPart = 0;
343 else
344 cb.QuadPart -= bytesRead;
347 if (pcbRead) pcbRead->QuadPart = totalBytesRead.QuadPart;
348 if (pcbWritten) pcbWritten->QuadPart = totalBytesWritten.QuadPart;
350 return hr;
353 static HRESULT WINAPI sub_stream_Commit(
354 IStream* iface,
355 DWORD grfCommitFlags)
357 FIXME("stub\n");
358 return E_NOTIMPL;
361 static HRESULT WINAPI sub_stream_Revert(
362 IStream* iface)
364 FIXME("stub\n");
365 return E_NOTIMPL;
368 static HRESULT WINAPI sub_stream_LockRegion(
369 IStream* iface,
370 ULARGE_INTEGER libOffset,
371 ULARGE_INTEGER cb,
372 DWORD dwLockType)
374 FIXME("stub\n");
375 return E_NOTIMPL;
378 static HRESULT WINAPI sub_stream_UnlockRegion(
379 IStream* iface,
380 ULARGE_INTEGER libOffset,
381 ULARGE_INTEGER cb,
382 DWORD dwLockType)
384 FIXME("stub\n");
385 return E_NOTIMPL;
388 static HRESULT WINAPI sub_stream_Stat(
389 IStream* iface,
390 STATSTG *pstatstg,
391 DWORD grfStatFlag)
393 sub_stream_t *This = impl_from_IStream(iface);
394 FIXME("(%p)->(%p, %08x)\n", This, pstatstg, grfStatFlag);
395 memset(pstatstg, 0, sizeof(*pstatstg));
396 pstatstg->cbSize = This->length;
397 return S_OK;
400 static HRESULT WINAPI sub_stream_Clone(
401 IStream* iface,
402 IStream **ppstm)
404 FIXME("stub\n");
405 return E_NOTIMPL;
408 static struct IStreamVtbl sub_stream_vtbl =
410 sub_stream_QueryInterface,
411 sub_stream_AddRef,
412 sub_stream_Release,
413 sub_stream_Read,
414 sub_stream_Write,
415 sub_stream_Seek,
416 sub_stream_SetSize,
417 sub_stream_CopyTo,
418 sub_stream_Commit,
419 sub_stream_Revert,
420 sub_stream_LockRegion,
421 sub_stream_UnlockRegion,
422 sub_stream_Stat,
423 sub_stream_Clone
426 static HRESULT create_sub_stream(IStream *stream, ULARGE_INTEGER start, ULARGE_INTEGER length, IStream **out)
428 sub_stream_t *This;
430 *out = NULL;
431 This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
432 if(!This) return E_OUTOFMEMORY;
434 This->IStream_iface.lpVtbl = &sub_stream_vtbl;
435 This->ref = 1;
436 This->start = start;
437 This->length = length;
438 This->pos.QuadPart = 0;
439 IStream_AddRef(stream);
440 This->base = stream;
442 *out = &This->IStream_iface;
443 return S_OK;
446 static HRESULT get_stream_size(IStream *stream, ULARGE_INTEGER *size)
448 STATSTG statstg = {NULL};
449 LARGE_INTEGER zero;
450 HRESULT hres;
452 hres = IStream_Stat(stream, &statstg, STATFLAG_NONAME);
453 if(SUCCEEDED(hres)) {
454 *size = statstg.cbSize;
455 return S_OK;
458 zero.QuadPart = 0;
459 return IStream_Seek(stream, zero, STREAM_SEEK_END, size);
462 static inline MimeBody *impl_from_IMimeBody(IMimeBody *iface)
464 return CONTAINING_RECORD(iface, MimeBody, IMimeBody_iface);
467 typedef struct propschema
469 IMimePropertySchema IMimePropertySchema_iface;
470 LONG ref;
471 } propschema;
473 static inline propschema *impl_from_IMimePropertySchema(IMimePropertySchema *iface)
475 return CONTAINING_RECORD(iface, propschema, IMimePropertySchema_iface);
478 static LPSTR strdupA(LPCSTR str)
480 char *ret;
481 int len = strlen(str);
482 ret = HeapAlloc(GetProcessHeap(), 0, len + 1);
483 memcpy(ret, str, len + 1);
484 return ret;
487 #define PARSER_BUF_SIZE 1024
489 /*****************************************************
490 * copy_headers_to_buf [internal]
492 * Copies the headers into a '\0' terminated memory block and leave
493 * the stream's current position set to after the blank line.
495 static HRESULT copy_headers_to_buf(IStream *stm, char **ptr)
497 char *buf = NULL;
498 DWORD size = PARSER_BUF_SIZE, offset = 0, last_end = 0;
499 HRESULT hr;
500 BOOL done = FALSE;
502 *ptr = NULL;
506 char *end;
507 DWORD read;
509 if(!buf)
510 buf = HeapAlloc(GetProcessHeap(), 0, size + 1);
511 else
513 size *= 2;
514 buf = HeapReAlloc(GetProcessHeap(), 0, buf, size + 1);
516 if(!buf)
518 hr = E_OUTOFMEMORY;
519 goto fail;
522 hr = IStream_Read(stm, buf + offset, size - offset, &read);
523 if(FAILED(hr)) goto fail;
525 offset += read;
526 buf[offset] = '\0';
528 if(read == 0) done = TRUE;
530 while(!done && (end = strstr(buf + last_end, "\r\n")))
532 DWORD new_end = end - buf + 2;
533 if(new_end - last_end == 2)
535 LARGE_INTEGER off;
536 off.QuadPart = (LONGLONG)new_end - offset;
537 IStream_Seek(stm, off, STREAM_SEEK_CUR, NULL);
538 buf[new_end] = '\0';
539 done = TRUE;
541 else
542 last_end = new_end;
544 } while(!done);
546 *ptr = buf;
547 return S_OK;
549 fail:
550 HeapFree(GetProcessHeap(), 0, buf);
551 return hr;
554 static header_t *read_prop(MimeBody *body, char **ptr)
556 char *colon = strchr(*ptr, ':');
557 const property_t *prop;
558 header_t *ret;
560 if(!colon) return NULL;
562 *colon = '\0';
564 for(prop = default_props; prop->name; prop++)
566 if(!lstrcmpiA(*ptr, prop->name))
568 TRACE("%s: found match with default property id %d\n", *ptr, prop->id);
569 break;
573 if(!prop->name)
575 property_list_entry_t *prop_entry;
576 LIST_FOR_EACH_ENTRY(prop_entry, &body->new_props, property_list_entry_t, entry)
578 if(!lstrcmpiA(*ptr, prop_entry->prop.name))
580 TRACE("%s: found match with already added new property id %d\n", *ptr, prop_entry->prop.id);
581 prop = &prop_entry->prop;
582 break;
585 if(!prop->name)
587 prop_entry = HeapAlloc(GetProcessHeap(), 0, sizeof(*prop_entry));
588 prop_entry->prop.name = strdupA(*ptr);
589 prop_entry->prop.id = body->next_prop_id++;
590 prop_entry->prop.flags = 0;
591 prop_entry->prop.default_vt = VT_LPSTR;
592 list_add_tail(&body->new_props, &prop_entry->entry);
593 prop = &prop_entry->prop;
594 TRACE("%s: allocating new prop id %d\n", *ptr, prop_entry->prop.id);
598 ret = HeapAlloc(GetProcessHeap(), 0, sizeof(*ret));
599 ret->prop = prop;
600 PropVariantInit(&ret->value);
601 list_init(&ret->params);
602 *ptr = colon + 1;
604 return ret;
607 static void unfold_header(char *header, int len)
609 char *start = header, *cp = header;
611 do {
612 while(*cp == ' ' || *cp == '\t')
614 cp++;
615 len--;
617 if(cp != start)
618 memmove(start, cp, len + 1);
620 cp = strstr(start, "\r\n");
621 len -= (cp - start);
622 start = cp;
623 *start = ' ';
624 start++;
625 len--;
626 cp += 2;
627 } while(*cp == ' ' || *cp == '\t');
629 *(start - 1) = '\0';
632 static char *unquote_string(const char *str)
634 BOOL quoted = FALSE;
635 char *ret, *cp;
637 while(*str == ' ' || *str == '\t') str++;
639 if(*str == '"')
641 quoted = TRUE;
642 str++;
644 ret = strdupA(str);
645 for(cp = ret; *cp; cp++)
647 if(*cp == '\\')
648 memmove(cp, cp + 1, strlen(cp + 1) + 1);
649 else if(*cp == '"')
651 if(!quoted)
653 WARN("quote in unquoted string\n");
655 else
657 *cp = '\0';
658 break;
662 return ret;
665 static void add_param(header_t *header, const char *p)
667 const char *key = p, *value, *cp = p;
668 param_t *param;
669 char *name;
671 TRACE("got param %s\n", p);
673 while (*key == ' ' || *key == '\t' ) key++;
675 cp = strchr(key, '=');
676 if(!cp)
678 WARN("malformed parameter - skipping\n");
679 return;
682 name = HeapAlloc(GetProcessHeap(), 0, cp - key + 1);
683 memcpy(name, key, cp - key);
684 name[cp - key] = '\0';
686 value = cp + 1;
688 param = HeapAlloc(GetProcessHeap(), 0, sizeof(*param));
689 param->name = name;
690 param->value = unquote_string(value);
691 list_add_tail(&header->params, &param->entry);
694 static void split_params(header_t *header, char *value)
696 char *cp = value, *start = value;
697 BOOL in_quotes = FALSE, done_value = FALSE;
699 while(*cp)
701 if(!in_quotes && *cp == ';')
703 *cp = '\0';
704 if(done_value) add_param(header, start);
705 done_value = TRUE;
706 start = cp + 1;
708 else if(*cp == '"')
709 in_quotes = !in_quotes;
710 cp++;
712 if(done_value) add_param(header, start);
715 static void read_value(header_t *header, char **cur)
717 char *end = *cur, *value;
718 DWORD len;
720 do {
721 end = strstr(end, "\r\n");
722 end += 2;
723 } while(*end == ' ' || *end == '\t');
725 len = end - *cur;
726 value = HeapAlloc(GetProcessHeap(), 0, len + 1);
727 memcpy(value, *cur, len);
728 value[len] = '\0';
730 unfold_header(value, len);
731 TRACE("value %s\n", debugstr_a(value));
733 if(header->prop->flags & MPF_HASPARAMS)
735 split_params(header, value);
736 TRACE("value w/o params %s\n", debugstr_a(value));
739 header->value.vt = VT_LPSTR;
740 header->value.u.pszVal = value;
742 *cur = end;
745 static void init_content_type(MimeBody *body, header_t *header)
747 char *slash;
748 DWORD len;
750 slash = strchr(header->value.u.pszVal, '/');
751 if(!slash)
753 WARN("malformed context type value\n");
754 return;
756 len = slash - header->value.u.pszVal;
757 body->content_pri_type = HeapAlloc(GetProcessHeap(), 0, len + 1);
758 memcpy(body->content_pri_type, header->value.u.pszVal, len);
759 body->content_pri_type[len] = '\0';
760 body->content_sub_type = strdupA(slash + 1);
763 static void init_content_encoding(MimeBody *body, header_t *header)
765 const char *encoding = header->value.u.pszVal;
767 if(!strcasecmp(encoding, "base64"))
768 body->encoding = IET_BASE64;
769 else if(!strcasecmp(encoding, "quoted-printable"))
770 body->encoding = IET_QP;
771 else if(!strcasecmp(encoding, "7bit"))
772 body->encoding = IET_7BIT;
773 else if(!strcasecmp(encoding, "8bit"))
774 body->encoding = IET_8BIT;
775 else
776 FIXME("unknown encoding %s\n", debugstr_a(encoding));
779 static HRESULT parse_headers(MimeBody *body, IStream *stm)
781 char *header_buf, *cur_header_ptr;
782 HRESULT hr;
783 header_t *header;
785 hr = copy_headers_to_buf(stm, &header_buf);
786 if(FAILED(hr)) return hr;
788 cur_header_ptr = header_buf;
789 while((header = read_prop(body, &cur_header_ptr)))
791 read_value(header, &cur_header_ptr);
792 list_add_tail(&body->headers, &header->entry);
794 switch(header->prop->id) {
795 case PID_HDR_CNTTYPE:
796 init_content_type(body, header);
797 break;
798 case PID_HDR_CNTXFER:
799 init_content_encoding(body, header);
800 break;
804 HeapFree(GetProcessHeap(), 0, header_buf);
805 return hr;
808 static void empty_param_list(struct list *list)
810 param_t *param, *cursor2;
812 LIST_FOR_EACH_ENTRY_SAFE(param, cursor2, list, param_t, entry)
814 list_remove(&param->entry);
815 HeapFree(GetProcessHeap(), 0, param->name);
816 HeapFree(GetProcessHeap(), 0, param->value);
817 HeapFree(GetProcessHeap(), 0, param);
821 static void empty_header_list(struct list *list)
823 header_t *header, *cursor2;
825 LIST_FOR_EACH_ENTRY_SAFE(header, cursor2, list, header_t, entry)
827 list_remove(&header->entry);
828 PropVariantClear(&header->value);
829 empty_param_list(&header->params);
830 HeapFree(GetProcessHeap(), 0, header);
834 static void empty_new_prop_list(struct list *list)
836 property_list_entry_t *prop, *cursor2;
838 LIST_FOR_EACH_ENTRY_SAFE(prop, cursor2, list, property_list_entry_t, entry)
840 list_remove(&prop->entry);
841 HeapFree(GetProcessHeap(), 0, (char *)prop->prop.name);
842 HeapFree(GetProcessHeap(), 0, prop);
846 static void release_data(REFIID riid, void *data)
848 if(!data) return;
850 if(IsEqualIID(riid, &IID_IStream))
851 IStream_Release((IStream *)data);
852 else
853 FIXME("Unhandled data format %s\n", debugstr_guid(riid));
856 static HRESULT find_prop(MimeBody *body, const char *name, header_t **prop)
858 header_t *header;
860 *prop = NULL;
862 LIST_FOR_EACH_ENTRY(header, &body->headers, header_t, entry)
864 if(ISPIDSTR(name))
866 if(STRTOPID(name) == header->prop->id)
868 *prop = header;
869 return S_OK;
872 else if(!lstrcmpiA(name, header->prop->name))
874 *prop = header;
875 return S_OK;
879 return MIME_E_NOT_FOUND;
882 static const property_t *find_default_prop(const char *name)
884 const property_t *prop_def = NULL;
886 for(prop_def = default_props; prop_def->name; prop_def++)
888 if(ISPIDSTR(name))
890 if(STRTOPID(name) == prop_def->id)
892 break;
895 else if(!lstrcmpiA(name, prop_def->name))
897 break;
901 if(prop_def->id)
902 TRACE("%s: found match with default property id %d\n", prop_def->name, prop_def->id);
903 else
904 prop_def = NULL;
906 return prop_def;
909 static HRESULT WINAPI MimeBody_QueryInterface(IMimeBody* iface,
910 REFIID riid,
911 void** ppvObject)
913 TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppvObject);
915 *ppvObject = NULL;
917 if (IsEqualIID(riid, &IID_IUnknown) ||
918 IsEqualIID(riid, &IID_IPersist) ||
919 IsEqualIID(riid, &IID_IPersistStreamInit) ||
920 IsEqualIID(riid, &IID_IMimePropertySet) ||
921 IsEqualIID(riid, &IID_IMimeBody))
923 *ppvObject = iface;
926 if(*ppvObject)
928 IUnknown_AddRef((IUnknown*)*ppvObject);
929 return S_OK;
932 FIXME("no interface for %s\n", debugstr_guid(riid));
933 return E_NOINTERFACE;
936 static ULONG WINAPI MimeBody_AddRef(IMimeBody *iface)
938 MimeBody *This = impl_from_IMimeBody(iface);
939 LONG ref = InterlockedIncrement(&This->ref);
941 TRACE("(%p) ref=%d\n", This, ref);
943 return ref;
946 static ULONG WINAPI MimeBody_Release(IMimeBody *iface)
948 MimeBody *This = impl_from_IMimeBody(iface);
949 LONG ref = InterlockedDecrement(&This->ref);
951 TRACE("(%p) ref=%d\n", This, ref);
953 if (!ref)
955 empty_header_list(&This->headers);
956 empty_new_prop_list(&This->new_props);
958 HeapFree(GetProcessHeap(), 0, This->content_pri_type);
959 HeapFree(GetProcessHeap(), 0, This->content_sub_type);
961 release_data(&This->data_iid, This->data);
963 HeapFree(GetProcessHeap(), 0, This);
966 return ref;
969 static HRESULT WINAPI MimeBody_GetClassID(
970 IMimeBody* iface,
971 CLSID* pClassID)
973 MimeBody *This = impl_from_IMimeBody(iface);
975 TRACE("(%p)->(%p)\n", This, pClassID);
977 if(!pClassID)
978 return E_INVALIDARG;
980 *pClassID = IID_IMimeBody;
981 return S_OK;
984 static HRESULT WINAPI MimeBody_IsDirty(
985 IMimeBody* iface)
987 MimeBody *This = impl_from_IMimeBody(iface);
988 FIXME("(%p)->() stub\n", This);
989 return E_NOTIMPL;
992 static HRESULT WINAPI MimeBody_Load(IMimeBody *iface, IStream *pStm)
994 MimeBody *This = impl_from_IMimeBody(iface);
995 TRACE("(%p)->(%p)\n", This, pStm);
996 return parse_headers(This, pStm);
999 static HRESULT WINAPI MimeBody_Save(IMimeBody *iface, IStream *pStm, BOOL fClearDirty)
1001 MimeBody *This = impl_from_IMimeBody(iface);
1002 FIXME("(%p)->(%p, %d)\n", This, pStm, fClearDirty);
1003 return E_NOTIMPL;
1006 static HRESULT WINAPI MimeBody_GetSizeMax(
1007 IMimeBody* iface,
1008 ULARGE_INTEGER* pcbSize)
1010 MimeBody *This = impl_from_IMimeBody(iface);
1011 FIXME("(%p)->(%p) stub\n", This, pcbSize);
1012 return E_NOTIMPL;
1015 static HRESULT WINAPI MimeBody_InitNew(
1016 IMimeBody* iface)
1018 MimeBody *This = impl_from_IMimeBody(iface);
1019 TRACE("(%p)->()\n", This);
1020 return S_OK;
1023 static HRESULT WINAPI MimeBody_GetPropInfo(
1024 IMimeBody* iface,
1025 LPCSTR pszName,
1026 LPMIMEPROPINFO pInfo)
1028 MimeBody *This = impl_from_IMimeBody(iface);
1029 header_t *header;
1030 HRESULT hr;
1031 DWORD supported = PIM_PROPID | PIM_VTDEFAULT;
1033 TRACE("(%p)->(%s, %p) semi-stub\n", This, debugstr_a(pszName), pInfo);
1035 if(!pszName || !pInfo)
1036 return E_INVALIDARG;
1038 TRACE("mask 0x%04x\n", pInfo->dwMask);
1040 if(pInfo->dwMask & ~supported)
1041 FIXME("Unsupported mask flags 0x%04x\n", pInfo->dwMask & ~supported);
1043 hr = find_prop(This, pszName, &header);
1044 if(hr == S_OK)
1046 if(pInfo->dwMask & PIM_CHARSET)
1047 pInfo->hCharset = 0;
1048 if(pInfo->dwMask & PIM_FLAGS)
1049 pInfo->dwFlags = 0x00000000;
1050 if(pInfo->dwMask & PIM_ROWNUMBER)
1051 pInfo->dwRowNumber = 0;
1052 if(pInfo->dwMask & PIM_ENCODINGTYPE)
1053 pInfo->ietEncoding = 0;
1054 if(pInfo->dwMask & PIM_VALUES)
1055 pInfo->cValues = 0;
1056 if(pInfo->dwMask & PIM_PROPID)
1057 pInfo->dwPropId = header->prop->id;
1058 if(pInfo->dwMask & PIM_VTDEFAULT)
1059 pInfo->vtDefault = header->prop->default_vt;
1060 if(pInfo->dwMask & PIM_VTCURRENT)
1061 pInfo->vtCurrent = 0;
1064 return hr;
1067 static HRESULT WINAPI MimeBody_SetPropInfo(
1068 IMimeBody* iface,
1069 LPCSTR pszName,
1070 LPCMIMEPROPINFO pInfo)
1072 MimeBody *This = impl_from_IMimeBody(iface);
1073 FIXME("(%p)->(%s, %p) stub\n", This, debugstr_a(pszName), pInfo);
1074 return E_NOTIMPL;
1077 static HRESULT WINAPI MimeBody_GetProp(
1078 IMimeBody* iface,
1079 LPCSTR pszName,
1080 DWORD dwFlags,
1081 LPPROPVARIANT pValue)
1083 MimeBody *This = impl_from_IMimeBody(iface);
1084 header_t *header;
1085 HRESULT hr;
1087 TRACE("(%p)->(%s, 0x%x, %p)\n", This, debugstr_a(pszName), dwFlags, pValue);
1089 if(!pszName || !pValue)
1090 return E_INVALIDARG;
1092 if(!ISPIDSTR(pszName) && !lstrcmpiA(pszName, "att:pri-content-type"))
1094 PropVariantClear(pValue);
1095 pValue->vt = VT_LPSTR;
1096 pValue->u.pszVal = strdupA(This->content_pri_type);
1097 return S_OK;
1100 hr = find_prop(This, pszName, &header);
1101 if(hr == S_OK)
1103 TRACE("type %d->%d\n", header->value.vt, pValue->vt);
1105 hr = PropVariantChangeType(pValue, &header->value, 0, pValue->vt);
1106 if(FAILED(hr))
1107 FIXME("Conversion not currently supported (%d->%d)\n", header->value.vt, pValue->vt);
1110 return hr;
1113 static HRESULT WINAPI MimeBody_SetProp(
1114 IMimeBody* iface,
1115 LPCSTR pszName,
1116 DWORD dwFlags,
1117 LPCPROPVARIANT pValue)
1119 MimeBody *This = impl_from_IMimeBody(iface);
1120 header_t *header;
1121 HRESULT hr;
1123 TRACE("(%p)->(%s, 0x%x, %p)\n", This, debugstr_a(pszName), dwFlags, pValue);
1125 if(!pszName || !pValue)
1126 return E_INVALIDARG;
1128 hr = find_prop(This, pszName, &header);
1129 if(hr != S_OK)
1131 property_list_entry_t *prop_entry;
1132 const property_t *prop = NULL;
1134 LIST_FOR_EACH_ENTRY(prop_entry, &This->new_props, property_list_entry_t, entry)
1136 if(ISPIDSTR(pszName))
1138 if(STRTOPID(pszName) == prop_entry->prop.id)
1140 TRACE("Found match with already added new property id %d\n", prop_entry->prop.id);
1141 prop = &prop_entry->prop;
1142 break;
1145 else if(!lstrcmpiA(pszName, prop_entry->prop.name))
1147 TRACE("Found match with already added new property id %d\n", prop_entry->prop.id);
1148 prop = &prop_entry->prop;
1149 break;
1153 header = HeapAlloc(GetProcessHeap(), 0, sizeof(*header));
1154 if(!header)
1155 return E_OUTOFMEMORY;
1157 if(!prop)
1159 const property_t *prop_def = NULL;
1160 prop_entry = HeapAlloc(GetProcessHeap(), 0, sizeof(*prop_entry));
1161 if(!prop_entry)
1163 HeapFree(GetProcessHeap(), 0, header);
1164 return E_OUTOFMEMORY;
1167 prop_def = find_default_prop(pszName);
1168 if(prop_def)
1170 prop_entry->prop.name = strdupA(prop_def->name);
1171 prop_entry->prop.id = prop_def->id;
1173 else
1175 if(ISPIDSTR(pszName))
1177 HeapFree(GetProcessHeap(), 0, prop_entry);
1178 HeapFree(GetProcessHeap(), 0, header);
1179 return MIME_E_NOT_FOUND;
1182 prop_entry->prop.name = strdupA(pszName);
1183 prop_entry->prop.id = This->next_prop_id++;
1186 prop_entry->prop.flags = 0;
1187 prop_entry->prop.default_vt = pValue->vt;
1188 list_add_tail(&This->new_props, &prop_entry->entry);
1189 prop = &prop_entry->prop;
1190 TRACE("Allocating new prop id %d\n", prop_entry->prop.id);
1193 header->prop = prop;
1194 PropVariantInit(&header->value);
1195 list_init(&header->params);
1196 list_add_tail(&This->headers, &header->entry);
1199 PropVariantCopy(&header->value, pValue);
1201 return S_OK;
1204 static HRESULT WINAPI MimeBody_AppendProp(
1205 IMimeBody* iface,
1206 LPCSTR pszName,
1207 DWORD dwFlags,
1208 LPPROPVARIANT pValue)
1210 MimeBody *This = impl_from_IMimeBody(iface);
1211 FIXME("(%p)->(%s, 0x%x, %p) stub\n", This, debugstr_a(pszName), dwFlags, pValue);
1212 return E_NOTIMPL;
1215 static HRESULT WINAPI MimeBody_DeleteProp(
1216 IMimeBody* iface,
1217 LPCSTR pszName)
1219 MimeBody *This = impl_from_IMimeBody(iface);
1220 header_t *cursor;
1221 BOOL found;
1223 TRACE("(%p)->(%s) stub\n", This, debugstr_a(pszName));
1225 LIST_FOR_EACH_ENTRY(cursor, &This->headers, header_t, entry)
1227 if(ISPIDSTR(pszName))
1228 found = STRTOPID(pszName) == cursor->prop->id;
1229 else
1230 found = !lstrcmpiA(pszName, cursor->prop->name);
1232 if(found)
1234 list_remove(&cursor->entry);
1235 HeapFree(GetProcessHeap(), 0, cursor);
1236 return S_OK;
1240 return MIME_E_NOT_FOUND;
1243 static HRESULT WINAPI MimeBody_CopyProps(
1244 IMimeBody* iface,
1245 ULONG cNames,
1246 LPCSTR* prgszName,
1247 IMimePropertySet* pPropertySet)
1249 MimeBody *This = impl_from_IMimeBody(iface);
1250 FIXME("(%p)->(%d, %p, %p) stub\n", This, cNames, prgszName, pPropertySet);
1251 return E_NOTIMPL;
1254 static HRESULT WINAPI MimeBody_MoveProps(
1255 IMimeBody* iface,
1256 ULONG cNames,
1257 LPCSTR* prgszName,
1258 IMimePropertySet* pPropertySet)
1260 MimeBody *This = impl_from_IMimeBody(iface);
1261 FIXME("(%p)->(%d, %p, %p) stub\n", This, cNames, prgszName, pPropertySet);
1262 return E_NOTIMPL;
1265 static HRESULT WINAPI MimeBody_DeleteExcept(
1266 IMimeBody* iface,
1267 ULONG cNames,
1268 LPCSTR* prgszName)
1270 MimeBody *This = impl_from_IMimeBody(iface);
1271 FIXME("(%p)->(%d, %p) stub\n", This, cNames, prgszName);
1272 return E_NOTIMPL;
1275 static HRESULT WINAPI MimeBody_QueryProp(
1276 IMimeBody* iface,
1277 LPCSTR pszName,
1278 LPCSTR pszCriteria,
1279 boolean fSubString,
1280 boolean fCaseSensitive)
1282 MimeBody *This = impl_from_IMimeBody(iface);
1283 FIXME("(%p)->(%s, %s, %d, %d) stub\n", This, debugstr_a(pszName), debugstr_a(pszCriteria), fSubString, fCaseSensitive);
1284 return E_NOTIMPL;
1287 static HRESULT WINAPI MimeBody_GetCharset(
1288 IMimeBody* iface,
1289 LPHCHARSET phCharset)
1291 MimeBody *This = impl_from_IMimeBody(iface);
1292 FIXME("(%p)->(%p) stub\n", This, phCharset);
1293 *phCharset = NULL;
1294 return S_OK;
1297 static HRESULT WINAPI MimeBody_SetCharset(
1298 IMimeBody* iface,
1299 HCHARSET hCharset,
1300 CSETAPPLYTYPE applytype)
1302 MimeBody *This = impl_from_IMimeBody(iface);
1303 FIXME("(%p)->(%p, %d) stub\n", This, hCharset, applytype);
1304 return E_NOTIMPL;
1307 static HRESULT WINAPI MimeBody_GetParameters(
1308 IMimeBody* iface,
1309 LPCSTR pszName,
1310 ULONG* pcParams,
1311 LPMIMEPARAMINFO* pprgParam)
1313 MimeBody *This = impl_from_IMimeBody(iface);
1314 HRESULT hr;
1315 header_t *header;
1317 TRACE("(%p)->(%s, %p, %p)\n", iface, debugstr_a(pszName), pcParams, pprgParam);
1319 *pprgParam = NULL;
1320 *pcParams = 0;
1322 hr = find_prop(This, pszName, &header);
1323 if(hr != S_OK) return hr;
1325 *pcParams = list_count(&header->params);
1326 if(*pcParams)
1328 IMimeAllocator *alloc;
1329 param_t *param;
1330 MIMEPARAMINFO *info;
1332 MimeOleGetAllocator(&alloc);
1334 *pprgParam = info = IMimeAllocator_Alloc(alloc, *pcParams * sizeof(**pprgParam));
1335 LIST_FOR_EACH_ENTRY(param, &header->params, param_t, entry)
1337 int len;
1339 len = strlen(param->name) + 1;
1340 info->pszName = IMimeAllocator_Alloc(alloc, len);
1341 memcpy(info->pszName, param->name, len);
1342 len = strlen(param->value) + 1;
1343 info->pszData = IMimeAllocator_Alloc(alloc, len);
1344 memcpy(info->pszData, param->value, len);
1345 info++;
1347 IMimeAllocator_Release(alloc);
1349 return S_OK;
1352 static HRESULT WINAPI MimeBody_IsContentType(
1353 IMimeBody* iface,
1354 LPCSTR pszPriType,
1355 LPCSTR pszSubType)
1357 MimeBody *This = impl_from_IMimeBody(iface);
1359 TRACE("(%p)->(%s, %s)\n", This, debugstr_a(pszPriType), debugstr_a(pszSubType));
1360 if(pszPriType)
1362 const char *pri = This->content_pri_type;
1363 if(!pri) pri = "text";
1364 if(lstrcmpiA(pri, pszPriType)) return S_FALSE;
1367 if(pszSubType)
1369 const char *sub = This->content_sub_type;
1370 if(!sub) sub = "plain";
1371 if(lstrcmpiA(sub, pszSubType)) return S_FALSE;
1374 return S_OK;
1377 static HRESULT WINAPI MimeBody_BindToObject(
1378 IMimeBody* iface,
1379 REFIID riid,
1380 void** ppvObject)
1382 MimeBody *This = impl_from_IMimeBody(iface);
1383 FIXME("(%p)->(%s, %p) stub\n", This, debugstr_guid(riid), ppvObject);
1384 return E_NOTIMPL;
1387 static HRESULT WINAPI MimeBody_Clone(
1388 IMimeBody* iface,
1389 IMimePropertySet** ppPropertySet)
1391 MimeBody *This = impl_from_IMimeBody(iface);
1392 FIXME("(%p)->(%p) stub\n", This, ppPropertySet);
1393 return E_NOTIMPL;
1396 static HRESULT WINAPI MimeBody_SetOption(
1397 IMimeBody* iface,
1398 const TYPEDID oid,
1399 LPCPROPVARIANT pValue)
1401 MimeBody *This = impl_from_IMimeBody(iface);
1402 HRESULT hr = E_NOTIMPL;
1403 TRACE("(%p)->(%08x, %p)\n", This, oid, pValue);
1405 if(pValue->vt != TYPEDID_TYPE(oid))
1407 WARN("Called with vartype %04x and oid %08x\n", pValue->vt, oid);
1408 return E_INVALIDARG;
1411 switch(oid)
1413 case OID_SECURITY_HWND_OWNER:
1414 FIXME("OID_SECURITY_HWND_OWNER (value %08x): ignoring\n", pValue->u.ulVal);
1415 hr = S_OK;
1416 break;
1417 case OID_TRANSMIT_BODY_ENCODING:
1418 FIXME("OID_TRANSMIT_BODY_ENCODING (value %08x): ignoring\n", pValue->u.ulVal);
1419 hr = S_OK;
1420 break;
1421 default:
1422 FIXME("Unhandled oid %08x\n", oid);
1425 return hr;
1428 static HRESULT WINAPI MimeBody_GetOption(
1429 IMimeBody* iface,
1430 const TYPEDID oid,
1431 LPPROPVARIANT pValue)
1433 MimeBody *This = impl_from_IMimeBody(iface);
1434 FIXME("(%p)->(%08x, %p): stub\n", This, oid, pValue);
1435 return E_NOTIMPL;
1438 static HRESULT WINAPI MimeBody_EnumProps(
1439 IMimeBody* iface,
1440 DWORD dwFlags,
1441 IMimeEnumProperties** ppEnum)
1443 MimeBody *This = impl_from_IMimeBody(iface);
1444 FIXME("(%p)->(0x%x, %p) stub\n", This, dwFlags, ppEnum);
1445 return E_NOTIMPL;
1448 static HRESULT WINAPI MimeBody_IsType(
1449 IMimeBody* iface,
1450 IMSGBODYTYPE bodytype)
1452 MimeBody *This = impl_from_IMimeBody(iface);
1454 TRACE("(%p)->(%d)\n", This, bodytype);
1455 switch(bodytype)
1457 case IBT_EMPTY:
1458 return This->data ? S_FALSE : S_OK;
1459 default:
1460 FIXME("Unimplemented bodytype %d - returning S_OK\n", bodytype);
1462 return S_OK;
1465 static HRESULT WINAPI MimeBody_SetDisplayName(
1466 IMimeBody* iface,
1467 LPCSTR pszDisplay)
1469 MimeBody *This = impl_from_IMimeBody(iface);
1470 FIXME("(%p)->(%s) stub\n", This, debugstr_a(pszDisplay));
1471 return E_NOTIMPL;
1474 static HRESULT WINAPI MimeBody_GetDisplayName(
1475 IMimeBody* iface,
1476 LPSTR* ppszDisplay)
1478 MimeBody *This = impl_from_IMimeBody(iface);
1479 FIXME("(%p)->(%p) stub\n", This, ppszDisplay);
1480 return E_NOTIMPL;
1483 static HRESULT WINAPI MimeBody_GetOffsets(
1484 IMimeBody* iface,
1485 LPBODYOFFSETS pOffsets)
1487 MimeBody *This = impl_from_IMimeBody(iface);
1488 TRACE("(%p)->(%p)\n", This, pOffsets);
1490 *pOffsets = This->body_offsets;
1492 if(This->body_offsets.cbBodyEnd == 0) return MIME_E_NO_DATA;
1493 return S_OK;
1496 static HRESULT WINAPI MimeBody_GetCurrentEncoding(
1497 IMimeBody* iface,
1498 ENCODINGTYPE* pietEncoding)
1500 MimeBody *This = impl_from_IMimeBody(iface);
1502 TRACE("(%p)->(%p)\n", This, pietEncoding);
1504 *pietEncoding = This->encoding;
1505 return S_OK;
1508 static HRESULT WINAPI MimeBody_SetCurrentEncoding(
1509 IMimeBody* iface,
1510 ENCODINGTYPE ietEncoding)
1512 MimeBody *This = impl_from_IMimeBody(iface);
1514 TRACE("(%p)->(%d)\n", This, ietEncoding);
1516 This->encoding = ietEncoding;
1517 return S_OK;
1520 static HRESULT WINAPI MimeBody_GetEstimatedSize(
1521 IMimeBody* iface,
1522 ENCODINGTYPE ietEncoding,
1523 ULONG* pcbSize)
1525 MimeBody *This = impl_from_IMimeBody(iface);
1526 FIXME("(%p)->(%d, %p) stub\n", This, ietEncoding, pcbSize);
1527 return E_NOTIMPL;
1530 static HRESULT WINAPI MimeBody_GetDataHere(
1531 IMimeBody* iface,
1532 ENCODINGTYPE ietEncoding,
1533 IStream* pStream)
1535 MimeBody *This = impl_from_IMimeBody(iface);
1536 FIXME("(%p)->(%d, %p) stub\n", This, ietEncoding, pStream);
1537 return E_NOTIMPL;
1540 static const signed char base64_decode_table[] =
1542 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x00 */
1543 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x10 */
1544 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, /* 0x20 */
1545 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, /* 0x30 */
1546 -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, /* 0x40 */
1547 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, /* 0x50 */
1548 -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, /* 0x60 */
1549 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1 /* 0x70 */
1552 static HRESULT decode_base64(IStream *input, IStream **ret_stream)
1554 const unsigned char *ptr, *end;
1555 unsigned char buf[1024];
1556 LARGE_INTEGER pos;
1557 unsigned char *ret;
1558 unsigned char in[4];
1559 IStream *output;
1560 DWORD size;
1561 int n = 0;
1562 HRESULT hres;
1564 pos.QuadPart = 0;
1565 hres = IStream_Seek(input, pos, STREAM_SEEK_SET, NULL);
1566 if(FAILED(hres))
1567 return hres;
1569 hres = CreateStreamOnHGlobal(NULL, TRUE, &output);
1570 if(FAILED(hres))
1571 return hres;
1573 while(1) {
1574 hres = IStream_Read(input, buf, sizeof(buf), &size);
1575 if(FAILED(hres) || !size)
1576 break;
1578 ptr = ret = buf;
1579 end = buf + size;
1581 while(1) {
1582 /* skip invalid chars */
1583 while(ptr < end &&
1584 (*ptr >= sizeof(base64_decode_table)/sizeof(*base64_decode_table)
1585 || base64_decode_table[*ptr] == -1))
1586 ptr++;
1587 if(ptr == end)
1588 break;
1590 in[n++] = base64_decode_table[*ptr++];
1591 switch(n) {
1592 case 2:
1593 *ret++ = in[0] << 2 | in[1] >> 4;
1594 continue;
1595 case 3:
1596 *ret++ = in[1] << 4 | in[2] >> 2;
1597 continue;
1598 case 4:
1599 *ret++ = ((in[2] << 6) & 0xc0) | in[3];
1600 n = 0;
1604 if(ret > buf) {
1605 hres = IStream_Write(output, buf, ret - buf, NULL);
1606 if(FAILED(hres))
1607 break;
1611 if(SUCCEEDED(hres))
1612 hres = IStream_Seek(output, pos, STREAM_SEEK_SET, NULL);
1613 if(FAILED(hres)) {
1614 IStream_Release(output);
1615 return hres;
1618 *ret_stream = output;
1619 return S_OK;
1622 static int hex_digit(char c)
1624 if('0' <= c && c <= '9')
1625 return c - '0';
1626 if('A' <= c && c <= 'F')
1627 return c - 'A' + 10;
1628 if('a' <= c && c <= 'f')
1629 return c - 'a' + 10;
1630 return -1;
1633 static HRESULT decode_qp(IStream *input, IStream **ret_stream)
1635 const unsigned char *ptr, *end;
1636 unsigned char *ret, prev = 0;
1637 unsigned char buf[1024];
1638 LARGE_INTEGER pos;
1639 IStream *output;
1640 DWORD size;
1641 int n = -1;
1642 HRESULT hres;
1644 pos.QuadPart = 0;
1645 hres = IStream_Seek(input, pos, STREAM_SEEK_SET, NULL);
1646 if(FAILED(hres))
1647 return hres;
1649 hres = CreateStreamOnHGlobal(NULL, TRUE, &output);
1650 if(FAILED(hres))
1651 return hres;
1653 while(1) {
1654 hres = IStream_Read(input, buf, sizeof(buf), &size);
1655 if(FAILED(hres) || !size)
1656 break;
1658 ptr = ret = buf;
1659 end = buf + size;
1661 while(ptr < end) {
1662 unsigned char byte = *ptr++;
1664 switch(n) {
1665 case -1:
1666 if(byte == '=')
1667 n = 0;
1668 else
1669 *ret++ = byte;
1670 continue;
1671 case 0:
1672 prev = byte;
1673 n = 1;
1674 continue;
1675 case 1:
1676 if(prev != '\r' || byte != '\n') {
1677 int h1 = hex_digit(prev), h2 = hex_digit(byte);
1678 if(h1 != -1 && h2 != -1)
1679 *ret++ = (h1 << 4) | h2;
1680 else
1681 *ret++ = '=';
1683 n = -1;
1684 continue;
1688 if(ret > buf) {
1689 hres = IStream_Write(output, buf, ret - buf, NULL);
1690 if(FAILED(hres))
1691 break;
1695 if(SUCCEEDED(hres))
1696 hres = IStream_Seek(output, pos, STREAM_SEEK_SET, NULL);
1697 if(FAILED(hres)) {
1698 IStream_Release(output);
1699 return hres;
1702 *ret_stream = output;
1703 return S_OK;
1706 static HRESULT WINAPI MimeBody_GetData(
1707 IMimeBody* iface,
1708 ENCODINGTYPE ietEncoding,
1709 IStream** ppStream)
1711 MimeBody *This = impl_from_IMimeBody(iface);
1712 ULARGE_INTEGER start, size;
1713 HRESULT hres;
1715 TRACE("(%p)->(%d %p)\n", This, ietEncoding, ppStream);
1717 if(This->encoding != ietEncoding) {
1718 switch(This->encoding) {
1719 case IET_BASE64:
1720 hres = decode_base64(This->data, ppStream);
1721 break;
1722 case IET_QP:
1723 hres = decode_qp(This->data, ppStream);
1724 break;
1725 default:
1726 FIXME("Decoding %d is not supported.\n", This->encoding);
1727 hres = S_FALSE;
1729 if(ietEncoding != IET_BINARY)
1730 FIXME("Encoding %d is not supported.\n", ietEncoding);
1731 if(hres != S_FALSE)
1732 return hres;
1735 start.QuadPart = 0;
1736 hres = get_stream_size(This->data, &size);
1737 if(SUCCEEDED(hres))
1738 hres = create_sub_stream(This->data, start, size, ppStream);
1739 return hres;
1742 static HRESULT WINAPI MimeBody_SetData(
1743 IMimeBody* iface,
1744 ENCODINGTYPE ietEncoding,
1745 LPCSTR pszPriType,
1746 LPCSTR pszSubType,
1747 REFIID riid,
1748 LPVOID pvObject)
1750 MimeBody *This = impl_from_IMimeBody(iface);
1751 TRACE("(%p)->(%d, %s, %s, %s %p)\n", This, ietEncoding, debugstr_a(pszPriType), debugstr_a(pszSubType),
1752 debugstr_guid(riid), pvObject);
1754 if(IsEqualIID(riid, &IID_IStream))
1755 IStream_AddRef((IStream *)pvObject);
1756 else
1758 FIXME("Unhandled object type %s\n", debugstr_guid(riid));
1759 return E_INVALIDARG;
1762 if(This->data)
1763 release_data(&This->data_iid, This->data);
1765 This->data_iid = *riid;
1766 This->data = pvObject;
1768 IMimeBody_SetCurrentEncoding(iface, ietEncoding);
1770 /* FIXME: Update the content type.
1771 If pszPriType == NULL use 'application'
1772 If pszSubType == NULL use 'octet-stream' */
1774 return S_OK;
1777 static HRESULT WINAPI MimeBody_EmptyData(
1778 IMimeBody* iface)
1780 MimeBody *This = impl_from_IMimeBody(iface);
1781 FIXME("(%p)->() stub\n", This);
1782 return E_NOTIMPL;
1785 static HRESULT WINAPI MimeBody_CopyTo(
1786 IMimeBody* iface,
1787 IMimeBody* pBody)
1789 MimeBody *This = impl_from_IMimeBody(iface);
1790 FIXME("(%p)->(%p) stub\n", This, pBody);
1791 return E_NOTIMPL;
1794 static HRESULT WINAPI MimeBody_GetTransmitInfo(
1795 IMimeBody* iface,
1796 LPTRANSMITINFO pTransmitInfo)
1798 MimeBody *This = impl_from_IMimeBody(iface);
1799 FIXME("(%p)->(%p) stub\n", This, pTransmitInfo);
1800 return E_NOTIMPL;
1803 static HRESULT WINAPI MimeBody_SaveToFile(
1804 IMimeBody* iface,
1805 ENCODINGTYPE ietEncoding,
1806 LPCSTR pszFilePath)
1808 MimeBody *This = impl_from_IMimeBody(iface);
1809 FIXME("(%p)->(%d, %s) stub\n", This, ietEncoding, debugstr_a(pszFilePath));
1810 return E_NOTIMPL;
1813 static HRESULT WINAPI MimeBody_GetHandle(
1814 IMimeBody* iface,
1815 LPHBODY phBody)
1817 MimeBody *This = impl_from_IMimeBody(iface);
1818 TRACE("(%p)->(%p)\n", iface, phBody);
1820 if(!phBody)
1821 return E_INVALIDARG;
1823 *phBody = This->handle;
1824 return This->handle ? S_OK : MIME_E_NO_DATA;
1827 static IMimeBodyVtbl body_vtbl =
1829 MimeBody_QueryInterface,
1830 MimeBody_AddRef,
1831 MimeBody_Release,
1832 MimeBody_GetClassID,
1833 MimeBody_IsDirty,
1834 MimeBody_Load,
1835 MimeBody_Save,
1836 MimeBody_GetSizeMax,
1837 MimeBody_InitNew,
1838 MimeBody_GetPropInfo,
1839 MimeBody_SetPropInfo,
1840 MimeBody_GetProp,
1841 MimeBody_SetProp,
1842 MimeBody_AppendProp,
1843 MimeBody_DeleteProp,
1844 MimeBody_CopyProps,
1845 MimeBody_MoveProps,
1846 MimeBody_DeleteExcept,
1847 MimeBody_QueryProp,
1848 MimeBody_GetCharset,
1849 MimeBody_SetCharset,
1850 MimeBody_GetParameters,
1851 MimeBody_IsContentType,
1852 MimeBody_BindToObject,
1853 MimeBody_Clone,
1854 MimeBody_SetOption,
1855 MimeBody_GetOption,
1856 MimeBody_EnumProps,
1857 MimeBody_IsType,
1858 MimeBody_SetDisplayName,
1859 MimeBody_GetDisplayName,
1860 MimeBody_GetOffsets,
1861 MimeBody_GetCurrentEncoding,
1862 MimeBody_SetCurrentEncoding,
1863 MimeBody_GetEstimatedSize,
1864 MimeBody_GetDataHere,
1865 MimeBody_GetData,
1866 MimeBody_SetData,
1867 MimeBody_EmptyData,
1868 MimeBody_CopyTo,
1869 MimeBody_GetTransmitInfo,
1870 MimeBody_SaveToFile,
1871 MimeBody_GetHandle
1874 static HRESULT MimeBody_set_offsets(MimeBody *body, const BODYOFFSETS *offsets)
1876 TRACE("setting offsets to %d, %d, %d, %d\n", offsets->cbBoundaryStart,
1877 offsets->cbHeaderStart, offsets->cbBodyStart, offsets->cbBodyEnd);
1879 body->body_offsets = *offsets;
1880 return S_OK;
1883 #define FIRST_CUSTOM_PROP_ID 0x100
1885 static MimeBody *mimebody_create(void)
1887 MimeBody *This;
1888 BODYOFFSETS body_offsets;
1890 This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
1891 if (!This)
1892 return NULL;
1894 This->IMimeBody_iface.lpVtbl = &body_vtbl;
1895 This->ref = 1;
1896 This->handle = NULL;
1897 list_init(&This->headers);
1898 list_init(&This->new_props);
1899 This->next_prop_id = FIRST_CUSTOM_PROP_ID;
1900 This->content_pri_type = NULL;
1901 This->content_sub_type = NULL;
1902 This->encoding = IET_7BIT;
1903 This->data = NULL;
1904 This->data_iid = IID_NULL;
1906 body_offsets.cbBoundaryStart = body_offsets.cbHeaderStart = 0;
1907 body_offsets.cbBodyStart = body_offsets.cbBodyEnd = 0;
1908 MimeBody_set_offsets(This, &body_offsets);
1910 return This;
1913 HRESULT MimeBody_create(IUnknown *outer, void **ppv)
1915 MimeBody *mb;
1917 if(outer)
1918 return CLASS_E_NOAGGREGATION;
1920 if ((mb = mimebody_create()))
1922 *ppv = &mb->IMimeBody_iface;
1923 return S_OK;
1925 else
1927 *ppv = NULL;
1928 return E_OUTOFMEMORY;
1932 typedef struct body_t
1934 struct list entry;
1935 DWORD index;
1936 MimeBody *mime_body;
1938 struct body_t *parent;
1939 struct list children;
1940 } body_t;
1942 typedef struct MimeMessage
1944 IMimeMessage IMimeMessage_iface;
1945 LONG ref;
1946 IStream *stream;
1948 struct list body_tree;
1949 DWORD next_index;
1950 } MimeMessage;
1952 static inline MimeMessage *impl_from_IMimeMessage(IMimeMessage *iface)
1954 return CONTAINING_RECORD(iface, MimeMessage, IMimeMessage_iface);
1957 static HRESULT WINAPI MimeMessage_QueryInterface(IMimeMessage *iface, REFIID riid, void **ppv)
1959 TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppv);
1961 if (IsEqualIID(riid, &IID_IUnknown) ||
1962 IsEqualIID(riid, &IID_IPersist) ||
1963 IsEqualIID(riid, &IID_IPersistStreamInit) ||
1964 IsEqualIID(riid, &IID_IMimeMessageTree) ||
1965 IsEqualIID(riid, &IID_IMimeMessage))
1967 *ppv = iface;
1968 IMimeMessage_AddRef(iface);
1969 return S_OK;
1972 FIXME("no interface for %s\n", debugstr_guid(riid));
1973 *ppv = NULL;
1974 return E_NOINTERFACE;
1977 static ULONG WINAPI MimeMessage_AddRef(IMimeMessage *iface)
1979 MimeMessage *This = impl_from_IMimeMessage(iface);
1980 ULONG ref = InterlockedIncrement(&This->ref);
1982 TRACE("(%p) ref=%d\n", This, ref);
1984 return ref;
1987 static void empty_body_list(struct list *list)
1989 body_t *body, *cursor2;
1990 LIST_FOR_EACH_ENTRY_SAFE(body, cursor2, list, body_t, entry)
1992 empty_body_list(&body->children);
1993 list_remove(&body->entry);
1994 IMimeBody_Release(&body->mime_body->IMimeBody_iface);
1995 HeapFree(GetProcessHeap(), 0, body);
1999 static ULONG WINAPI MimeMessage_Release(IMimeMessage *iface)
2001 MimeMessage *This = impl_from_IMimeMessage(iface);
2002 ULONG ref = InterlockedDecrement(&This->ref);
2004 TRACE("(%p) ref=%d\n", This, ref);
2006 if (!ref)
2008 empty_body_list(&This->body_tree);
2010 if(This->stream) IStream_Release(This->stream);
2011 HeapFree(GetProcessHeap(), 0, This);
2014 return ref;
2017 /*** IPersist methods ***/
2018 static HRESULT WINAPI MimeMessage_GetClassID(
2019 IMimeMessage *iface,
2020 CLSID *pClassID)
2022 FIXME("(%p)->(%p)\n", iface, pClassID);
2023 return E_NOTIMPL;
2026 /*** IPersistStreamInit methods ***/
2027 static HRESULT WINAPI MimeMessage_IsDirty(
2028 IMimeMessage *iface)
2030 FIXME("(%p)->()\n", iface);
2031 return E_NOTIMPL;
2034 static body_t *new_body_entry(MimeBody *mime_body, DWORD index, body_t *parent)
2036 body_t *body = HeapAlloc(GetProcessHeap(), 0, sizeof(*body));
2037 if(body)
2039 body->mime_body = mime_body;
2040 body->index = index;
2041 list_init(&body->children);
2042 body->parent = parent;
2044 mime_body->handle = UlongToHandle(body->index);
2046 return body;
2049 typedef struct
2051 struct list entry;
2052 BODYOFFSETS offsets;
2053 } offset_entry_t;
2055 static HRESULT create_body_offset_list(IStream *stm, const char *boundary, struct list *body_offsets)
2057 HRESULT hr;
2058 DWORD read, boundary_start;
2059 int boundary_len = strlen(boundary);
2060 char *buf, *ptr, *overlap;
2061 DWORD start = 0, overlap_no;
2062 offset_entry_t *cur_body = NULL;
2063 BOOL is_first_line = TRUE;
2064 ULARGE_INTEGER cur;
2065 LARGE_INTEGER zero;
2067 list_init(body_offsets);
2069 overlap_no = boundary_len + 5;
2071 overlap = buf = HeapAlloc(GetProcessHeap(), 0, overlap_no + PARSER_BUF_SIZE + 1);
2073 zero.QuadPart = 0;
2074 hr = IStream_Seek(stm, zero, STREAM_SEEK_CUR, &cur);
2075 start = cur.u.LowPart;
2077 do {
2078 hr = IStream_Read(stm, overlap, PARSER_BUF_SIZE, &read);
2079 if(FAILED(hr)) goto end;
2080 if(read == 0) break;
2081 overlap[read] = '\0';
2083 ptr = buf;
2084 while(1) {
2085 if(is_first_line) {
2086 is_first_line = FALSE;
2087 }else {
2088 ptr = strstr(ptr, "\r\n");
2089 if(!ptr)
2090 break;
2091 ptr += 2;
2094 boundary_start = start + ptr - buf;
2096 if(*ptr == '-' && *(ptr + 1) == '-' && !memcmp(ptr + 2, boundary, boundary_len)) {
2097 ptr += boundary_len + 2;
2099 if(*ptr == '\r' && *(ptr + 1) == '\n')
2101 ptr += 2;
2102 if(cur_body)
2104 cur_body->offsets.cbBodyEnd = boundary_start - 2;
2105 list_add_tail(body_offsets, &cur_body->entry);
2107 cur_body = HeapAlloc(GetProcessHeap(), 0, sizeof(*cur_body));
2108 cur_body->offsets.cbBoundaryStart = boundary_start;
2109 cur_body->offsets.cbHeaderStart = start + ptr - buf;
2111 else if(*ptr == '-' && *(ptr + 1) == '-')
2113 if(cur_body)
2115 cur_body->offsets.cbBodyEnd = boundary_start - 2;
2116 list_add_tail(body_offsets, &cur_body->entry);
2117 goto end;
2123 if(overlap == buf) /* 1st iteration */
2125 memmove(buf, buf + PARSER_BUF_SIZE - overlap_no, overlap_no);
2126 overlap = buf + overlap_no;
2127 start += read - overlap_no;
2129 else
2131 memmove(buf, buf + PARSER_BUF_SIZE, overlap_no);
2132 start += read;
2134 } while(1);
2136 end:
2137 HeapFree(GetProcessHeap(), 0, buf);
2138 return hr;
2141 static body_t *create_sub_body(MimeMessage *msg, IStream *pStm, BODYOFFSETS *offset, body_t *parent)
2143 ULARGE_INTEGER start, length;
2144 MimeBody *mime_body;
2145 HRESULT hr;
2146 body_t *body;
2147 LARGE_INTEGER pos;
2149 pos.QuadPart = offset->cbHeaderStart;
2150 IStream_Seek(pStm, pos, STREAM_SEEK_SET, NULL);
2152 mime_body = mimebody_create();
2153 IMimeBody_Load(&mime_body->IMimeBody_iface, pStm);
2155 pos.QuadPart = 0;
2156 hr = IStream_Seek(pStm, pos, STREAM_SEEK_CUR, &start);
2157 offset->cbBodyStart = start.QuadPart;
2158 if (parent) MimeBody_set_offsets(mime_body, offset);
2160 length.QuadPart = offset->cbBodyEnd - offset->cbBodyStart;
2161 create_sub_stream(pStm, start, length, (IStream**)&mime_body->data);
2162 mime_body->data_iid = IID_IStream;
2164 body = new_body_entry(mime_body, msg->next_index++, parent);
2166 if(IMimeBody_IsContentType(&mime_body->IMimeBody_iface, "multipart", NULL) == S_OK)
2168 MIMEPARAMINFO *param_info;
2169 ULONG count, i;
2170 IMimeAllocator *alloc;
2172 hr = IMimeBody_GetParameters(&mime_body->IMimeBody_iface, "Content-Type", &count,
2173 &param_info);
2174 if(hr != S_OK || count == 0) return body;
2176 MimeOleGetAllocator(&alloc);
2178 for(i = 0; i < count; i++)
2180 if(!lstrcmpiA(param_info[i].pszName, "boundary"))
2182 struct list offset_list;
2183 offset_entry_t *cur, *cursor2;
2184 hr = create_body_offset_list(pStm, param_info[i].pszData, &offset_list);
2185 LIST_FOR_EACH_ENTRY_SAFE(cur, cursor2, &offset_list, offset_entry_t, entry)
2187 body_t *sub_body;
2189 sub_body = create_sub_body(msg, pStm, &cur->offsets, body);
2190 list_add_tail(&body->children, &sub_body->entry);
2191 list_remove(&cur->entry);
2192 HeapFree(GetProcessHeap(), 0, cur);
2194 break;
2197 IMimeAllocator_FreeParamInfoArray(alloc, count, param_info, TRUE);
2198 IMimeAllocator_Release(alloc);
2200 return body;
2203 static HRESULT WINAPI MimeMessage_Load(IMimeMessage *iface, IStream *pStm)
2205 MimeMessage *This = impl_from_IMimeMessage(iface);
2206 body_t *root_body;
2207 BODYOFFSETS offsets;
2208 ULARGE_INTEGER cur;
2209 LARGE_INTEGER zero;
2211 TRACE("(%p)->(%p)\n", iface, pStm);
2213 if(This->stream)
2215 FIXME("already loaded a message\n");
2216 return E_FAIL;
2219 empty_body_list(&This->body_tree);
2221 IStream_AddRef(pStm);
2222 This->stream = pStm;
2223 offsets.cbBoundaryStart = offsets.cbHeaderStart = 0;
2224 offsets.cbBodyStart = offsets.cbBodyEnd = 0;
2226 root_body = create_sub_body(This, pStm, &offsets, NULL);
2228 zero.QuadPart = 0;
2229 IStream_Seek(pStm, zero, STREAM_SEEK_END, &cur);
2230 offsets.cbBodyEnd = cur.u.LowPart;
2231 MimeBody_set_offsets(root_body->mime_body, &offsets);
2233 list_add_head(&This->body_tree, &root_body->entry);
2235 return S_OK;
2238 static HRESULT WINAPI MimeMessage_Save(IMimeMessage *iface, IStream *pStm, BOOL fClearDirty)
2240 FIXME("(%p)->(%p, %s)\n", iface, pStm, fClearDirty ? "TRUE" : "FALSE");
2241 return E_NOTIMPL;
2244 static HRESULT WINAPI MimeMessage_GetSizeMax(
2245 IMimeMessage *iface,
2246 ULARGE_INTEGER *pcbSize)
2248 FIXME("(%p)->(%p)\n", iface, pcbSize);
2249 return E_NOTIMPL;
2252 static HRESULT WINAPI MimeMessage_InitNew(
2253 IMimeMessage *iface)
2255 FIXME("(%p)->()\n", iface);
2256 return E_NOTIMPL;
2259 /*** IMimeMessageTree methods ***/
2260 static HRESULT WINAPI MimeMessage_GetMessageSource(IMimeMessage *iface, IStream **ppStream,
2261 DWORD dwFlags)
2263 MimeMessage *This = impl_from_IMimeMessage(iface);
2265 FIXME("(%p)->(%p, 0x%x)\n", iface, ppStream, dwFlags);
2267 IStream_AddRef(This->stream);
2268 *ppStream = This->stream;
2269 return S_OK;
2272 static HRESULT WINAPI MimeMessage_GetMessageSize(
2273 IMimeMessage *iface,
2274 ULONG *pcbSize,
2275 DWORD dwFlags)
2277 FIXME("(%p)->(%p, 0x%x)\n", iface, pcbSize, dwFlags);
2278 return E_NOTIMPL;
2281 static HRESULT WINAPI MimeMessage_LoadOffsetTable(
2282 IMimeMessage *iface,
2283 IStream *pStream)
2285 FIXME("(%p)->(%p)\n", iface, pStream);
2286 return E_NOTIMPL;
2289 static HRESULT WINAPI MimeMessage_SaveOffsetTable(
2290 IMimeMessage *iface,
2291 IStream *pStream,
2292 DWORD dwFlags)
2294 FIXME("(%p)->(%p, 0x%x)\n", iface, pStream, dwFlags);
2295 return E_NOTIMPL;
2299 static HRESULT WINAPI MimeMessage_GetFlags(
2300 IMimeMessage *iface,
2301 DWORD *pdwFlags)
2303 FIXME("(%p)->(%p)\n", iface, pdwFlags);
2304 return E_NOTIMPL;
2307 static HRESULT WINAPI MimeMessage_Commit(
2308 IMimeMessage *iface,
2309 DWORD dwFlags)
2311 FIXME("(%p)->(0x%x)\n", iface, dwFlags);
2312 return S_OK;
2316 static HRESULT WINAPI MimeMessage_HandsOffStorage(
2317 IMimeMessage *iface)
2319 FIXME("(%p)->()\n", iface);
2320 return E_NOTIMPL;
2323 static HRESULT find_body(struct list *list, HBODY hbody, body_t **body)
2325 body_t *cur;
2326 HRESULT hr;
2328 if(hbody == HBODY_ROOT)
2330 *body = LIST_ENTRY(list_head(list), body_t, entry);
2331 return S_OK;
2334 LIST_FOR_EACH_ENTRY(cur, list, body_t, entry)
2336 if(cur->index == HandleToUlong(hbody))
2338 *body = cur;
2339 return S_OK;
2341 hr = find_body(&cur->children, hbody, body);
2342 if(hr == S_OK) return S_OK;
2344 return S_FALSE;
2347 static HRESULT WINAPI MimeMessage_BindToObject(IMimeMessage *iface, const HBODY hBody, REFIID riid,
2348 void **ppvObject)
2350 MimeMessage *This = impl_from_IMimeMessage(iface);
2351 HRESULT hr;
2352 body_t *body;
2354 TRACE("(%p)->(%p, %s, %p)\n", iface, hBody, debugstr_guid(riid), ppvObject);
2356 hr = find_body(&This->body_tree, hBody, &body);
2358 if(hr != S_OK) return hr;
2360 if(IsEqualIID(riid, &IID_IMimeBody))
2362 IMimeBody_AddRef(&body->mime_body->IMimeBody_iface);
2363 *ppvObject = &body->mime_body->IMimeBody_iface;
2364 return S_OK;
2367 return E_NOINTERFACE;
2370 static HRESULT WINAPI MimeMessage_SaveBody(
2371 IMimeMessage *iface,
2372 HBODY hBody,
2373 DWORD dwFlags,
2374 IStream *pStream)
2376 FIXME("(%p)->(%p, 0x%x, %p)\n", iface, hBody, dwFlags, pStream);
2377 return E_NOTIMPL;
2380 static HRESULT get_body(MimeMessage *msg, BODYLOCATION location, HBODY pivot, body_t **out)
2382 body_t *root = LIST_ENTRY(list_head(&msg->body_tree), body_t, entry);
2383 body_t *body;
2384 HRESULT hr;
2385 struct list *list;
2387 if(location == IBL_ROOT)
2389 *out = root;
2390 return S_OK;
2393 hr = find_body(&msg->body_tree, pivot, &body);
2395 if(hr == S_OK)
2397 switch(location)
2399 case IBL_PARENT:
2400 if(body->parent)
2401 *out = body->parent;
2402 else
2403 hr = MIME_E_NOT_FOUND;
2404 break;
2406 case IBL_FIRST:
2407 list = list_head(&body->children);
2408 if(list)
2409 *out = LIST_ENTRY(list, body_t, entry);
2410 else
2411 hr = MIME_E_NOT_FOUND;
2412 break;
2414 case IBL_LAST:
2415 list = list_tail(&body->children);
2416 if(list)
2417 *out = LIST_ENTRY(list, body_t, entry);
2418 else
2419 hr = MIME_E_NOT_FOUND;
2420 break;
2422 case IBL_NEXT:
2423 list = list_next(&body->parent->children, &body->entry);
2424 if(list)
2425 *out = LIST_ENTRY(list, body_t, entry);
2426 else
2427 hr = MIME_E_NOT_FOUND;
2428 break;
2430 case IBL_PREVIOUS:
2431 list = list_prev(&body->parent->children, &body->entry);
2432 if(list)
2433 *out = LIST_ENTRY(list, body_t, entry);
2434 else
2435 hr = MIME_E_NOT_FOUND;
2436 break;
2438 default:
2439 hr = E_FAIL;
2440 break;
2444 return hr;
2448 static HRESULT WINAPI MimeMessage_InsertBody(
2449 IMimeMessage *iface,
2450 BODYLOCATION location,
2451 HBODY hPivot,
2452 LPHBODY phBody)
2454 FIXME("(%p)->(%d, %p, %p)\n", iface, location, hPivot, phBody);
2455 return E_NOTIMPL;
2458 static HRESULT WINAPI MimeMessage_GetBody(IMimeMessage *iface, BODYLOCATION location, HBODY hPivot,
2459 HBODY *phBody)
2461 MimeMessage *This = impl_from_IMimeMessage(iface);
2462 body_t *body;
2463 HRESULT hr;
2465 TRACE("(%p)->(%d, %p, %p)\n", iface, location, hPivot, phBody);
2467 if(!phBody)
2468 return E_INVALIDARG;
2470 *phBody = NULL;
2472 hr = get_body(This, location, hPivot, &body);
2474 if(hr == S_OK) *phBody = UlongToHandle(body->index);
2476 return hr;
2479 static HRESULT WINAPI MimeMessage_DeleteBody(
2480 IMimeMessage *iface,
2481 HBODY hBody,
2482 DWORD dwFlags)
2484 FIXME("(%p)->(%p, %08x)\n", iface, hBody, dwFlags);
2485 return E_NOTIMPL;
2488 static HRESULT WINAPI MimeMessage_MoveBody(
2489 IMimeMessage *iface,
2490 HBODY hBody,
2491 BODYLOCATION location)
2493 FIXME("(%p)->(%d)\n", iface, location);
2494 return E_NOTIMPL;
2497 static void count_children(body_t *body, boolean recurse, ULONG *count)
2499 body_t *child;
2501 LIST_FOR_EACH_ENTRY(child, &body->children, body_t, entry)
2503 (*count)++;
2504 if(recurse) count_children(child, recurse, count);
2508 static HRESULT WINAPI MimeMessage_CountBodies(IMimeMessage *iface, HBODY hParent, boolean fRecurse,
2509 ULONG *pcBodies)
2511 HRESULT hr;
2512 MimeMessage *This = impl_from_IMimeMessage(iface);
2513 body_t *body;
2515 TRACE("(%p)->(%p, %s, %p)\n", iface, hParent, fRecurse ? "TRUE" : "FALSE", pcBodies);
2517 hr = find_body(&This->body_tree, hParent, &body);
2518 if(hr != S_OK) return hr;
2520 *pcBodies = 1;
2521 count_children(body, fRecurse, pcBodies);
2523 return S_OK;
2526 static HRESULT find_next(MimeMessage *This, body_t *body, FINDBODY *find, HBODY *out)
2528 struct list *ptr;
2529 HBODY next;
2531 for (;;)
2533 if (!body) ptr = list_head( &This->body_tree );
2534 else
2536 ptr = list_head( &body->children );
2537 while (!ptr)
2539 if (!body->parent) return MIME_E_NOT_FOUND;
2540 if (!(ptr = list_next( &body->parent->children, &body->entry ))) body = body->parent;
2544 body = LIST_ENTRY( ptr, body_t, entry );
2545 next = UlongToHandle( body->index );
2546 find->dwReserved = body->index;
2547 if (IMimeBody_IsContentType(&body->mime_body->IMimeBody_iface, find->pszPriType,
2548 find->pszSubType) == S_OK)
2550 *out = next;
2551 return S_OK;
2554 return MIME_E_NOT_FOUND;
2557 static HRESULT WINAPI MimeMessage_FindFirst(IMimeMessage *iface, FINDBODY *pFindBody, HBODY *phBody)
2559 MimeMessage *This = impl_from_IMimeMessage(iface);
2561 TRACE("(%p)->(%p, %p)\n", iface, pFindBody, phBody);
2563 pFindBody->dwReserved = 0;
2564 return find_next(This, NULL, pFindBody, phBody);
2567 static HRESULT WINAPI MimeMessage_FindNext(IMimeMessage *iface, FINDBODY *pFindBody, HBODY *phBody)
2569 MimeMessage *This = impl_from_IMimeMessage(iface);
2570 body_t *body;
2571 HRESULT hr;
2573 TRACE("(%p)->(%p, %p)\n", iface, pFindBody, phBody);
2575 hr = find_body( &This->body_tree, UlongToHandle( pFindBody->dwReserved ), &body );
2576 if (hr != S_OK) return MIME_E_NOT_FOUND;
2577 return find_next(This, body, pFindBody, phBody);
2580 static HRESULT WINAPI MimeMessage_ResolveURL(
2581 IMimeMessage *iface,
2582 HBODY hRelated,
2583 LPCSTR pszBase,
2584 LPCSTR pszURL,
2585 DWORD dwFlags,
2586 LPHBODY phBody)
2588 FIXME("(%p)->(%p, %s, %s, 0x%x, %p)\n", iface, hRelated, pszBase, pszURL, dwFlags, phBody);
2589 return E_NOTIMPL;
2592 static HRESULT WINAPI MimeMessage_ToMultipart(
2593 IMimeMessage *iface,
2594 HBODY hBody,
2595 LPCSTR pszSubType,
2596 LPHBODY phMultipart)
2598 FIXME("(%p)->(%p, %s, %p)\n", iface, hBody, pszSubType, phMultipart);
2599 return E_NOTIMPL;
2602 static HRESULT WINAPI MimeMessage_GetBodyOffsets(
2603 IMimeMessage *iface,
2604 HBODY hBody,
2605 LPBODYOFFSETS pOffsets)
2607 FIXME("(%p)->(%p, %p)\n", iface, hBody, pOffsets);
2608 return E_NOTIMPL;
2611 static HRESULT WINAPI MimeMessage_GetCharset(
2612 IMimeMessage *iface,
2613 LPHCHARSET phCharset)
2615 FIXME("(%p)->(%p)\n", iface, phCharset);
2616 *phCharset = NULL;
2617 return S_OK;
2620 static HRESULT WINAPI MimeMessage_SetCharset(
2621 IMimeMessage *iface,
2622 HCHARSET hCharset,
2623 CSETAPPLYTYPE applytype)
2625 FIXME("(%p)->(%p, %d)\n", iface, hCharset, applytype);
2626 return E_NOTIMPL;
2629 static HRESULT WINAPI MimeMessage_IsBodyType(
2630 IMimeMessage *iface,
2631 HBODY hBody,
2632 IMSGBODYTYPE bodytype)
2634 HRESULT hr;
2635 IMimeBody *mime_body;
2636 TRACE("(%p)->(%p, %d)\n", iface, hBody, bodytype);
2638 hr = IMimeMessage_BindToObject(iface, hBody, &IID_IMimeBody, (void**)&mime_body);
2639 if(hr != S_OK) return hr;
2641 hr = IMimeBody_IsType(mime_body, bodytype);
2642 MimeBody_Release(mime_body);
2643 return hr;
2646 static HRESULT WINAPI MimeMessage_IsContentType(
2647 IMimeMessage *iface,
2648 HBODY hBody,
2649 LPCSTR pszPriType,
2650 LPCSTR pszSubType)
2652 HRESULT hr;
2653 IMimeBody *mime_body;
2654 TRACE("(%p)->(%p, %s, %s)\n", iface, hBody, debugstr_a(pszPriType),
2655 debugstr_a(pszSubType));
2657 hr = IMimeMessage_BindToObject(iface, hBody, &IID_IMimeBody, (void**)&mime_body);
2658 if(FAILED(hr)) return hr;
2660 hr = IMimeBody_IsContentType(mime_body, pszPriType, pszSubType);
2661 IMimeBody_Release(mime_body);
2662 return hr;
2665 static HRESULT WINAPI MimeMessage_QueryBodyProp(
2666 IMimeMessage *iface,
2667 HBODY hBody,
2668 LPCSTR pszName,
2669 LPCSTR pszCriteria,
2670 boolean fSubString,
2671 boolean fCaseSensitive)
2673 FIXME("(%p)->(%p, %s, %s, %s, %s)\n", iface, hBody, pszName, pszCriteria, fSubString ? "TRUE" : "FALSE", fCaseSensitive ? "TRUE" : "FALSE");
2674 return E_NOTIMPL;
2677 static HRESULT WINAPI MimeMessage_GetBodyProp(
2678 IMimeMessage *iface,
2679 HBODY hBody,
2680 LPCSTR pszName,
2681 DWORD dwFlags,
2682 LPPROPVARIANT pValue)
2684 HRESULT hr;
2685 IMimeBody *mime_body;
2687 TRACE("(%p)->(%p, %s, 0x%x, %p)\n", iface, hBody, pszName, dwFlags, pValue);
2689 hr = IMimeMessage_BindToObject(iface, hBody, &IID_IMimeBody, (void**)&mime_body);
2690 if(hr != S_OK) return hr;
2692 hr = IMimeBody_GetProp(mime_body, pszName, dwFlags, pValue);
2693 IMimeBody_Release(mime_body);
2695 return hr;
2698 static HRESULT WINAPI MimeMessage_SetBodyProp(
2699 IMimeMessage *iface,
2700 HBODY hBody,
2701 LPCSTR pszName,
2702 DWORD dwFlags,
2703 LPCPROPVARIANT pValue)
2705 FIXME("(%p)->(%p, %s, 0x%x, %p)\n", iface, hBody, pszName, dwFlags, pValue);
2706 return E_NOTIMPL;
2709 static HRESULT WINAPI MimeMessage_DeleteBodyProp(
2710 IMimeMessage *iface,
2711 HBODY hBody,
2712 LPCSTR pszName)
2714 FIXME("(%p)->(%p, %s)\n", iface, hBody, pszName);
2715 return E_NOTIMPL;
2718 static HRESULT WINAPI MimeMessage_SetOption(
2719 IMimeMessage *iface,
2720 const TYPEDID oid,
2721 LPCPROPVARIANT pValue)
2723 HRESULT hr = S_OK;
2724 TRACE("(%p)->(%08x, %p)\n", iface, oid, pValue);
2726 /* Message ID is checked before type.
2727 * OID 0x4D -> 0x56 and 0x58 aren't defined but will filtered out later.
2729 if(TYPEDID_ID(oid) < TYPEDID_ID(OID_ALLOW_8BIT_HEADER) || TYPEDID_ID(oid) > TYPEDID_ID(OID_SECURITY_2KEY_CERT_BAG_64))
2731 WARN("oid (%08x) out of range\n", oid);
2732 return MIME_E_INVALID_OPTION_ID;
2735 if(pValue->vt != TYPEDID_TYPE(oid))
2737 WARN("Called with vartype %04x and oid %08x\n", pValue->vt, oid);
2738 return S_OK;
2741 switch(oid)
2743 case OID_HIDE_TNEF_ATTACHMENTS:
2744 FIXME("OID_HIDE_TNEF_ATTACHMENTS (value %d): ignoring\n", pValue->u.boolVal);
2745 break;
2746 case OID_SHOW_MACBINARY:
2747 FIXME("OID_SHOW_MACBINARY (value %d): ignoring\n", pValue->u.boolVal);
2748 break;
2749 case OID_SAVEBODY_KEEPBOUNDARY:
2750 FIXME("OID_SAVEBODY_KEEPBOUNDARY (value %d): ignoring\n", pValue->u.boolVal);
2751 break;
2752 case OID_CLEANUP_TREE_ON_SAVE:
2753 FIXME("OID_CLEANUP_TREE_ON_SAVE (value %d): ignoring\n", pValue->u.boolVal);
2754 break;
2755 default:
2756 FIXME("Unhandled oid %08x\n", oid);
2757 hr = MIME_E_INVALID_OPTION_ID;
2760 return hr;
2763 static HRESULT WINAPI MimeMessage_GetOption(
2764 IMimeMessage *iface,
2765 const TYPEDID oid,
2766 LPPROPVARIANT pValue)
2768 FIXME("(%p)->(%08x, %p)\n", iface, oid, pValue);
2769 return E_NOTIMPL;
2772 /*** IMimeMessage methods ***/
2773 static HRESULT WINAPI MimeMessage_CreateWebPage(
2774 IMimeMessage *iface,
2775 IStream *pRootStm,
2776 LPWEBPAGEOPTIONS pOptions,
2777 IMimeMessageCallback *pCallback,
2778 IMoniker **ppMoniker)
2780 FIXME("(%p)->(%p, %p, %p, %p)\n", iface, pRootStm, pOptions, pCallback, ppMoniker);
2781 *ppMoniker = NULL;
2782 return E_NOTIMPL;
2785 static HRESULT WINAPI MimeMessage_GetProp(
2786 IMimeMessage *iface,
2787 LPCSTR pszName,
2788 DWORD dwFlags,
2789 LPPROPVARIANT pValue)
2791 FIXME("(%p)->(%s, 0x%x, %p)\n", iface, pszName, dwFlags, pValue);
2792 return E_NOTIMPL;
2795 static HRESULT WINAPI MimeMessage_SetProp(
2796 IMimeMessage *iface,
2797 LPCSTR pszName,
2798 DWORD dwFlags,
2799 LPCPROPVARIANT pValue)
2801 FIXME("(%p)->(%s, 0x%x, %p)\n", iface, pszName, dwFlags, pValue);
2802 return E_NOTIMPL;
2805 static HRESULT WINAPI MimeMessage_DeleteProp(
2806 IMimeMessage *iface,
2807 LPCSTR pszName)
2809 FIXME("(%p)->(%s)\n", iface, pszName);
2810 return E_NOTIMPL;
2813 static HRESULT WINAPI MimeMessage_QueryProp(
2814 IMimeMessage *iface,
2815 LPCSTR pszName,
2816 LPCSTR pszCriteria,
2817 boolean fSubString,
2818 boolean fCaseSensitive)
2820 FIXME("(%p)->(%s, %s, %s, %s)\n", iface, pszName, pszCriteria, fSubString ? "TRUE" : "FALSE", fCaseSensitive ? "TRUE" : "FALSE");
2821 return E_NOTIMPL;
2824 static HRESULT WINAPI MimeMessage_GetTextBody(
2825 IMimeMessage *iface,
2826 DWORD dwTxtType,
2827 ENCODINGTYPE ietEncoding,
2828 IStream **pStream,
2829 LPHBODY phBody)
2831 HRESULT hr;
2832 HBODY hbody;
2833 FINDBODY find_struct;
2834 IMimeBody *mime_body;
2835 static char text[] = "text";
2836 static char plain[] = "plain";
2837 static char html[] = "html";
2839 TRACE("(%p)->(%d, %d, %p, %p)\n", iface, dwTxtType, ietEncoding, pStream, phBody);
2841 find_struct.pszPriType = text;
2843 switch(dwTxtType)
2845 case TXT_PLAIN:
2846 find_struct.pszSubType = plain;
2847 break;
2848 case TXT_HTML:
2849 find_struct.pszSubType = html;
2850 break;
2851 default:
2852 return MIME_E_INVALID_TEXT_TYPE;
2855 hr = IMimeMessage_FindFirst(iface, &find_struct, &hbody);
2856 if(hr != S_OK)
2858 TRACE("not found hr %08x\n", hr);
2859 *phBody = NULL;
2860 return hr;
2863 IMimeMessage_BindToObject(iface, hbody, &IID_IMimeBody, (void**)&mime_body);
2865 IMimeBody_GetData(mime_body, ietEncoding, pStream);
2866 *phBody = hbody;
2867 IMimeBody_Release(mime_body);
2868 return hr;
2871 static HRESULT WINAPI MimeMessage_SetTextBody(
2872 IMimeMessage *iface,
2873 DWORD dwTxtType,
2874 ENCODINGTYPE ietEncoding,
2875 HBODY hAlternative,
2876 IStream *pStream,
2877 LPHBODY phBody)
2879 FIXME("(%p)->(%d, %d, %p, %p, %p)\n", iface, dwTxtType, ietEncoding, hAlternative, pStream, phBody);
2880 return E_NOTIMPL;
2883 static HRESULT WINAPI MimeMessage_AttachObject(
2884 IMimeMessage *iface,
2885 REFIID riid,
2886 void *pvObject,
2887 LPHBODY phBody)
2889 FIXME("(%p)->(%s, %p, %p)\n", iface, debugstr_guid(riid), pvObject, phBody);
2890 return E_NOTIMPL;
2893 static HRESULT WINAPI MimeMessage_AttachFile(
2894 IMimeMessage *iface,
2895 LPCSTR pszFilePath,
2896 IStream *pstmFile,
2897 LPHBODY phBody)
2899 FIXME("(%p)->(%s, %p, %p)\n", iface, pszFilePath, pstmFile, phBody);
2900 return E_NOTIMPL;
2903 static HRESULT WINAPI MimeMessage_AttachURL(
2904 IMimeMessage *iface,
2905 LPCSTR pszBase,
2906 LPCSTR pszURL,
2907 DWORD dwFlags,
2908 IStream *pstmURL,
2909 LPSTR *ppszCIDURL,
2910 LPHBODY phBody)
2912 FIXME("(%p)->(%s, %s, 0x%x, %p, %p, %p)\n", iface, pszBase, pszURL, dwFlags, pstmURL, ppszCIDURL, phBody);
2913 return E_NOTIMPL;
2916 static HRESULT WINAPI MimeMessage_GetAttachments(
2917 IMimeMessage *iface,
2918 ULONG *pcAttach,
2919 LPHBODY *pprghAttach)
2921 HRESULT hr;
2922 FINDBODY find_struct;
2923 HBODY hbody;
2924 LPHBODY array;
2925 ULONG size = 10;
2927 TRACE("(%p)->(%p, %p)\n", iface, pcAttach, pprghAttach);
2929 *pcAttach = 0;
2930 array = CoTaskMemAlloc(size * sizeof(HBODY));
2932 find_struct.pszPriType = find_struct.pszSubType = NULL;
2933 hr = IMimeMessage_FindFirst(iface, &find_struct, &hbody);
2934 while(hr == S_OK)
2936 hr = IMimeMessage_IsContentType(iface, hbody, "multipart", NULL);
2937 TRACE("IsCT rets %08x %d\n", hr, *pcAttach);
2938 if(hr != S_OK)
2940 if(*pcAttach + 1 > size)
2942 size *= 2;
2943 array = CoTaskMemRealloc(array, size * sizeof(HBODY));
2945 array[*pcAttach] = hbody;
2946 (*pcAttach)++;
2948 hr = IMimeMessage_FindNext(iface, &find_struct, &hbody);
2951 *pprghAttach = array;
2952 return S_OK;
2955 static HRESULT WINAPI MimeMessage_GetAddressTable(
2956 IMimeMessage *iface,
2957 IMimeAddressTable **ppTable)
2959 FIXME("(%p)->(%p)\n", iface, ppTable);
2960 return E_NOTIMPL;
2963 static HRESULT WINAPI MimeMessage_GetSender(
2964 IMimeMessage *iface,
2965 LPADDRESSPROPS pAddress)
2967 FIXME("(%p)->(%p)\n", iface, pAddress);
2968 return E_NOTIMPL;
2971 static HRESULT WINAPI MimeMessage_GetAddressTypes(
2972 IMimeMessage *iface,
2973 DWORD dwAdrTypes,
2974 DWORD dwProps,
2975 LPADDRESSLIST pList)
2977 FIXME("(%p)->(%d, %d, %p)\n", iface, dwAdrTypes, dwProps, pList);
2978 return E_NOTIMPL;
2981 static HRESULT WINAPI MimeMessage_GetAddressFormat(
2982 IMimeMessage *iface,
2983 DWORD dwAdrTypes,
2984 ADDRESSFORMAT format,
2985 LPSTR *ppszFormat)
2987 FIXME("(%p)->(%d, %d, %p)\n", iface, dwAdrTypes, format, ppszFormat);
2988 return E_NOTIMPL;
2991 static HRESULT WINAPI MimeMessage_EnumAddressTypes(
2992 IMimeMessage *iface,
2993 DWORD dwAdrTypes,
2994 DWORD dwProps,
2995 IMimeEnumAddressTypes **ppEnum)
2997 FIXME("(%p)->(%d, %d, %p)\n", iface, dwAdrTypes, dwProps, ppEnum);
2998 return E_NOTIMPL;
3001 static HRESULT WINAPI MimeMessage_SplitMessage(
3002 IMimeMessage *iface,
3003 ULONG cbMaxPart,
3004 IMimeMessageParts **ppParts)
3006 FIXME("(%p)->(%d, %p)\n", iface, cbMaxPart, ppParts);
3007 return E_NOTIMPL;
3010 static HRESULT WINAPI MimeMessage_GetRootMoniker(
3011 IMimeMessage *iface,
3012 IMoniker **ppMoniker)
3014 FIXME("(%p)->(%p)\n", iface, ppMoniker);
3015 return E_NOTIMPL;
3018 static const IMimeMessageVtbl MimeMessageVtbl =
3020 MimeMessage_QueryInterface,
3021 MimeMessage_AddRef,
3022 MimeMessage_Release,
3023 MimeMessage_GetClassID,
3024 MimeMessage_IsDirty,
3025 MimeMessage_Load,
3026 MimeMessage_Save,
3027 MimeMessage_GetSizeMax,
3028 MimeMessage_InitNew,
3029 MimeMessage_GetMessageSource,
3030 MimeMessage_GetMessageSize,
3031 MimeMessage_LoadOffsetTable,
3032 MimeMessage_SaveOffsetTable,
3033 MimeMessage_GetFlags,
3034 MimeMessage_Commit,
3035 MimeMessage_HandsOffStorage,
3036 MimeMessage_BindToObject,
3037 MimeMessage_SaveBody,
3038 MimeMessage_InsertBody,
3039 MimeMessage_GetBody,
3040 MimeMessage_DeleteBody,
3041 MimeMessage_MoveBody,
3042 MimeMessage_CountBodies,
3043 MimeMessage_FindFirst,
3044 MimeMessage_FindNext,
3045 MimeMessage_ResolveURL,
3046 MimeMessage_ToMultipart,
3047 MimeMessage_GetBodyOffsets,
3048 MimeMessage_GetCharset,
3049 MimeMessage_SetCharset,
3050 MimeMessage_IsBodyType,
3051 MimeMessage_IsContentType,
3052 MimeMessage_QueryBodyProp,
3053 MimeMessage_GetBodyProp,
3054 MimeMessage_SetBodyProp,
3055 MimeMessage_DeleteBodyProp,
3056 MimeMessage_SetOption,
3057 MimeMessage_GetOption,
3058 MimeMessage_CreateWebPage,
3059 MimeMessage_GetProp,
3060 MimeMessage_SetProp,
3061 MimeMessage_DeleteProp,
3062 MimeMessage_QueryProp,
3063 MimeMessage_GetTextBody,
3064 MimeMessage_SetTextBody,
3065 MimeMessage_AttachObject,
3066 MimeMessage_AttachFile,
3067 MimeMessage_AttachURL,
3068 MimeMessage_GetAttachments,
3069 MimeMessage_GetAddressTable,
3070 MimeMessage_GetSender,
3071 MimeMessage_GetAddressTypes,
3072 MimeMessage_GetAddressFormat,
3073 MimeMessage_EnumAddressTypes,
3074 MimeMessage_SplitMessage,
3075 MimeMessage_GetRootMoniker,
3078 HRESULT MimeMessage_create(IUnknown *outer, void **obj)
3080 MimeMessage *This;
3081 MimeBody *mime_body;
3082 body_t *root_body;
3084 TRACE("(%p, %p)\n", outer, obj);
3086 if (outer)
3088 FIXME("outer unknown not supported yet\n");
3089 return E_NOTIMPL;
3092 *obj = NULL;
3094 This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
3095 if (!This) return E_OUTOFMEMORY;
3097 This->IMimeMessage_iface.lpVtbl = &MimeMessageVtbl;
3098 This->ref = 1;
3099 This->stream = NULL;
3100 list_init(&This->body_tree);
3101 This->next_index = 1;
3103 mime_body = mimebody_create();
3104 root_body = new_body_entry(mime_body, This->next_index++, NULL);
3105 list_add_head(&This->body_tree, &root_body->entry);
3107 *obj = &This->IMimeMessage_iface;
3108 return S_OK;
3111 /***********************************************************************
3112 * MimeOleCreateMessage (INETCOMM.@)
3114 HRESULT WINAPI MimeOleCreateMessage(IUnknown *pUnkOuter, IMimeMessage **ppMessage)
3116 TRACE("(%p, %p)\n", pUnkOuter, ppMessage);
3117 return MimeMessage_create(NULL, (void **)ppMessage);
3120 /***********************************************************************
3121 * MimeOleSetCompatMode (INETCOMM.@)
3123 HRESULT WINAPI MimeOleSetCompatMode(DWORD dwMode)
3125 FIXME("(0x%x)\n", dwMode);
3126 return S_OK;
3129 /***********************************************************************
3130 * MimeOleCreateVirtualStream (INETCOMM.@)
3132 HRESULT WINAPI MimeOleCreateVirtualStream(IStream **ppStream)
3134 HRESULT hr;
3135 FIXME("(%p)\n", ppStream);
3137 hr = CreateStreamOnHGlobal(NULL, TRUE, ppStream);
3138 return hr;
3141 typedef struct MimeSecurity
3143 IMimeSecurity IMimeSecurity_iface;
3144 LONG ref;
3145 } MimeSecurity;
3147 static inline MimeSecurity *impl_from_IMimeSecurity(IMimeSecurity *iface)
3149 return CONTAINING_RECORD(iface, MimeSecurity, IMimeSecurity_iface);
3152 static HRESULT WINAPI MimeSecurity_QueryInterface(IMimeSecurity *iface, REFIID riid, void **ppv)
3154 TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppv);
3156 if (IsEqualIID(riid, &IID_IUnknown) ||
3157 IsEqualIID(riid, &IID_IMimeSecurity))
3159 *ppv = iface;
3160 IMimeSecurity_AddRef(iface);
3161 return S_OK;
3164 FIXME("no interface for %s\n", debugstr_guid(riid));
3165 *ppv = NULL;
3166 return E_NOINTERFACE;
3169 static ULONG WINAPI MimeSecurity_AddRef(IMimeSecurity *iface)
3171 MimeSecurity *This = impl_from_IMimeSecurity(iface);
3172 LONG ref = InterlockedIncrement(&This->ref);
3174 TRACE("(%p) ref=%d\n", This, ref);
3176 return ref;
3179 static ULONG WINAPI MimeSecurity_Release(IMimeSecurity *iface)
3181 MimeSecurity *This = impl_from_IMimeSecurity(iface);
3182 LONG ref = InterlockedDecrement(&This->ref);
3184 TRACE("(%p) ref=%d\n", This, ref);
3186 if (!ref)
3187 HeapFree(GetProcessHeap(), 0, This);
3189 return ref;
3192 static HRESULT WINAPI MimeSecurity_InitNew(
3193 IMimeSecurity* iface)
3195 FIXME("(%p)->(): stub\n", iface);
3196 return S_OK;
3199 static HRESULT WINAPI MimeSecurity_CheckInit(
3200 IMimeSecurity* iface)
3202 FIXME("(%p)->(): stub\n", iface);
3203 return E_NOTIMPL;
3206 static HRESULT WINAPI MimeSecurity_EncodeMessage(
3207 IMimeSecurity* iface,
3208 IMimeMessageTree* pTree,
3209 DWORD dwFlags)
3211 FIXME("(%p)->(%p, %08x): stub\n", iface, pTree, dwFlags);
3212 return E_NOTIMPL;
3215 static HRESULT WINAPI MimeSecurity_EncodeBody(
3216 IMimeSecurity* iface,
3217 IMimeMessageTree* pTree,
3218 HBODY hEncodeRoot,
3219 DWORD dwFlags)
3221 FIXME("(%p)->(%p, %p, %08x): stub\n", iface, pTree, hEncodeRoot, dwFlags);
3222 return E_NOTIMPL;
3225 static HRESULT WINAPI MimeSecurity_DecodeMessage(
3226 IMimeSecurity* iface,
3227 IMimeMessageTree* pTree,
3228 DWORD dwFlags)
3230 FIXME("(%p)->(%p, %08x): stub\n", iface, pTree, dwFlags);
3231 return E_NOTIMPL;
3234 static HRESULT WINAPI MimeSecurity_DecodeBody(
3235 IMimeSecurity* iface,
3236 IMimeMessageTree* pTree,
3237 HBODY hDecodeRoot,
3238 DWORD dwFlags)
3240 FIXME("(%p)->(%p, %p, %08x): stub\n", iface, pTree, hDecodeRoot, dwFlags);
3241 return E_NOTIMPL;
3244 static HRESULT WINAPI MimeSecurity_EnumCertificates(
3245 IMimeSecurity* iface,
3246 HCAPICERTSTORE hc,
3247 DWORD dwUsage,
3248 PCX509CERT pPrev,
3249 PCX509CERT* ppCert)
3251 FIXME("(%p)->(%p, %08x, %p, %p): stub\n", iface, hc, dwUsage, pPrev, ppCert);
3252 return E_NOTIMPL;
3255 static HRESULT WINAPI MimeSecurity_GetCertificateName(
3256 IMimeSecurity* iface,
3257 const PCX509CERT pX509Cert,
3258 const CERTNAMETYPE cn,
3259 LPSTR* ppszName)
3261 FIXME("(%p)->(%p, %08x, %p): stub\n", iface, pX509Cert, cn, ppszName);
3262 return E_NOTIMPL;
3265 static HRESULT WINAPI MimeSecurity_GetMessageType(
3266 IMimeSecurity* iface,
3267 const HWND hwndParent,
3268 IMimeBody* pBody,
3269 DWORD* pdwSecType)
3271 FIXME("(%p)->(%p, %p, %p): stub\n", iface, hwndParent, pBody, pdwSecType);
3272 return E_NOTIMPL;
3275 static HRESULT WINAPI MimeSecurity_GetCertData(
3276 IMimeSecurity* iface,
3277 const PCX509CERT pX509Cert,
3278 const CERTDATAID dataid,
3279 LPPROPVARIANT pValue)
3281 FIXME("(%p)->(%p, %x, %p): stub\n", iface, pX509Cert, dataid, pValue);
3282 return E_NOTIMPL;
3286 static const IMimeSecurityVtbl MimeSecurityVtbl =
3288 MimeSecurity_QueryInterface,
3289 MimeSecurity_AddRef,
3290 MimeSecurity_Release,
3291 MimeSecurity_InitNew,
3292 MimeSecurity_CheckInit,
3293 MimeSecurity_EncodeMessage,
3294 MimeSecurity_EncodeBody,
3295 MimeSecurity_DecodeMessage,
3296 MimeSecurity_DecodeBody,
3297 MimeSecurity_EnumCertificates,
3298 MimeSecurity_GetCertificateName,
3299 MimeSecurity_GetMessageType,
3300 MimeSecurity_GetCertData
3303 HRESULT MimeSecurity_create(IUnknown *outer, void **obj)
3305 MimeSecurity *This;
3307 *obj = NULL;
3309 if (outer) return CLASS_E_NOAGGREGATION;
3311 This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
3312 if (!This) return E_OUTOFMEMORY;
3314 This->IMimeSecurity_iface.lpVtbl = &MimeSecurityVtbl;
3315 This->ref = 1;
3317 *obj = &This->IMimeSecurity_iface;
3318 return S_OK;
3321 /***********************************************************************
3322 * MimeOleCreateSecurity (INETCOMM.@)
3324 HRESULT WINAPI MimeOleCreateSecurity(IMimeSecurity **ppSecurity)
3326 return MimeSecurity_create(NULL, (void **)ppSecurity);
3329 static HRESULT WINAPI MimeAlloc_QueryInterface(
3330 IMimeAllocator* iface,
3331 REFIID riid,
3332 void **obj)
3334 TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), obj);
3336 if (IsEqualIID(riid, &IID_IUnknown) ||
3337 IsEqualIID(riid, &IID_IMalloc) ||
3338 IsEqualIID(riid, &IID_IMimeAllocator))
3340 *obj = iface;
3341 IMimeAllocator_AddRef(iface);
3342 return S_OK;
3345 FIXME("no interface for %s\n", debugstr_guid(riid));
3346 *obj = NULL;
3347 return E_NOINTERFACE;
3350 static ULONG WINAPI MimeAlloc_AddRef(
3351 IMimeAllocator* iface)
3353 return 2;
3356 static ULONG WINAPI MimeAlloc_Release(
3357 IMimeAllocator* iface)
3359 return 1;
3362 static LPVOID WINAPI MimeAlloc_Alloc(
3363 IMimeAllocator* iface,
3364 SIZE_T cb)
3366 return CoTaskMemAlloc(cb);
3369 static LPVOID WINAPI MimeAlloc_Realloc(
3370 IMimeAllocator* iface,
3371 LPVOID pv,
3372 SIZE_T cb)
3374 return CoTaskMemRealloc(pv, cb);
3377 static void WINAPI MimeAlloc_Free(
3378 IMimeAllocator* iface,
3379 LPVOID pv)
3381 CoTaskMemFree(pv);
3384 static SIZE_T WINAPI MimeAlloc_GetSize(
3385 IMimeAllocator* iface,
3386 LPVOID pv)
3388 FIXME("stub\n");
3389 return 0;
3392 static int WINAPI MimeAlloc_DidAlloc(
3393 IMimeAllocator* iface,
3394 LPVOID pv)
3396 FIXME("stub\n");
3397 return 0;
3400 static void WINAPI MimeAlloc_HeapMinimize(
3401 IMimeAllocator* iface)
3403 FIXME("stub\n");
3404 return;
3407 static HRESULT WINAPI MimeAlloc_FreeParamInfoArray(
3408 IMimeAllocator* iface,
3409 ULONG cParams,
3410 LPMIMEPARAMINFO prgParam,
3411 boolean fFreeArray)
3413 ULONG i;
3414 TRACE("(%p)->(%d, %p, %d)\n", iface, cParams, prgParam, fFreeArray);
3416 for(i = 0; i < cParams; i++)
3418 IMimeAllocator_Free(iface, prgParam[i].pszName);
3419 IMimeAllocator_Free(iface, prgParam[i].pszData);
3421 if(fFreeArray) IMimeAllocator_Free(iface, prgParam);
3422 return S_OK;
3425 static HRESULT WINAPI MimeAlloc_FreeAddressList(
3426 IMimeAllocator* iface,
3427 LPADDRESSLIST pList)
3429 FIXME("stub\n");
3430 return E_NOTIMPL;
3433 static HRESULT WINAPI MimeAlloc_FreeAddressProps(
3434 IMimeAllocator* iface,
3435 LPADDRESSPROPS pAddress)
3437 FIXME("stub\n");
3438 return E_NOTIMPL;
3441 static HRESULT WINAPI MimeAlloc_ReleaseObjects(
3442 IMimeAllocator* iface,
3443 ULONG cObjects,
3444 IUnknown **prgpUnknown,
3445 boolean fFreeArray)
3447 FIXME("stub\n");
3448 return E_NOTIMPL;
3452 static HRESULT WINAPI MimeAlloc_FreeEnumHeaderRowArray(
3453 IMimeAllocator* iface,
3454 ULONG cRows,
3455 LPENUMHEADERROW prgRow,
3456 boolean fFreeArray)
3458 FIXME("stub\n");
3459 return E_NOTIMPL;
3462 static HRESULT WINAPI MimeAlloc_FreeEnumPropertyArray(
3463 IMimeAllocator* iface,
3464 ULONG cProps,
3465 LPENUMPROPERTY prgProp,
3466 boolean fFreeArray)
3468 FIXME("stub\n");
3469 return E_NOTIMPL;
3472 static HRESULT WINAPI MimeAlloc_FreeThumbprint(
3473 IMimeAllocator* iface,
3474 THUMBBLOB *pthumbprint)
3476 FIXME("stub\n");
3477 return E_NOTIMPL;
3481 static HRESULT WINAPI MimeAlloc_PropVariantClear(
3482 IMimeAllocator* iface,
3483 LPPROPVARIANT pProp)
3485 FIXME("stub\n");
3486 return E_NOTIMPL;
3489 static IMimeAllocatorVtbl mime_alloc_vtbl =
3491 MimeAlloc_QueryInterface,
3492 MimeAlloc_AddRef,
3493 MimeAlloc_Release,
3494 MimeAlloc_Alloc,
3495 MimeAlloc_Realloc,
3496 MimeAlloc_Free,
3497 MimeAlloc_GetSize,
3498 MimeAlloc_DidAlloc,
3499 MimeAlloc_HeapMinimize,
3500 MimeAlloc_FreeParamInfoArray,
3501 MimeAlloc_FreeAddressList,
3502 MimeAlloc_FreeAddressProps,
3503 MimeAlloc_ReleaseObjects,
3504 MimeAlloc_FreeEnumHeaderRowArray,
3505 MimeAlloc_FreeEnumPropertyArray,
3506 MimeAlloc_FreeThumbprint,
3507 MimeAlloc_PropVariantClear
3510 static IMimeAllocator mime_allocator =
3512 &mime_alloc_vtbl
3515 HRESULT MimeAllocator_create(IUnknown *outer, void **obj)
3517 if(outer) return CLASS_E_NOAGGREGATION;
3519 *obj = &mime_allocator;
3520 return S_OK;
3523 HRESULT WINAPI MimeOleGetAllocator(IMimeAllocator **alloc)
3525 return MimeAllocator_create(NULL, (void**)alloc);
3528 HRESULT VirtualStream_create(IUnknown *outer, void **obj)
3530 FIXME("(%p, %p)\n", outer, obj);
3532 *obj = NULL;
3533 if (outer) return CLASS_E_NOAGGREGATION;
3535 return MimeOleCreateVirtualStream((IStream **)obj);
3538 /* IMimePropertySchema Interface */
3539 static HRESULT WINAPI propschema_QueryInterface(IMimePropertySchema *iface, REFIID riid, void **out)
3541 propschema *This = impl_from_IMimePropertySchema(iface);
3542 TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), out);
3544 *out = NULL;
3546 if (IsEqualIID(riid, &IID_IUnknown) ||
3547 IsEqualIID(riid, &IID_IMimePropertySchema))
3549 *out = iface;
3551 else
3553 FIXME("no interface for %s\n", debugstr_guid(riid));
3554 return E_NOINTERFACE;
3557 IMimePropertySchema_AddRef(iface);
3558 return S_OK;
3561 static ULONG WINAPI propschema_AddRef(IMimePropertySchema *iface)
3563 propschema *This = impl_from_IMimePropertySchema(iface);
3564 LONG ref = InterlockedIncrement(&This->ref);
3566 TRACE("(%p) ref=%d\n", This, ref);
3568 return ref;
3571 static ULONG WINAPI propschema_Release(IMimePropertySchema *iface)
3573 propschema *This = impl_from_IMimePropertySchema(iface);
3574 LONG ref = InterlockedDecrement(&This->ref);
3576 TRACE("(%p) ref=%d\n", This, ref);
3578 if (!ref)
3580 HeapFree(GetProcessHeap(), 0, This);
3583 return ref;
3586 static HRESULT WINAPI propschema_RegisterProperty(IMimePropertySchema *iface, const char *name, DWORD flags,
3587 DWORD rownumber, VARTYPE vtdefault, DWORD *propid)
3589 propschema *This = impl_from_IMimePropertySchema(iface);
3590 FIXME("(%p)->(%s, %x, %d, %d, %p) stub\n", This, debugstr_a(name), flags, rownumber, vtdefault, propid);
3591 return E_NOTIMPL;
3594 static HRESULT WINAPI propschema_ModifyProperty(IMimePropertySchema *iface, const char *name, DWORD flags,
3595 DWORD rownumber, VARTYPE vtdefault)
3597 propschema *This = impl_from_IMimePropertySchema(iface);
3598 FIXME("(%p)->(%s, %x, %d, %d) stub\n", This, debugstr_a(name), flags, rownumber, vtdefault);
3599 return S_OK;
3602 static HRESULT WINAPI propschema_GetPropertyId(IMimePropertySchema *iface, const char *name, DWORD *propid)
3604 propschema *This = impl_from_IMimePropertySchema(iface);
3605 FIXME("(%p)->(%s, %p) stub\n", This, debugstr_a(name), propid);
3606 return E_NOTIMPL;
3609 static HRESULT WINAPI propschema_GetPropertyName(IMimePropertySchema *iface, DWORD propid, char **name)
3611 propschema *This = impl_from_IMimePropertySchema(iface);
3612 FIXME("(%p)->(%d, %p) stub\n", This, propid, name);
3613 return E_NOTIMPL;
3616 static HRESULT WINAPI propschema_RegisterAddressType(IMimePropertySchema *iface, const char *name, DWORD *adrtype)
3618 propschema *This = impl_from_IMimePropertySchema(iface);
3619 FIXME("(%p)->(%s, %p) stub\n", This, debugstr_a(name), adrtype);
3620 return E_NOTIMPL;
3623 static IMimePropertySchemaVtbl prop_schema_vtbl =
3625 propschema_QueryInterface,
3626 propschema_AddRef,
3627 propschema_Release,
3628 propschema_RegisterProperty,
3629 propschema_ModifyProperty,
3630 propschema_GetPropertyId,
3631 propschema_GetPropertyName,
3632 propschema_RegisterAddressType
3636 HRESULT WINAPI MimeOleGetPropertySchema(IMimePropertySchema **schema)
3638 propschema *This;
3640 TRACE("(%p) stub\n", schema);
3642 This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
3643 if (!This)
3644 return E_OUTOFMEMORY;
3646 This->IMimePropertySchema_iface.lpVtbl = &prop_schema_vtbl;
3647 This->ref = 1;
3649 *schema = &This->IMimePropertySchema_iface;
3651 return S_OK;
3654 HRESULT WINAPI MimeGetAddressFormatW(REFIID riid, void *object, DWORD addr_type,
3655 ADDRESSFORMAT addr_format, WCHAR **address)
3657 FIXME("(%s, %p, %d, %d, %p) stub\n", debugstr_guid(riid), object, addr_type, addr_format, address);
3659 return E_NOTIMPL;
3662 static HRESULT WINAPI mime_obj_QueryInterface(IUnknown *iface, REFIID riid, void **ppv)
3664 FIXME("(%s %p)\n", debugstr_guid(riid), ppv);
3665 *ppv = NULL;
3666 return E_NOINTERFACE;
3669 static ULONG WINAPI mime_obj_AddRef(IUnknown *iface)
3671 TRACE("\n");
3672 return 2;
3675 static ULONG WINAPI mime_obj_Release(IUnknown *iface)
3677 TRACE("\n");
3678 return 1;
3681 static const IUnknownVtbl mime_obj_vtbl = {
3682 mime_obj_QueryInterface,
3683 mime_obj_AddRef,
3684 mime_obj_Release
3687 static IUnknown mime_obj = { &mime_obj_vtbl };
3689 HRESULT WINAPI MimeOleObjectFromMoniker(BINDF bindf, IMoniker *moniker, IBindCtx *binding,
3690 REFIID riid, void **out, IMoniker **moniker_new)
3692 WCHAR *display_name, *mhtml_url;
3693 size_t len;
3694 HRESULT hres;
3696 static const WCHAR mhtml_prefixW[] = {'m','h','t','m','l',':'};
3698 WARN("(0x%08x, %p, %p, %s, %p, %p) semi-stub\n", bindf, moniker, binding, debugstr_guid(riid), out, moniker_new);
3700 if(!IsEqualGUID(&IID_IUnknown, riid)) {
3701 FIXME("Unsupported riid %s\n", debugstr_guid(riid));
3702 return E_NOINTERFACE;
3705 hres = IMoniker_GetDisplayName(moniker, NULL, NULL, &display_name);
3706 if(FAILED(hres))
3707 return hres;
3709 TRACE("display name %s\n", debugstr_w(display_name));
3711 len = strlenW(display_name);
3712 mhtml_url = heap_alloc((len+1)*sizeof(WCHAR) + sizeof(mhtml_prefixW));
3713 if(!mhtml_url)
3714 return E_OUTOFMEMORY;
3716 memcpy(mhtml_url, mhtml_prefixW, sizeof(mhtml_prefixW));
3717 strcpyW(mhtml_url + sizeof(mhtml_prefixW)/sizeof(WCHAR), display_name);
3718 HeapFree(GetProcessHeap(), 0, display_name);
3720 hres = CreateURLMoniker(NULL, mhtml_url, moniker_new);
3721 heap_free(mhtml_url);
3722 if(FAILED(hres))
3723 return hres;
3725 /* FIXME: We most likely should start binding here and return something more meaningful as mime object. */
3726 *out = &mime_obj;
3727 return S_OK;