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
23 #define NONAMELESSUNION
35 #include "wine/list.h"
36 #include "wine/debug.h"
38 #include "inetcomm_private.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(inetcomm);
46 DWORD flags; /* MIMEPROPFLAGS */
54 } property_list_entry_t;
56 static const property_t default_props[] =
58 {"References", PID_HDR_REFS, 0, VT_LPSTR},
59 {"Subject", PID_HDR_SUBJECT, 0, VT_LPSTR},
60 {"From", PID_HDR_FROM, MPF_ADDRESS, VT_LPSTR},
61 {"Message-ID", PID_HDR_MESSAGEID, 0, VT_LPSTR},
62 {"Return-Path", PID_HDR_RETURNPATH, MPF_ADDRESS, VT_LPSTR},
63 {"Date", PID_HDR_DATE, 0, VT_LPSTR},
64 {"Received", PID_HDR_RECEIVED, 0, VT_LPSTR},
65 {"Reply-To", PID_HDR_REPLYTO, MPF_ADDRESS, VT_LPSTR},
66 {"X-Mailer", PID_HDR_XMAILER, 0, VT_LPSTR},
67 {"Bcc", PID_HDR_BCC, MPF_ADDRESS, VT_LPSTR},
68 {"MIME-Version", PID_HDR_MIMEVER, MPF_MIME, VT_LPSTR},
69 {"Content-Type", PID_HDR_CNTTYPE, MPF_MIME | MPF_HASPARAMS, VT_LPSTR},
70 {"Content-Transfer-Encoding", PID_HDR_CNTXFER, MPF_MIME, VT_LPSTR},
71 {"Content-ID", PID_HDR_CNTID, MPF_MIME, VT_LPSTR},
72 {"Content-Disposition", PID_HDR_CNTDISP, MPF_MIME | MPF_HASPARAMS, VT_LPSTR},
73 {"To", PID_HDR_TO, MPF_ADDRESS, VT_LPSTR},
74 {"Cc", PID_HDR_CC, MPF_ADDRESS, VT_LPSTR},
75 {"Sender", PID_HDR_SENDER, MPF_ADDRESS, VT_LPSTR},
76 {"In-Reply-To", PID_HDR_INREPLYTO, 0, VT_LPSTR},
90 const property_t *prop;
95 typedef struct MimeBody
97 const IMimeBodyVtbl *lpVtbl;
103 struct list new_props; /* FIXME: This should be in a PropertySchema */
105 char *content_pri_type;
106 char *content_sub_type;
107 ENCODINGTYPE encoding;
110 BODYOFFSETS body_offsets;
113 static inline MimeBody *impl_from_IMimeBody( IMimeBody *iface )
115 return (MimeBody *)((char*)iface - FIELD_OFFSET(MimeBody, lpVtbl));
118 static LPSTR strdupA(LPCSTR str)
121 int len = strlen(str);
122 ret = HeapAlloc(GetProcessHeap(), 0, len + 1);
123 memcpy(ret, str, len + 1);
127 #define PARSER_BUF_SIZE 1024
129 /*****************************************************
130 * copy_headers_to_buf [internal]
132 * Copies the headers into a '\0' terminated memory block and leave
133 * the stream's current position set to after the blank line.
135 static HRESULT copy_headers_to_buf(IStream *stm, char **ptr)
138 DWORD size = PARSER_BUF_SIZE, offset = 0, last_end = 0;
150 buf = HeapAlloc(GetProcessHeap(), 0, size + 1);
154 buf = HeapReAlloc(GetProcessHeap(), 0, buf, size + 1);
162 hr = IStream_Read(stm, buf + offset, size - offset, &read);
163 if(FAILED(hr)) goto fail;
168 if(read == 0) done = 1;
170 while(!done && (end = strstr(buf + last_end, "\r\n")))
172 DWORD new_end = end - buf + 2;
173 if(new_end - last_end == 2)
176 off.QuadPart = new_end;
177 IStream_Seek(stm, off, STREAM_SEEK_SET, NULL);
190 HeapFree(GetProcessHeap(), 0, buf);
194 static header_t *read_prop(MimeBody *body, char **ptr)
196 char *colon = strchr(*ptr, ':');
197 const property_t *prop;
200 if(!colon) return NULL;
204 for(prop = default_props; prop->name; prop++)
206 if(!strcasecmp(*ptr, prop->name))
208 TRACE("%s: found match with default property id %d\n", *ptr, prop->id);
215 property_list_entry_t *prop_entry;
216 LIST_FOR_EACH_ENTRY(prop_entry, &body->new_props, property_list_entry_t, entry)
218 if(!strcasecmp(*ptr, prop_entry->prop.name))
220 TRACE("%s: found match with already added new property id %d\n", *ptr, prop_entry->prop.id);
221 prop = &prop_entry->prop;
227 prop_entry = HeapAlloc(GetProcessHeap(), 0, sizeof(*prop_entry));
228 prop_entry->prop.name = strdupA(*ptr);
229 prop_entry->prop.id = body->next_prop_id++;
230 prop_entry->prop.flags = 0;
231 prop_entry->prop.default_vt = VT_LPSTR;
232 list_add_tail(&body->new_props, &prop_entry->entry);
233 prop = &prop_entry->prop;
234 TRACE("%s: allocating new prop id %d\n", *ptr, prop_entry->prop.id);
238 ret = HeapAlloc(GetProcessHeap(), 0, sizeof(*ret));
240 PropVariantInit(&ret->value);
241 list_init(&ret->params);
247 static void unfold_header(char *header, int len)
249 char *start = header, *cp = header;
252 while(*cp == ' ' || *cp == '\t')
258 memmove(start, cp, len + 1);
260 cp = strstr(start, "\r\n");
267 } while(*cp == ' ' || *cp == '\t');
272 static char *unquote_string(const char *str)
277 while(*str == ' ' || *str == '\t') str++;
285 for(cp = ret; *cp; cp++)
288 memmove(cp, cp + 1, strlen(cp + 1) + 1);
293 WARN("quote in unquoted string\n");
305 static void add_param(header_t *header, const char *p)
307 const char *key = p, *value, *cp = p;
311 TRACE("got param %s\n", p);
313 while (*key == ' ' || *key == '\t' ) key++;
315 cp = strchr(key, '=');
318 WARN("malformed parameter - skipping\n");
322 name = HeapAlloc(GetProcessHeap(), 0, cp - key + 1);
323 memcpy(name, key, cp - key);
324 name[cp - key] = '\0';
328 param = HeapAlloc(GetProcessHeap(), 0, sizeof(*param));
330 param->value = unquote_string(value);
331 list_add_tail(&header->params, ¶m->entry);
334 static void split_params(header_t *header, char *value)
336 char *cp = value, *start = value;
342 if(!in_quote && *cp == ';')
345 if(done_value) add_param(header, start);
350 in_quote = !in_quote;
353 if(done_value) add_param(header, start);
356 static void read_value(header_t *header, char **cur)
358 char *end = *cur, *value;
362 end = strstr(end, "\r\n");
364 } while(*end == ' ' || *end == '\t');
367 value = HeapAlloc(GetProcessHeap(), 0, len + 1);
368 memcpy(value, *cur, len);
371 unfold_header(value, len);
372 TRACE("value %s\n", debugstr_a(value));
374 if(header->prop->flags & MPF_HASPARAMS)
376 split_params(header, value);
377 TRACE("value w/o params %s\n", debugstr_a(value));
380 header->value.vt = VT_LPSTR;
381 header->value.u.pszVal = value;
386 static void init_content_type(MimeBody *body, header_t *header)
391 if(header->prop->id != PID_HDR_CNTTYPE)
393 ERR("called with header %s\n", header->prop->name);
397 slash = strchr(header->value.u.pszVal, '/');
400 WARN("malformed context type value\n");
403 len = slash - header->value.u.pszVal;
404 body->content_pri_type = HeapAlloc(GetProcessHeap(), 0, len + 1);
405 memcpy(body->content_pri_type, header->value.u.pszVal, len);
406 body->content_pri_type[len] = '\0';
407 body->content_sub_type = strdupA(slash + 1);
410 static HRESULT parse_headers(MimeBody *body, IStream *stm)
412 char *header_buf, *cur_header_ptr;
416 hr = copy_headers_to_buf(stm, &header_buf);
417 if(FAILED(hr)) return hr;
419 cur_header_ptr = header_buf;
420 while((header = read_prop(body, &cur_header_ptr)))
422 read_value(header, &cur_header_ptr);
423 list_add_tail(&body->headers, &header->entry);
425 if(header->prop->id == PID_HDR_CNTTYPE)
426 init_content_type(body, header);
429 HeapFree(GetProcessHeap(), 0, header_buf);
433 static void empty_param_list(struct list *list)
435 param_t *param, *cursor2;
437 LIST_FOR_EACH_ENTRY_SAFE(param, cursor2, list, param_t, entry)
439 list_remove(¶m->entry);
440 HeapFree(GetProcessHeap(), 0, param->name);
441 HeapFree(GetProcessHeap(), 0, param->value);
442 HeapFree(GetProcessHeap(), 0, param);
446 static void empty_header_list(struct list *list)
448 header_t *header, *cursor2;
450 LIST_FOR_EACH_ENTRY_SAFE(header, cursor2, list, header_t, entry)
452 list_remove(&header->entry);
453 PropVariantClear(&header->value);
454 empty_param_list(&header->params);
455 HeapFree(GetProcessHeap(), 0, header);
459 static void empty_new_prop_list(struct list *list)
461 property_list_entry_t *prop, *cursor2;
463 LIST_FOR_EACH_ENTRY_SAFE(prop, cursor2, list, property_list_entry_t, entry)
465 list_remove(&prop->entry);
466 HeapFree(GetProcessHeap(), 0, (char *)prop->prop.name);
467 HeapFree(GetProcessHeap(), 0, prop);
471 static void release_data(REFIID riid, void *data)
475 if(IsEqualIID(riid, &IID_IStream))
476 IStream_Release((IStream *)data);
478 FIXME("Unhandled data format %s\n", debugstr_guid(riid));
481 static HRESULT find_prop(MimeBody *body, const char *name, header_t **prop)
487 LIST_FOR_EACH_ENTRY(header, &body->headers, header_t, entry)
489 if(!strcasecmp(name, header->prop->name))
496 return MIME_E_NOT_FOUND;
499 static HRESULT WINAPI MimeBody_QueryInterface(IMimeBody* iface,
503 TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppvObject);
507 if (IsEqualIID(riid, &IID_IUnknown) ||
508 IsEqualIID(riid, &IID_IPersist) ||
509 IsEqualIID(riid, &IID_IPersistStreamInit) ||
510 IsEqualIID(riid, &IID_IMimePropertySet) ||
511 IsEqualIID(riid, &IID_IMimeBody))
518 IUnknown_AddRef((IUnknown*)*ppvObject);
522 FIXME("no interface for %s\n", debugstr_guid(riid));
523 return E_NOINTERFACE;
526 static ULONG WINAPI MimeBody_AddRef(IMimeBody* iface)
528 MimeBody *This = impl_from_IMimeBody(iface);
529 TRACE("(%p)->()\n", iface);
530 return InterlockedIncrement(&This->refs);
533 static ULONG WINAPI MimeBody_Release(IMimeBody* iface)
535 MimeBody *This = impl_from_IMimeBody(iface);
538 TRACE("(%p)->()\n", iface);
540 refs = InterlockedDecrement(&This->refs);
543 empty_header_list(&This->headers);
544 empty_new_prop_list(&This->new_props);
546 HeapFree(GetProcessHeap(), 0, This->content_pri_type);
547 HeapFree(GetProcessHeap(), 0, This->content_sub_type);
549 release_data(&This->data_iid, This->data);
551 HeapFree(GetProcessHeap(), 0, This);
557 static HRESULT WINAPI MimeBody_GetClassID(
566 static HRESULT WINAPI MimeBody_IsDirty(
573 static HRESULT WINAPI MimeBody_Load(
577 MimeBody *This = impl_from_IMimeBody(iface);
578 TRACE("(%p)->(%p)\n", iface, pStm);
579 return parse_headers(This, pStm);
582 static HRESULT WINAPI MimeBody_Save(
591 static HRESULT WINAPI MimeBody_GetSizeMax(
593 ULARGE_INTEGER* pcbSize)
599 static HRESULT WINAPI MimeBody_InitNew(
602 TRACE("%p->()\n", iface);
606 static HRESULT WINAPI MimeBody_GetPropInfo(
609 LPMIMEPROPINFO pInfo)
615 static HRESULT WINAPI MimeBody_SetPropInfo(
618 LPCMIMEPROPINFO pInfo)
624 static HRESULT WINAPI MimeBody_GetProp(
628 LPPROPVARIANT pValue)
630 MimeBody *This = impl_from_IMimeBody(iface);
631 TRACE("(%p)->(%s, %d, %p)\n", This, pszName, dwFlags, pValue);
633 if(!strcasecmp(pszName, "att:pri-content-type"))
635 PropVariantClear(pValue);
636 pValue->vt = VT_LPSTR;
637 pValue->u.pszVal = strdupA(This->content_pri_type);
645 static HRESULT WINAPI MimeBody_SetProp(
649 LPCPROPVARIANT pValue)
655 static HRESULT WINAPI MimeBody_AppendProp(
659 LPPROPVARIANT pValue)
665 static HRESULT WINAPI MimeBody_DeleteProp(
673 static HRESULT WINAPI MimeBody_CopyProps(
677 IMimePropertySet* pPropertySet)
683 static HRESULT WINAPI MimeBody_MoveProps(
687 IMimePropertySet* pPropertySet)
693 static HRESULT WINAPI MimeBody_DeleteExcept(
702 static HRESULT WINAPI MimeBody_QueryProp(
707 boolean fCaseSensitive)
713 static HRESULT WINAPI MimeBody_GetCharset(
715 LPHCHARSET phCharset)
722 static HRESULT WINAPI MimeBody_SetCharset(
725 CSETAPPLYTYPE applytype)
731 static HRESULT WINAPI MimeBody_GetParameters(
735 LPMIMEPARAMINFO* pprgParam)
737 MimeBody *This = impl_from_IMimeBody(iface);
741 TRACE("(%p)->(%s, %p, %p)\n", iface, debugstr_a(pszName), pcParams, pprgParam);
746 hr = find_prop(This, pszName, &header);
747 if(hr != S_OK) return hr;
749 *pcParams = list_count(&header->params);
752 IMimeAllocator *alloc;
756 MimeOleGetAllocator(&alloc);
758 *pprgParam = info = IMimeAllocator_Alloc(alloc, *pcParams * sizeof(**pprgParam));
759 LIST_FOR_EACH_ENTRY(param, &header->params, param_t, entry)
763 len = strlen(param->name) + 1;
764 info->pszName = IMimeAllocator_Alloc(alloc, len);
765 memcpy(info->pszName, param->name, len);
766 len = strlen(param->value) + 1;
767 info->pszData = IMimeAllocator_Alloc(alloc, len);
768 memcpy(info->pszData, param->value, len);
771 IMimeAllocator_Release(alloc);
776 static HRESULT WINAPI MimeBody_IsContentType(
781 MimeBody *This = impl_from_IMimeBody(iface);
783 TRACE("(%p)->(%s, %s)\n", This, debugstr_a(pszPriType), debugstr_a(pszSubType));
786 const char *pri = This->content_pri_type;
787 if(!pri) pri = "text";
788 if(strcasecmp(pri, pszPriType)) return S_FALSE;
793 const char *sub = This->content_sub_type;
794 if(!sub) sub = "plain";
795 if(strcasecmp(sub, pszSubType)) return S_FALSE;
801 static HRESULT WINAPI MimeBody_BindToObject(
810 static HRESULT WINAPI MimeBody_Clone(
812 IMimePropertySet** ppPropertySet)
818 static HRESULT WINAPI MimeBody_SetOption(
821 LPCPROPVARIANT pValue)
823 HRESULT hr = E_NOTIMPL;
824 TRACE("(%p)->(%08x, %p)\n", iface, oid, pValue);
826 if(pValue->vt != TYPEDID_TYPE(oid))
828 WARN("Called with vartype %04x and oid %08x\n", pValue->vt, oid);
834 case OID_SECURITY_HWND_OWNER:
835 FIXME("OID_SECURITY_HWND_OWNER (value %08x): ignoring\n", pValue->u.ulVal);
839 FIXME("Unhandled oid %08x\n", oid);
845 static HRESULT WINAPI MimeBody_GetOption(
848 LPPROPVARIANT pValue)
850 FIXME("(%p)->(%08x, %p): stub\n", iface, oid, pValue);
854 static HRESULT WINAPI MimeBody_EnumProps(
857 IMimeEnumProperties** ppEnum)
863 static HRESULT WINAPI MimeBody_IsType(
865 IMSGBODYTYPE bodytype)
867 MimeBody *This = impl_from_IMimeBody(iface);
869 TRACE("(%p)->(%d)\n", iface, bodytype);
873 return This->data ? S_FALSE : S_OK;
875 FIXME("Unimplemented bodytype %d - returning S_OK\n", bodytype);
880 static HRESULT WINAPI MimeBody_SetDisplayName(
888 static HRESULT WINAPI MimeBody_GetDisplayName(
896 static HRESULT WINAPI MimeBody_GetOffsets(
898 LPBODYOFFSETS pOffsets)
900 MimeBody *This = impl_from_IMimeBody(iface);
901 TRACE("(%p)->(%p)\n", This, pOffsets);
903 *pOffsets = This->body_offsets;
905 if(This->body_offsets.cbBodyEnd == 0) return MIME_E_NO_DATA;
909 static HRESULT WINAPI MimeBody_GetCurrentEncoding(
911 ENCODINGTYPE* pietEncoding)
913 MimeBody *This = impl_from_IMimeBody(iface);
915 TRACE("(%p)->(%p)\n", This, pietEncoding);
917 *pietEncoding = This->encoding;
921 static HRESULT WINAPI MimeBody_SetCurrentEncoding(
923 ENCODINGTYPE ietEncoding)
925 MimeBody *This = impl_from_IMimeBody(iface);
927 TRACE("(%p)->(%d)\n", This, ietEncoding);
929 This->encoding = ietEncoding;
933 static HRESULT WINAPI MimeBody_GetEstimatedSize(
935 ENCODINGTYPE ietEncoding,
942 static HRESULT WINAPI MimeBody_GetDataHere(
944 ENCODINGTYPE ietEncoding,
951 static HRESULT WINAPI MimeBody_GetData(
953 ENCODINGTYPE ietEncoding,
956 MimeBody *This = impl_from_IMimeBody(iface);
957 FIXME("(%p)->(%d, %p). Ignoring encoding type.\n", This, ietEncoding, ppStream);
959 *ppStream = This->data;
960 IStream_AddRef(*ppStream);
964 static HRESULT WINAPI MimeBody_SetData(
966 ENCODINGTYPE ietEncoding,
972 MimeBody *This = impl_from_IMimeBody(iface);
973 TRACE("(%p)->(%d, %s, %s, %s %p)\n", This, ietEncoding, debugstr_a(pszPriType), debugstr_a(pszSubType),
974 debugstr_guid(riid), pvObject);
976 if(IsEqualIID(riid, &IID_IStream))
977 IStream_AddRef((IStream *)pvObject);
980 FIXME("Unhandled object type %s\n", debugstr_guid(riid));
985 FIXME("release old data\n");
987 This->data_iid = *riid;
988 This->data = pvObject;
990 IMimeBody_SetCurrentEncoding(iface, ietEncoding);
992 /* FIXME: Update the content type.
993 If pszPriType == NULL use 'application'
994 If pszSubType == NULL use 'octet-stream' */
999 static HRESULT WINAPI MimeBody_EmptyData(
1006 static HRESULT WINAPI MimeBody_CopyTo(
1014 static HRESULT WINAPI MimeBody_GetTransmitInfo(
1016 LPTRANSMITINFO pTransmitInfo)
1022 static HRESULT WINAPI MimeBody_SaveToFile(
1024 ENCODINGTYPE ietEncoding,
1031 static HRESULT WINAPI MimeBody_GetHandle(
1035 MimeBody *This = impl_from_IMimeBody(iface);
1036 TRACE("(%p)->(%p)\n", iface, phBody);
1038 *phBody = This->handle;
1039 return This->handle ? S_OK : MIME_E_NO_DATA;
1042 static IMimeBodyVtbl body_vtbl =
1044 MimeBody_QueryInterface,
1047 MimeBody_GetClassID,
1051 MimeBody_GetSizeMax,
1053 MimeBody_GetPropInfo,
1054 MimeBody_SetPropInfo,
1057 MimeBody_AppendProp,
1058 MimeBody_DeleteProp,
1061 MimeBody_DeleteExcept,
1063 MimeBody_GetCharset,
1064 MimeBody_SetCharset,
1065 MimeBody_GetParameters,
1066 MimeBody_IsContentType,
1067 MimeBody_BindToObject,
1073 MimeBody_SetDisplayName,
1074 MimeBody_GetDisplayName,
1075 MimeBody_GetOffsets,
1076 MimeBody_GetCurrentEncoding,
1077 MimeBody_SetCurrentEncoding,
1078 MimeBody_GetEstimatedSize,
1079 MimeBody_GetDataHere,
1084 MimeBody_GetTransmitInfo,
1085 MimeBody_SaveToFile,
1089 static HRESULT MimeBody_set_offsets(MimeBody *body, const BODYOFFSETS *offsets)
1091 TRACE("setting offsets to %d, %d, %d, %d\n", offsets->cbBoundaryStart,
1092 offsets->cbHeaderStart, offsets->cbBodyStart, offsets->cbBodyEnd);
1094 body->body_offsets = *offsets;
1098 #define FIRST_CUSTOM_PROP_ID 0x100
1100 HRESULT MimeBody_create(IUnknown *outer, void **obj)
1103 BODYOFFSETS body_offsets;
1107 if(outer) return CLASS_E_NOAGGREGATION;
1109 This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
1110 if (!This) return E_OUTOFMEMORY;
1112 This->lpVtbl = &body_vtbl;
1114 This->handle = NULL;
1115 list_init(&This->headers);
1116 list_init(&This->new_props);
1117 This->next_prop_id = FIRST_CUSTOM_PROP_ID;
1118 This->content_pri_type = NULL;
1119 This->content_sub_type = NULL;
1120 This->encoding = IET_7BIT;
1122 This->data_iid = IID_NULL;
1124 body_offsets.cbBoundaryStart = body_offsets.cbHeaderStart = 0;
1125 body_offsets.cbBodyStart = body_offsets.cbBodyEnd = 0;
1126 MimeBody_set_offsets(This, &body_offsets);
1128 *obj = &This->lpVtbl;
1134 IStreamVtbl *lpVtbl;
1138 ULARGE_INTEGER pos, start, length;
1141 static inline sub_stream_t *impl_from_IStream( IStream *iface )
1143 return (sub_stream_t *)((char*)iface - FIELD_OFFSET(sub_stream_t, lpVtbl));
1146 static HRESULT WINAPI sub_stream_QueryInterface(
1151 sub_stream_t *This = impl_from_IStream(iface);
1153 TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), ppvObject);
1156 if(IsEqualIID(riid, &IID_IUnknown) ||
1157 IsEqualIID(riid, &IID_ISequentialStream) ||
1158 IsEqualIID(riid, &IID_IStream))
1160 IStream_AddRef(iface);
1164 return E_NOINTERFACE;
1167 static ULONG WINAPI sub_stream_AddRef(
1170 sub_stream_t *This = impl_from_IStream(iface);
1172 TRACE("(%p)\n", This);
1173 return InterlockedIncrement(&This->refs);
1176 static ULONG WINAPI sub_stream_Release(
1179 sub_stream_t *This = impl_from_IStream(iface);
1182 TRACE("(%p)\n", This);
1183 refs = InterlockedDecrement(&This->refs);
1186 IStream_Release(This->base);
1187 HeapFree(GetProcessHeap(), 0, This);
1192 static HRESULT WINAPI sub_stream_Read(
1198 sub_stream_t *This = impl_from_IStream(iface);
1200 ULARGE_INTEGER base_pos;
1201 LARGE_INTEGER tmp_pos;
1203 TRACE("(%p, %d, %p)\n", pv, cb, pcbRead);
1205 tmp_pos.QuadPart = 0;
1206 IStream_Seek(This->base, tmp_pos, STREAM_SEEK_CUR, &base_pos);
1207 tmp_pos.QuadPart = This->pos.QuadPart + This->start.QuadPart;
1208 IStream_Seek(This->base, tmp_pos, STREAM_SEEK_SET, NULL);
1210 if(This->pos.QuadPart + cb > This->length.QuadPart)
1211 cb = This->length.QuadPart - This->pos.QuadPart;
1213 hr = IStream_Read(This->base, pv, cb, pcbRead);
1215 This->pos.QuadPart += *pcbRead;
1217 tmp_pos.QuadPart = base_pos.QuadPart;
1218 IStream_Seek(This->base, tmp_pos, STREAM_SEEK_SET, NULL);
1223 static HRESULT WINAPI sub_stream_Write(
1233 static HRESULT WINAPI sub_stream_Seek(
1235 LARGE_INTEGER dlibMove,
1237 ULARGE_INTEGER *plibNewPosition)
1239 sub_stream_t *This = impl_from_IStream(iface);
1240 LARGE_INTEGER new_pos;
1242 TRACE("(%08x.%08x, %x, %p)\n", dlibMove.u.HighPart, dlibMove.u.LowPart, dwOrigin, plibNewPosition);
1246 case STREAM_SEEK_SET:
1249 case STREAM_SEEK_CUR:
1250 new_pos.QuadPart = This->pos.QuadPart + dlibMove.QuadPart;
1252 case STREAM_SEEK_END:
1253 new_pos.QuadPart = This->length.QuadPart + dlibMove.QuadPart;
1256 return STG_E_INVALIDFUNCTION;
1259 if(new_pos.QuadPart < 0) new_pos.QuadPart = 0;
1260 else if(new_pos.QuadPart > This->length.QuadPart) new_pos.QuadPart = This->length.QuadPart;
1262 This->pos.QuadPart = new_pos.QuadPart;
1264 if(plibNewPosition) *plibNewPosition = This->pos;
1268 static HRESULT WINAPI sub_stream_SetSize(
1270 ULARGE_INTEGER libNewSize)
1276 static HRESULT WINAPI sub_stream_CopyTo(
1280 ULARGE_INTEGER *pcbRead,
1281 ULARGE_INTEGER *pcbWritten)
1284 BYTE tmpBuffer[128];
1285 ULONG bytesRead, bytesWritten, copySize;
1286 ULARGE_INTEGER totalBytesRead;
1287 ULARGE_INTEGER totalBytesWritten;
1289 TRACE("(%p)->(%p, %d, %p, %p)\n", iface, pstm, cb.u.LowPart, pcbRead, pcbWritten);
1291 totalBytesRead.QuadPart = 0;
1292 totalBytesWritten.QuadPart = 0;
1294 while ( cb.QuadPart > 0 )
1296 if ( cb.QuadPart >= sizeof(tmpBuffer) )
1297 copySize = sizeof(tmpBuffer);
1299 copySize = cb.u.LowPart;
1301 hr = IStream_Read(iface, tmpBuffer, copySize, &bytesRead);
1302 if (FAILED(hr)) break;
1304 totalBytesRead.QuadPart += bytesRead;
1308 hr = IStream_Write(pstm, tmpBuffer, bytesRead, &bytesWritten);
1309 if (FAILED(hr)) break;
1310 totalBytesWritten.QuadPart += bytesWritten;
1313 if (bytesRead != copySize)
1316 cb.QuadPart -= bytesRead;
1319 if (pcbRead) pcbRead->QuadPart = totalBytesRead.QuadPart;
1320 if (pcbWritten) pcbWritten->QuadPart = totalBytesWritten.QuadPart;
1325 static HRESULT WINAPI sub_stream_Commit(
1327 DWORD grfCommitFlags)
1333 static HRESULT WINAPI sub_stream_Revert(
1340 static HRESULT WINAPI sub_stream_LockRegion(
1342 ULARGE_INTEGER libOffset,
1350 static HRESULT WINAPI sub_stream_UnlockRegion(
1352 ULARGE_INTEGER libOffset,
1360 static HRESULT WINAPI sub_stream_Stat(
1365 sub_stream_t *This = impl_from_IStream(iface);
1366 FIXME("(%p)->(%p, %08x)\n", This, pstatstg, grfStatFlag);
1367 memset(pstatstg, 0, sizeof(*pstatstg));
1368 pstatstg->cbSize = This->length;
1372 static HRESULT WINAPI sub_stream_Clone(
1380 static struct IStreamVtbl sub_stream_vtbl =
1382 sub_stream_QueryInterface,
1392 sub_stream_LockRegion,
1393 sub_stream_UnlockRegion,
1398 static HRESULT create_sub_stream(IStream *stream, ULARGE_INTEGER start, ULARGE_INTEGER length, IStream **out)
1403 This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
1404 if(!This) return E_OUTOFMEMORY;
1406 This->lpVtbl = &sub_stream_vtbl;
1408 This->start = start;
1409 This->length = length;
1410 This->pos.QuadPart = 0;
1411 IStream_AddRef(stream);
1412 This->base = stream;
1414 *out = (IStream*)&This->lpVtbl;
1419 typedef struct body_t
1423 IMimeBody *mime_body;
1425 struct body_t *parent;
1426 struct list children;
1429 typedef struct MimeMessage
1431 IMimeMessage IMimeMessage_iface;
1435 struct list body_tree;
1439 static inline MimeMessage *impl_from_IMimeMessage(IMimeMessage *iface)
1441 return CONTAINING_RECORD(iface, MimeMessage, IMimeMessage_iface);
1444 static HRESULT WINAPI MimeMessage_QueryInterface(IMimeMessage *iface, REFIID riid, void **ppv)
1446 TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppv);
1448 if (IsEqualIID(riid, &IID_IUnknown) ||
1449 IsEqualIID(riid, &IID_IPersist) ||
1450 IsEqualIID(riid, &IID_IPersistStreamInit) ||
1451 IsEqualIID(riid, &IID_IMimeMessageTree) ||
1452 IsEqualIID(riid, &IID_IMimeMessage))
1455 IMimeMessage_AddRef(iface);
1459 FIXME("no interface for %s\n", debugstr_guid(riid));
1461 return E_NOINTERFACE;
1464 static ULONG WINAPI MimeMessage_AddRef(IMimeMessage *iface)
1466 MimeMessage *This = impl_from_IMimeMessage(iface);
1467 ULONG ref = InterlockedIncrement(&This->ref);
1469 TRACE("(%p) ref=%d\n", This, ref);
1474 static void empty_body_list(struct list *list)
1476 body_t *body, *cursor2;
1477 LIST_FOR_EACH_ENTRY_SAFE(body, cursor2, list, body_t, entry)
1479 empty_body_list(&body->children);
1480 list_remove(&body->entry);
1481 IMimeBody_Release(body->mime_body);
1482 HeapFree(GetProcessHeap(), 0, body);
1486 static ULONG WINAPI MimeMessage_Release(IMimeMessage *iface)
1488 MimeMessage *This = impl_from_IMimeMessage(iface);
1489 ULONG ref = InterlockedDecrement(&This->ref);
1491 TRACE("(%p) ref=%d\n", This, ref);
1495 empty_body_list(&This->body_tree);
1497 if(This->stream) IStream_Release(This->stream);
1498 HeapFree(GetProcessHeap(), 0, This);
1504 /*** IPersist methods ***/
1505 static HRESULT WINAPI MimeMessage_GetClassID(
1506 IMimeMessage *iface,
1509 FIXME("(%p)->(%p)\n", iface, pClassID);
1513 /*** IPersistStreamInit methods ***/
1514 static HRESULT WINAPI MimeMessage_IsDirty(
1515 IMimeMessage *iface)
1517 FIXME("(%p)->()\n", iface);
1521 static body_t *new_body_entry(IMimeBody *mime_body, DWORD index, body_t *parent)
1523 body_t *body = HeapAlloc(GetProcessHeap(), 0, sizeof(*body));
1526 body->mime_body = mime_body;
1527 body->index = index;
1528 list_init(&body->children);
1529 body->parent = parent;
1537 BODYOFFSETS offsets;
1540 static HRESULT create_body_offset_list(IStream *stm, const char *boundary, struct list *body_offsets)
1544 int boundary_len = strlen(boundary);
1545 char *buf, *nl_boundary, *ptr, *overlap;
1546 DWORD start = 0, overlap_no;
1547 offset_entry_t *cur_body = NULL;
1551 list_init(body_offsets);
1552 nl_boundary = HeapAlloc(GetProcessHeap(), 0, 4 + boundary_len + 1);
1553 memcpy(nl_boundary, "\r\n--", 4);
1554 memcpy(nl_boundary + 4, boundary, boundary_len + 1);
1556 overlap_no = boundary_len + 5;
1558 overlap = buf = HeapAlloc(GetProcessHeap(), 0, overlap_no + PARSER_BUF_SIZE + 1);
1561 hr = IStream_Seek(stm, zero, STREAM_SEEK_CUR, &cur);
1562 start = cur.u.LowPart;
1565 hr = IStream_Read(stm, overlap, PARSER_BUF_SIZE, &read);
1566 if(FAILED(hr)) goto end;
1567 if(read == 0) break;
1568 overlap[read] = '\0';
1572 ptr = strstr(ptr, nl_boundary);
1575 DWORD boundary_start = start + ptr - buf;
1576 char *end = ptr + boundary_len + 4;
1578 if(*end == '\0' || *(end + 1) == '\0')
1581 if(*end == '\r' && *(end + 1) == '\n')
1585 cur_body->offsets.cbBodyEnd = boundary_start;
1586 list_add_tail(body_offsets, &cur_body->entry);
1588 cur_body = HeapAlloc(GetProcessHeap(), 0, sizeof(*cur_body));
1589 cur_body->offsets.cbBoundaryStart = boundary_start + 2; /* doesn't including the leading \r\n */
1590 cur_body->offsets.cbHeaderStart = boundary_start + boundary_len + 6;
1592 else if(*end == '-' && *(end + 1) == '-')
1596 cur_body->offsets.cbBodyEnd = boundary_start;
1597 list_add_tail(body_offsets, &cur_body->entry);
1605 if(overlap == buf) /* 1st iteration */
1607 memcpy(buf, buf + PARSER_BUF_SIZE - overlap_no, overlap_no);
1608 overlap = buf + overlap_no;
1609 start += read - overlap_no;
1613 memcpy(buf, buf + PARSER_BUF_SIZE, overlap_no);
1619 HeapFree(GetProcessHeap(), 0, nl_boundary);
1620 HeapFree(GetProcessHeap(), 0, buf);
1624 static body_t *create_sub_body(MimeMessage *msg, IStream *pStm, BODYOFFSETS *offset, body_t *parent)
1626 IMimeBody *mime_body;
1632 MimeBody_create(NULL, (void**)&mime_body);
1633 IMimeBody_Load(mime_body, pStm);
1635 hr = IStream_Seek(pStm, zero, STREAM_SEEK_CUR, &cur);
1636 offset->cbBodyStart = cur.u.LowPart + offset->cbHeaderStart;
1637 if(parent) MimeBody_set_offsets(impl_from_IMimeBody(mime_body), offset);
1638 IMimeBody_SetData(mime_body, IET_BINARY, NULL, NULL, &IID_IStream, pStm);
1639 body = new_body_entry(mime_body, msg->next_index++, parent);
1641 if(IMimeBody_IsContentType(mime_body, "multipart", NULL) == S_OK)
1643 MIMEPARAMINFO *param_info;
1645 IMimeAllocator *alloc;
1647 hr = IMimeBody_GetParameters(mime_body, "Content-Type", &count, ¶m_info);
1648 if(hr != S_OK || count == 0) return body;
1650 MimeOleGetAllocator(&alloc);
1652 for(i = 0; i < count; i++)
1654 if(!strcasecmp(param_info[i].pszName, "boundary"))
1656 struct list offset_list;
1657 offset_entry_t *cur, *cursor2;
1658 hr = create_body_offset_list(pStm, param_info[i].pszData, &offset_list);
1659 LIST_FOR_EACH_ENTRY_SAFE(cur, cursor2, &offset_list, offset_entry_t, entry)
1662 IStream *sub_stream;
1663 ULARGE_INTEGER start, length;
1665 start.QuadPart = cur->offsets.cbHeaderStart;
1666 length.QuadPart = cur->offsets.cbBodyEnd - cur->offsets.cbHeaderStart;
1667 create_sub_stream(pStm, start, length, &sub_stream);
1668 sub_body = create_sub_body(msg, sub_stream, &cur->offsets, body);
1669 IStream_Release(sub_stream);
1670 list_add_tail(&body->children, &sub_body->entry);
1671 list_remove(&cur->entry);
1672 HeapFree(GetProcessHeap(), 0, cur);
1677 IMimeAllocator_FreeParamInfoArray(alloc, count, param_info, TRUE);
1678 IMimeAllocator_Release(alloc);
1683 static HRESULT WINAPI MimeMessage_Load(IMimeMessage *iface, IStream *pStm)
1685 MimeMessage *This = impl_from_IMimeMessage(iface);
1687 BODYOFFSETS offsets;
1691 TRACE("(%p)->(%p)\n", iface, pStm);
1695 FIXME("already loaded a message\n");
1699 IStream_AddRef(pStm);
1700 This->stream = pStm;
1701 offsets.cbBoundaryStart = offsets.cbHeaderStart = 0;
1702 offsets.cbBodyStart = offsets.cbBodyEnd = 0;
1704 root_body = create_sub_body(This, pStm, &offsets, NULL);
1707 IStream_Seek(pStm, zero, STREAM_SEEK_END, &cur);
1708 offsets.cbBodyEnd = cur.u.LowPart;
1709 MimeBody_set_offsets(impl_from_IMimeBody(root_body->mime_body), &offsets);
1711 list_add_head(&This->body_tree, &root_body->entry);
1716 static HRESULT WINAPI MimeMessage_Save(
1717 IMimeMessage *iface,
1721 FIXME("(%p)->(%p, %s)\n", iface, pStm, fClearDirty ? "TRUE" : "FALSE");
1725 static HRESULT WINAPI MimeMessage_GetSizeMax(
1726 IMimeMessage *iface,
1727 ULARGE_INTEGER *pcbSize)
1729 FIXME("(%p)->(%p)\n", iface, pcbSize);
1733 static HRESULT WINAPI MimeMessage_InitNew(
1734 IMimeMessage *iface)
1736 FIXME("(%p)->()\n", iface);
1740 /*** IMimeMessageTree methods ***/
1741 static HRESULT WINAPI MimeMessage_GetMessageSource(IMimeMessage *iface, IStream **ppStream,
1744 MimeMessage *This = impl_from_IMimeMessage(iface);
1746 FIXME("(%p)->(%p, 0x%x)\n", iface, ppStream, dwFlags);
1748 IStream_AddRef(This->stream);
1749 *ppStream = This->stream;
1753 static HRESULT WINAPI MimeMessage_GetMessageSize(
1754 IMimeMessage *iface,
1758 FIXME("(%p)->(%p, 0x%x)\n", iface, pcbSize, dwFlags);
1762 static HRESULT WINAPI MimeMessage_LoadOffsetTable(
1763 IMimeMessage *iface,
1766 FIXME("(%p)->(%p)\n", iface, pStream);
1770 static HRESULT WINAPI MimeMessage_SaveOffsetTable(
1771 IMimeMessage *iface,
1775 FIXME("(%p)->(%p, 0x%x)\n", iface, pStream, dwFlags);
1780 static HRESULT WINAPI MimeMessage_GetFlags(
1781 IMimeMessage *iface,
1784 FIXME("(%p)->(%p)\n", iface, pdwFlags);
1788 static HRESULT WINAPI MimeMessage_Commit(
1789 IMimeMessage *iface,
1792 FIXME("(%p)->(0x%x)\n", iface, dwFlags);
1797 static HRESULT WINAPI MimeMessage_HandsOffStorage(
1798 IMimeMessage *iface)
1800 FIXME("(%p)->()\n", iface);
1804 static HRESULT find_body(struct list *list, HBODY hbody, body_t **body)
1809 if(hbody == HBODY_ROOT)
1811 *body = LIST_ENTRY(list_head(list), body_t, entry);
1815 LIST_FOR_EACH_ENTRY(cur, list, body_t, entry)
1817 if(cur->index == HandleToUlong(hbody))
1822 hr = find_body(&cur->children, hbody, body);
1823 if(hr == S_OK) return S_OK;
1828 static HRESULT WINAPI MimeMessage_BindToObject(IMimeMessage *iface, const HBODY hBody, REFIID riid,
1831 MimeMessage *This = impl_from_IMimeMessage(iface);
1835 TRACE("(%p)->(%p, %s, %p)\n", iface, hBody, debugstr_guid(riid), ppvObject);
1837 hr = find_body(&This->body_tree, hBody, &body);
1839 if(hr != S_OK) return hr;
1841 if(IsEqualIID(riid, &IID_IMimeBody))
1843 IMimeBody_AddRef(body->mime_body);
1844 *ppvObject = body->mime_body;
1848 return E_NOINTERFACE;
1851 static HRESULT WINAPI MimeMessage_SaveBody(
1852 IMimeMessage *iface,
1857 FIXME("(%p)->(%p, 0x%x, %p)\n", iface, hBody, dwFlags, pStream);
1861 static HRESULT get_body(MimeMessage *msg, BODYLOCATION location, HBODY pivot, body_t **out)
1863 body_t *root = LIST_ENTRY(list_head(&msg->body_tree), body_t, entry);
1868 if(location == IBL_ROOT)
1874 hr = find_body(&msg->body_tree, pivot, &body);
1881 *out = body->parent;
1885 list = list_head(&body->children);
1887 *out = LIST_ENTRY(list, body_t, entry);
1889 hr = MIME_E_NOT_FOUND;
1893 list = list_tail(&body->children);
1895 *out = LIST_ENTRY(list, body_t, entry);
1897 hr = MIME_E_NOT_FOUND;
1901 list = list_next(&body->parent->children, &body->entry);
1903 *out = LIST_ENTRY(list, body_t, entry);
1905 hr = MIME_E_NOT_FOUND;
1909 list = list_prev(&body->parent->children, &body->entry);
1911 *out = LIST_ENTRY(list, body_t, entry);
1913 hr = MIME_E_NOT_FOUND;
1926 static HRESULT WINAPI MimeMessage_InsertBody(
1927 IMimeMessage *iface,
1928 BODYLOCATION location,
1932 FIXME("(%p)->(%d, %p, %p)\n", iface, location, hPivot, phBody);
1936 static HRESULT WINAPI MimeMessage_GetBody(IMimeMessage *iface, BODYLOCATION location, HBODY hPivot,
1939 MimeMessage *This = impl_from_IMimeMessage(iface);
1943 TRACE("(%p)->(%d, %p, %p)\n", iface, location, hPivot, phBody);
1945 hr = get_body(This, location, hPivot, &body);
1947 if(hr == S_OK) *phBody = UlongToHandle(body->index);
1952 static HRESULT WINAPI MimeMessage_DeleteBody(
1953 IMimeMessage *iface,
1957 FIXME("(%p)->(%p, %08x)\n", iface, hBody, dwFlags);
1961 static HRESULT WINAPI MimeMessage_MoveBody(
1962 IMimeMessage *iface,
1964 BODYLOCATION location)
1966 FIXME("(%p)->(%d)\n", iface, location);
1970 static void count_children(body_t *body, boolean recurse, ULONG *count)
1974 LIST_FOR_EACH_ENTRY(child, &body->children, body_t, entry)
1977 if(recurse) count_children(child, recurse, count);
1981 static HRESULT WINAPI MimeMessage_CountBodies(IMimeMessage *iface, HBODY hParent, boolean fRecurse,
1985 MimeMessage *This = impl_from_IMimeMessage(iface);
1988 TRACE("(%p)->(%p, %s, %p)\n", iface, hParent, fRecurse ? "TRUE" : "FALSE", pcBodies);
1990 hr = find_body(&This->body_tree, hParent, &body);
1991 if(hr != S_OK) return hr;
1994 count_children(body, fRecurse, pcBodies);
1999 static HRESULT find_next(IMimeMessage *msg, body_t *body, LPFINDBODY find, HBODY *out)
2001 MimeMessage *This = (MimeMessage *)msg;
2007 if (!body) ptr = list_head( &This->body_tree );
2010 ptr = list_head( &body->children );
2013 if (!body->parent) return MIME_E_NOT_FOUND;
2014 if (!(ptr = list_next( &body->parent->children, &body->entry ))) body = body->parent;
2018 body = LIST_ENTRY( ptr, body_t, entry );
2019 next = UlongToHandle( body->index );
2020 find->dwReserved = body->index;
2021 if (IMimeBody_IsContentType(body->mime_body, find->pszPriType, find->pszSubType) == S_OK)
2027 return MIME_E_NOT_FOUND;
2030 static HRESULT WINAPI MimeMessage_FindFirst(
2031 IMimeMessage *iface,
2032 LPFINDBODY pFindBody,
2035 TRACE("(%p)->(%p, %p)\n", iface, pFindBody, phBody);
2037 pFindBody->dwReserved = 0;
2038 return find_next( iface, NULL, pFindBody, phBody );
2041 static HRESULT WINAPI MimeMessage_FindNext(IMimeMessage *iface, FINDBODY *pFindBody, HBODY *phBody)
2043 MimeMessage *This = impl_from_IMimeMessage(iface);
2047 TRACE("(%p)->(%p, %p)\n", iface, pFindBody, phBody);
2049 hr = find_body( &This->body_tree, UlongToHandle( pFindBody->dwReserved ), &body );
2050 if (hr != S_OK) return MIME_E_NOT_FOUND;
2051 return find_next( iface, body, pFindBody, phBody );
2054 static HRESULT WINAPI MimeMessage_ResolveURL(
2055 IMimeMessage *iface,
2062 FIXME("(%p)->(%p, %s, %s, 0x%x, %p)\n", iface, hRelated, pszBase, pszURL, dwFlags, phBody);
2066 static HRESULT WINAPI MimeMessage_ToMultipart(
2067 IMimeMessage *iface,
2070 LPHBODY phMultipart)
2072 FIXME("(%p)->(%p, %s, %p)\n", iface, hBody, pszSubType, phMultipart);
2076 static HRESULT WINAPI MimeMessage_GetBodyOffsets(
2077 IMimeMessage *iface,
2079 LPBODYOFFSETS pOffsets)
2081 FIXME("(%p)->(%p, %p)\n", iface, hBody, pOffsets);
2085 static HRESULT WINAPI MimeMessage_GetCharset(
2086 IMimeMessage *iface,
2087 LPHCHARSET phCharset)
2089 FIXME("(%p)->(%p)\n", iface, phCharset);
2094 static HRESULT WINAPI MimeMessage_SetCharset(
2095 IMimeMessage *iface,
2097 CSETAPPLYTYPE applytype)
2099 FIXME("(%p)->(%p, %d)\n", iface, hCharset, applytype);
2103 static HRESULT WINAPI MimeMessage_IsBodyType(
2104 IMimeMessage *iface,
2106 IMSGBODYTYPE bodytype)
2109 IMimeBody *mime_body;
2110 TRACE("(%p)->(%p, %d)\n", iface, hBody, bodytype);
2112 hr = IMimeMessage_BindToObject(iface, hBody, &IID_IMimeBody, (void**)&mime_body);
2113 if(hr != S_OK) return hr;
2115 hr = IMimeBody_IsType(mime_body, bodytype);
2116 MimeBody_Release(mime_body);
2120 static HRESULT WINAPI MimeMessage_IsContentType(
2121 IMimeMessage *iface,
2127 IMimeBody *mime_body;
2128 TRACE("(%p)->(%p, %s, %s)\n", iface, hBody, debugstr_a(pszPriType),
2129 debugstr_a(pszSubType));
2131 hr = IMimeMessage_BindToObject(iface, hBody, &IID_IMimeBody, (void**)&mime_body);
2132 if(FAILED(hr)) return hr;
2134 hr = IMimeBody_IsContentType(mime_body, pszPriType, pszSubType);
2135 IMimeBody_Release(mime_body);
2139 static HRESULT WINAPI MimeMessage_QueryBodyProp(
2140 IMimeMessage *iface,
2145 boolean fCaseSensitive)
2147 FIXME("(%p)->(%p, %s, %s, %s, %s)\n", iface, hBody, pszName, pszCriteria, fSubString ? "TRUE" : "FALSE", fCaseSensitive ? "TRUE" : "FALSE");
2151 static HRESULT WINAPI MimeMessage_GetBodyProp(
2152 IMimeMessage *iface,
2156 LPPROPVARIANT pValue)
2159 IMimeBody *mime_body;
2161 TRACE("(%p)->(%p, %s, 0x%x, %p)\n", iface, hBody, pszName, dwFlags, pValue);
2163 hr = IMimeMessage_BindToObject(iface, hBody, &IID_IMimeBody, (void**)&mime_body);
2164 if(hr != S_OK) return hr;
2166 hr = IMimeBody_GetProp(mime_body, pszName, dwFlags, pValue);
2167 IMimeBody_Release(mime_body);
2172 static HRESULT WINAPI MimeMessage_SetBodyProp(
2173 IMimeMessage *iface,
2177 LPCPROPVARIANT pValue)
2179 FIXME("(%p)->(%p, %s, 0x%x, %p)\n", iface, hBody, pszName, dwFlags, pValue);
2183 static HRESULT WINAPI MimeMessage_DeleteBodyProp(
2184 IMimeMessage *iface,
2188 FIXME("(%p)->(%p, %s)\n", iface, hBody, pszName);
2192 static HRESULT WINAPI MimeMessage_SetOption(
2193 IMimeMessage *iface,
2195 LPCPROPVARIANT pValue)
2197 HRESULT hr = E_NOTIMPL;
2198 TRACE("(%p)->(%08x, %p)\n", iface, oid, pValue);
2200 if(pValue->vt != TYPEDID_TYPE(oid))
2202 WARN("Called with vartype %04x and oid %08x\n", pValue->vt, oid);
2203 return E_INVALIDARG;
2208 case OID_HIDE_TNEF_ATTACHMENTS:
2209 FIXME("OID_HIDE_TNEF_ATTACHMENTS (value %d): ignoring\n", pValue->u.boolVal);
2212 case OID_SHOW_MACBINARY:
2213 FIXME("OID_SHOW_MACBINARY (value %d): ignoring\n", pValue->u.boolVal);
2217 FIXME("Unhandled oid %08x\n", oid);
2223 static HRESULT WINAPI MimeMessage_GetOption(
2224 IMimeMessage *iface,
2226 LPPROPVARIANT pValue)
2228 FIXME("(%p)->(%08x, %p)\n", iface, oid, pValue);
2232 /*** IMimeMessage methods ***/
2233 static HRESULT WINAPI MimeMessage_CreateWebPage(
2234 IMimeMessage *iface,
2236 LPWEBPAGEOPTIONS pOptions,
2237 IMimeMessageCallback *pCallback,
2238 IMoniker **ppMoniker)
2240 FIXME("(%p)->(%p, %p, %p, %p)\n", iface, pRootStm, pOptions, pCallback, ppMoniker);
2245 static HRESULT WINAPI MimeMessage_GetProp(
2246 IMimeMessage *iface,
2249 LPPROPVARIANT pValue)
2251 FIXME("(%p)->(%s, 0x%x, %p)\n", iface, pszName, dwFlags, pValue);
2255 static HRESULT WINAPI MimeMessage_SetProp(
2256 IMimeMessage *iface,
2259 LPCPROPVARIANT pValue)
2261 FIXME("(%p)->(%s, 0x%x, %p)\n", iface, pszName, dwFlags, pValue);
2265 static HRESULT WINAPI MimeMessage_DeleteProp(
2266 IMimeMessage *iface,
2269 FIXME("(%p)->(%s)\n", iface, pszName);
2273 static HRESULT WINAPI MimeMessage_QueryProp(
2274 IMimeMessage *iface,
2278 boolean fCaseSensitive)
2280 FIXME("(%p)->(%s, %s, %s, %s)\n", iface, pszName, pszCriteria, fSubString ? "TRUE" : "FALSE", fCaseSensitive ? "TRUE" : "FALSE");
2284 static HRESULT WINAPI MimeMessage_GetTextBody(
2285 IMimeMessage *iface,
2287 ENCODINGTYPE ietEncoding,
2293 FINDBODY find_struct;
2294 IMimeBody *mime_body;
2295 static char text[] = "text";
2296 static char plain[] = "plain";
2297 static char html[] = "html";
2299 TRACE("(%p)->(%d, %d, %p, %p)\n", iface, dwTxtType, ietEncoding, pStream, phBody);
2301 find_struct.pszPriType = text;
2306 find_struct.pszSubType = plain;
2309 find_struct.pszSubType = html;
2312 return MIME_E_INVALID_TEXT_TYPE;
2315 hr = IMimeMessage_FindFirst(iface, &find_struct, &hbody);
2318 TRACE("not found hr %08x\n", hr);
2323 IMimeMessage_BindToObject(iface, hbody, &IID_IMimeBody, (void**)&mime_body);
2325 IMimeBody_GetData(mime_body, ietEncoding, pStream);
2327 IMimeBody_Release(mime_body);
2331 static HRESULT WINAPI MimeMessage_SetTextBody(
2332 IMimeMessage *iface,
2334 ENCODINGTYPE ietEncoding,
2339 FIXME("(%p)->(%d, %d, %p, %p, %p)\n", iface, dwTxtType, ietEncoding, hAlternative, pStream, phBody);
2343 static HRESULT WINAPI MimeMessage_AttachObject(
2344 IMimeMessage *iface,
2349 FIXME("(%p)->(%s, %p, %p)\n", iface, debugstr_guid(riid), pvObject, phBody);
2353 static HRESULT WINAPI MimeMessage_AttachFile(
2354 IMimeMessage *iface,
2359 FIXME("(%p)->(%s, %p, %p)\n", iface, pszFilePath, pstmFile, phBody);
2363 static HRESULT WINAPI MimeMessage_AttachURL(
2364 IMimeMessage *iface,
2372 FIXME("(%p)->(%s, %s, 0x%x, %p, %p, %p)\n", iface, pszBase, pszURL, dwFlags, pstmURL, ppszCIDURL, phBody);
2376 static HRESULT WINAPI MimeMessage_GetAttachments(
2377 IMimeMessage *iface,
2379 LPHBODY *pprghAttach)
2382 FINDBODY find_struct;
2387 TRACE("(%p)->(%p, %p)\n", iface, pcAttach, pprghAttach);
2390 array = CoTaskMemAlloc(size * sizeof(HBODY));
2392 find_struct.pszPriType = find_struct.pszSubType = NULL;
2393 hr = IMimeMessage_FindFirst(iface, &find_struct, &hbody);
2396 hr = IMimeMessage_IsContentType(iface, hbody, "multipart", NULL);
2397 TRACE("IsCT rets %08x %d\n", hr, *pcAttach);
2400 if(*pcAttach + 1 > size)
2403 array = CoTaskMemRealloc(array, size * sizeof(HBODY));
2405 array[*pcAttach] = hbody;
2408 hr = IMimeMessage_FindNext(iface, &find_struct, &hbody);
2411 *pprghAttach = array;
2415 static HRESULT WINAPI MimeMessage_GetAddressTable(
2416 IMimeMessage *iface,
2417 IMimeAddressTable **ppTable)
2419 FIXME("(%p)->(%p)\n", iface, ppTable);
2423 static HRESULT WINAPI MimeMessage_GetSender(
2424 IMimeMessage *iface,
2425 LPADDRESSPROPS pAddress)
2427 FIXME("(%p)->(%p)\n", iface, pAddress);
2431 static HRESULT WINAPI MimeMessage_GetAddressTypes(
2432 IMimeMessage *iface,
2435 LPADDRESSLIST pList)
2437 FIXME("(%p)->(%d, %d, %p)\n", iface, dwAdrTypes, dwProps, pList);
2441 static HRESULT WINAPI MimeMessage_GetAddressFormat(
2442 IMimeMessage *iface,
2444 ADDRESSFORMAT format,
2447 FIXME("(%p)->(%d, %d, %p)\n", iface, dwAdrTypes, format, ppszFormat);
2451 static HRESULT WINAPI MimeMessage_EnumAddressTypes(
2452 IMimeMessage *iface,
2455 IMimeEnumAddressTypes **ppEnum)
2457 FIXME("(%p)->(%d, %d, %p)\n", iface, dwAdrTypes, dwProps, ppEnum);
2461 static HRESULT WINAPI MimeMessage_SplitMessage(
2462 IMimeMessage *iface,
2464 IMimeMessageParts **ppParts)
2466 FIXME("(%p)->(%d, %p)\n", iface, cbMaxPart, ppParts);
2470 static HRESULT WINAPI MimeMessage_GetRootMoniker(
2471 IMimeMessage *iface,
2472 IMoniker **ppMoniker)
2474 FIXME("(%p)->(%p)\n", iface, ppMoniker);
2478 static const IMimeMessageVtbl MimeMessageVtbl =
2480 MimeMessage_QueryInterface,
2482 MimeMessage_Release,
2483 MimeMessage_GetClassID,
2484 MimeMessage_IsDirty,
2487 MimeMessage_GetSizeMax,
2488 MimeMessage_InitNew,
2489 MimeMessage_GetMessageSource,
2490 MimeMessage_GetMessageSize,
2491 MimeMessage_LoadOffsetTable,
2492 MimeMessage_SaveOffsetTable,
2493 MimeMessage_GetFlags,
2495 MimeMessage_HandsOffStorage,
2496 MimeMessage_BindToObject,
2497 MimeMessage_SaveBody,
2498 MimeMessage_InsertBody,
2499 MimeMessage_GetBody,
2500 MimeMessage_DeleteBody,
2501 MimeMessage_MoveBody,
2502 MimeMessage_CountBodies,
2503 MimeMessage_FindFirst,
2504 MimeMessage_FindNext,
2505 MimeMessage_ResolveURL,
2506 MimeMessage_ToMultipart,
2507 MimeMessage_GetBodyOffsets,
2508 MimeMessage_GetCharset,
2509 MimeMessage_SetCharset,
2510 MimeMessage_IsBodyType,
2511 MimeMessage_IsContentType,
2512 MimeMessage_QueryBodyProp,
2513 MimeMessage_GetBodyProp,
2514 MimeMessage_SetBodyProp,
2515 MimeMessage_DeleteBodyProp,
2516 MimeMessage_SetOption,
2517 MimeMessage_GetOption,
2518 MimeMessage_CreateWebPage,
2519 MimeMessage_GetProp,
2520 MimeMessage_SetProp,
2521 MimeMessage_DeleteProp,
2522 MimeMessage_QueryProp,
2523 MimeMessage_GetTextBody,
2524 MimeMessage_SetTextBody,
2525 MimeMessage_AttachObject,
2526 MimeMessage_AttachFile,
2527 MimeMessage_AttachURL,
2528 MimeMessage_GetAttachments,
2529 MimeMessage_GetAddressTable,
2530 MimeMessage_GetSender,
2531 MimeMessage_GetAddressTypes,
2532 MimeMessage_GetAddressFormat,
2533 MimeMessage_EnumAddressTypes,
2534 MimeMessage_SplitMessage,
2535 MimeMessage_GetRootMoniker,
2538 HRESULT MimeMessage_create(IUnknown *outer, void **obj)
2542 TRACE("(%p, %p)\n", outer, obj);
2546 FIXME("outer unknown not supported yet\n");
2552 This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
2553 if (!This) return E_OUTOFMEMORY;
2555 This->IMimeMessage_iface.lpVtbl = &MimeMessageVtbl;
2557 This->stream = NULL;
2558 list_init(&This->body_tree);
2559 This->next_index = 1;
2561 *obj = &This->IMimeMessage_iface;
2565 /***********************************************************************
2566 * MimeOleCreateMessage (INETCOMM.@)
2568 HRESULT WINAPI MimeOleCreateMessage(IUnknown *pUnkOuter, IMimeMessage **ppMessage)
2570 TRACE("(%p, %p)\n", pUnkOuter, ppMessage);
2571 return MimeMessage_create(NULL, (void **)ppMessage);
2574 /***********************************************************************
2575 * MimeOleSetCompatMode (INETCOMM.@)
2577 HRESULT WINAPI MimeOleSetCompatMode(DWORD dwMode)
2579 FIXME("(0x%x)\n", dwMode);
2583 /***********************************************************************
2584 * MimeOleCreateVirtualStream (INETCOMM.@)
2586 HRESULT WINAPI MimeOleCreateVirtualStream(IStream **ppStream)
2589 FIXME("(%p)\n", ppStream);
2591 hr = CreateStreamOnHGlobal(NULL, TRUE, ppStream);
2595 typedef struct MimeSecurity
2597 const IMimeSecurityVtbl *lpVtbl;
2602 static HRESULT WINAPI MimeSecurity_QueryInterface(
2603 IMimeSecurity* iface,
2607 TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), obj);
2609 if (IsEqualIID(riid, &IID_IUnknown) ||
2610 IsEqualIID(riid, &IID_IMimeSecurity))
2613 IMimeSecurity_AddRef(iface);
2617 FIXME("no interface for %s\n", debugstr_guid(riid));
2619 return E_NOINTERFACE;
2622 static ULONG WINAPI MimeSecurity_AddRef(
2623 IMimeSecurity* iface)
2625 MimeSecurity *This = (MimeSecurity *)iface;
2626 TRACE("(%p)->()\n", iface);
2627 return InterlockedIncrement(&This->refs);
2630 static ULONG WINAPI MimeSecurity_Release(
2631 IMimeSecurity* iface)
2633 MimeSecurity *This = (MimeSecurity *)iface;
2636 TRACE("(%p)->()\n", iface);
2638 refs = InterlockedDecrement(&This->refs);
2641 HeapFree(GetProcessHeap(), 0, This);
2647 static HRESULT WINAPI MimeSecurity_InitNew(
2648 IMimeSecurity* iface)
2650 FIXME("(%p)->(): stub\n", iface);
2654 static HRESULT WINAPI MimeSecurity_CheckInit(
2655 IMimeSecurity* iface)
2657 FIXME("(%p)->(): stub\n", iface);
2661 static HRESULT WINAPI MimeSecurity_EncodeMessage(
2662 IMimeSecurity* iface,
2663 IMimeMessageTree* pTree,
2666 FIXME("(%p)->(%p, %08x): stub\n", iface, pTree, dwFlags);
2670 static HRESULT WINAPI MimeSecurity_EncodeBody(
2671 IMimeSecurity* iface,
2672 IMimeMessageTree* pTree,
2676 FIXME("(%p)->(%p, %p, %08x): stub\n", iface, pTree, hEncodeRoot, dwFlags);
2680 static HRESULT WINAPI MimeSecurity_DecodeMessage(
2681 IMimeSecurity* iface,
2682 IMimeMessageTree* pTree,
2685 FIXME("(%p)->(%p, %08x): stub\n", iface, pTree, dwFlags);
2689 static HRESULT WINAPI MimeSecurity_DecodeBody(
2690 IMimeSecurity* iface,
2691 IMimeMessageTree* pTree,
2695 FIXME("(%p)->(%p, %p, %08x): stub\n", iface, pTree, hDecodeRoot, dwFlags);
2699 static HRESULT WINAPI MimeSecurity_EnumCertificates(
2700 IMimeSecurity* iface,
2706 FIXME("(%p)->(%p, %08x, %p, %p): stub\n", iface, hc, dwUsage, pPrev, ppCert);
2710 static HRESULT WINAPI MimeSecurity_GetCertificateName(
2711 IMimeSecurity* iface,
2712 const PCX509CERT pX509Cert,
2713 const CERTNAMETYPE cn,
2716 FIXME("(%p)->(%p, %08x, %p): stub\n", iface, pX509Cert, cn, ppszName);
2720 static HRESULT WINAPI MimeSecurity_GetMessageType(
2721 IMimeSecurity* iface,
2722 const HWND hwndParent,
2726 FIXME("(%p)->(%p, %p, %p): stub\n", iface, hwndParent, pBody, pdwSecType);
2730 static HRESULT WINAPI MimeSecurity_GetCertData(
2731 IMimeSecurity* iface,
2732 const PCX509CERT pX509Cert,
2733 const CERTDATAID dataid,
2734 LPPROPVARIANT pValue)
2736 FIXME("(%p)->(%p, %x, %p): stub\n", iface, pX509Cert, dataid, pValue);
2741 static const IMimeSecurityVtbl MimeSecurityVtbl =
2743 MimeSecurity_QueryInterface,
2744 MimeSecurity_AddRef,
2745 MimeSecurity_Release,
2746 MimeSecurity_InitNew,
2747 MimeSecurity_CheckInit,
2748 MimeSecurity_EncodeMessage,
2749 MimeSecurity_EncodeBody,
2750 MimeSecurity_DecodeMessage,
2751 MimeSecurity_DecodeBody,
2752 MimeSecurity_EnumCertificates,
2753 MimeSecurity_GetCertificateName,
2754 MimeSecurity_GetMessageType,
2755 MimeSecurity_GetCertData
2758 HRESULT MimeSecurity_create(IUnknown *outer, void **obj)
2764 if (outer) return CLASS_E_NOAGGREGATION;
2766 This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
2767 if (!This) return E_OUTOFMEMORY;
2769 This->lpVtbl = &MimeSecurityVtbl;
2772 *obj = &This->lpVtbl;
2776 /***********************************************************************
2777 * MimeOleCreateSecurity (INETCOMM.@)
2779 HRESULT WINAPI MimeOleCreateSecurity(IMimeSecurity **ppSecurity)
2781 return MimeSecurity_create(NULL, (void **)ppSecurity);
2786 IMimeAllocatorVtbl *lpVtbl;
2789 static HRESULT WINAPI MimeAlloc_QueryInterface(
2790 IMimeAllocator* iface,
2794 TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), obj);
2796 if (IsEqualIID(riid, &IID_IUnknown) ||
2797 IsEqualIID(riid, &IID_IMalloc) ||
2798 IsEqualIID(riid, &IID_IMimeAllocator))
2801 IMimeAllocator_AddRef(iface);
2805 FIXME("no interface for %s\n", debugstr_guid(riid));
2807 return E_NOINTERFACE;
2810 static ULONG WINAPI MimeAlloc_AddRef(
2811 IMimeAllocator* iface)
2816 static ULONG WINAPI MimeAlloc_Release(
2817 IMimeAllocator* iface)
2822 static LPVOID WINAPI MimeAlloc_Alloc(
2823 IMimeAllocator* iface,
2826 return CoTaskMemAlloc(cb);
2829 static LPVOID WINAPI MimeAlloc_Realloc(
2830 IMimeAllocator* iface,
2834 return CoTaskMemRealloc(pv, cb);
2837 static void WINAPI MimeAlloc_Free(
2838 IMimeAllocator* iface,
2844 static ULONG WINAPI MimeAlloc_GetSize(
2845 IMimeAllocator* iface,
2852 static int WINAPI MimeAlloc_DidAlloc(
2853 IMimeAllocator* iface,
2860 static void WINAPI MimeAlloc_HeapMinimize(
2861 IMimeAllocator* iface)
2867 static HRESULT WINAPI MimeAlloc_FreeParamInfoArray(
2868 IMimeAllocator* iface,
2870 LPMIMEPARAMINFO prgParam,
2874 TRACE("(%p)->(%d, %p, %d)\n", iface, cParams, prgParam, fFreeArray);
2876 for(i = 0; i < cParams; i++)
2878 IMimeAllocator_Free(iface, prgParam[i].pszName);
2879 IMimeAllocator_Free(iface, prgParam[i].pszData);
2881 if(fFreeArray) IMimeAllocator_Free(iface, prgParam);
2885 static HRESULT WINAPI MimeAlloc_FreeAddressList(
2886 IMimeAllocator* iface,
2887 LPADDRESSLIST pList)
2893 static HRESULT WINAPI MimeAlloc_FreeAddressProps(
2894 IMimeAllocator* iface,
2895 LPADDRESSPROPS pAddress)
2901 static HRESULT WINAPI MimeAlloc_ReleaseObjects(
2902 IMimeAllocator* iface,
2904 IUnknown **prgpUnknown,
2912 static HRESULT WINAPI MimeAlloc_FreeEnumHeaderRowArray(
2913 IMimeAllocator* iface,
2915 LPENUMHEADERROW prgRow,
2922 static HRESULT WINAPI MimeAlloc_FreeEnumPropertyArray(
2923 IMimeAllocator* iface,
2925 LPENUMPROPERTY prgProp,
2932 static HRESULT WINAPI MimeAlloc_FreeThumbprint(
2933 IMimeAllocator* iface,
2934 THUMBBLOB *pthumbprint)
2941 static HRESULT WINAPI MimeAlloc_PropVariantClear(
2942 IMimeAllocator* iface,
2943 LPPROPVARIANT pProp)
2949 static IMimeAllocatorVtbl mime_alloc_vtbl =
2951 MimeAlloc_QueryInterface,
2959 MimeAlloc_HeapMinimize,
2960 MimeAlloc_FreeParamInfoArray,
2961 MimeAlloc_FreeAddressList,
2962 MimeAlloc_FreeAddressProps,
2963 MimeAlloc_ReleaseObjects,
2964 MimeAlloc_FreeEnumHeaderRowArray,
2965 MimeAlloc_FreeEnumPropertyArray,
2966 MimeAlloc_FreeThumbprint,
2967 MimeAlloc_PropVariantClear
2970 static MimeAllocator mime_allocator =
2975 HRESULT MimeAllocator_create(IUnknown *outer, void **obj)
2977 if(outer) return CLASS_E_NOAGGREGATION;
2979 *obj = &mime_allocator;
2983 HRESULT WINAPI MimeOleGetAllocator(IMimeAllocator **alloc)
2985 return MimeAllocator_create(NULL, (void**)alloc);
2988 HRESULT VirtualStream_create(IUnknown *outer, void **obj)
2990 FIXME("(%p, %p)\n", outer, obj);
2993 if (outer) return CLASS_E_NOAGGREGATION;
2995 return MimeOleCreateVirtualStream((IStream **)obj);