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, 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)
634 static HRESULT WINAPI MimeBody_SetProp(
638 LPCPROPVARIANT pValue)
644 static HRESULT WINAPI MimeBody_AppendProp(
648 LPPROPVARIANT pValue)
654 static HRESULT WINAPI MimeBody_DeleteProp(
662 static HRESULT WINAPI MimeBody_CopyProps(
666 IMimePropertySet* pPropertySet)
672 static HRESULT WINAPI MimeBody_MoveProps(
676 IMimePropertySet* pPropertySet)
682 static HRESULT WINAPI MimeBody_DeleteExcept(
691 static HRESULT WINAPI MimeBody_QueryProp(
696 boolean fCaseSensitive)
702 static HRESULT WINAPI MimeBody_GetCharset(
704 LPHCHARSET phCharset)
710 static HRESULT WINAPI MimeBody_SetCharset(
713 CSETAPPLYTYPE applytype)
719 static HRESULT WINAPI MimeBody_GetParameters(
723 LPMIMEPARAMINFO* pprgParam)
725 MimeBody *This = impl_from_IMimeBody(iface);
729 TRACE("(%p)->(%s, %p, %p)\n", iface, debugstr_a(pszName), pcParams, pprgParam);
734 hr = find_prop(This, pszName, &header);
735 if(hr != S_OK) return hr;
737 *pcParams = list_count(&header->params);
740 IMimeAllocator *alloc;
744 MimeOleGetAllocator(&alloc);
746 *pprgParam = info = IMimeAllocator_Alloc(alloc, *pcParams * sizeof(**pprgParam));
747 LIST_FOR_EACH_ENTRY(param, &header->params, param_t, entry)
751 len = strlen(param->name) + 1;
752 info->pszName = IMimeAllocator_Alloc(alloc, len);
753 memcpy(info->pszName, param->name, len);
754 len = strlen(param->value) + 1;
755 info->pszData = IMimeAllocator_Alloc(alloc, len);
756 memcpy(info->pszData, param->value, len);
759 IMimeAllocator_Release(alloc);
764 static HRESULT WINAPI MimeBody_IsContentType(
769 MimeBody *This = impl_from_IMimeBody(iface);
771 TRACE("(%p)->(%s, %s)\n", This, debugstr_a(pszPriType), debugstr_a(pszSubType));
774 const char *pri = This->content_pri_type;
775 if(!pri) pri = "text";
776 if(strcasecmp(pri, pszPriType)) return S_FALSE;
781 const char *sub = This->content_sub_type;
782 if(!sub) sub = "plain";
783 if(strcasecmp(sub, pszSubType)) return S_FALSE;
789 static HRESULT WINAPI MimeBody_BindToObject(
798 static HRESULT WINAPI MimeBody_Clone(
800 IMimePropertySet** ppPropertySet)
806 static HRESULT WINAPI MimeBody_SetOption(
809 LPCPROPVARIANT pValue)
815 static HRESULT WINAPI MimeBody_GetOption(
818 LPPROPVARIANT pValue)
824 static HRESULT WINAPI MimeBody_EnumProps(
827 IMimeEnumProperties** ppEnum)
833 static HRESULT WINAPI MimeBody_IsType(
835 IMSGBODYTYPE bodytype)
841 static HRESULT WINAPI MimeBody_SetDisplayName(
849 static HRESULT WINAPI MimeBody_GetDisplayName(
857 static HRESULT WINAPI MimeBody_GetOffsets(
859 LPBODYOFFSETS pOffsets)
861 MimeBody *This = impl_from_IMimeBody(iface);
862 TRACE("(%p)->(%p)\n", This, pOffsets);
864 *pOffsets = This->body_offsets;
866 if(This->body_offsets.cbBodyEnd == 0) return MIME_E_NO_DATA;
870 static HRESULT WINAPI MimeBody_GetCurrentEncoding(
872 ENCODINGTYPE* pietEncoding)
874 MimeBody *This = impl_from_IMimeBody(iface);
876 TRACE("(%p)->(%p)\n", This, pietEncoding);
878 *pietEncoding = This->encoding;
882 static HRESULT WINAPI MimeBody_SetCurrentEncoding(
884 ENCODINGTYPE ietEncoding)
886 MimeBody *This = impl_from_IMimeBody(iface);
888 TRACE("(%p)->(%d)\n", This, ietEncoding);
890 This->encoding = ietEncoding;
894 static HRESULT WINAPI MimeBody_GetEstimatedSize(
896 ENCODINGTYPE ietEncoding,
903 static HRESULT WINAPI MimeBody_GetDataHere(
905 ENCODINGTYPE ietEncoding,
912 static HRESULT WINAPI MimeBody_GetData(
914 ENCODINGTYPE ietEncoding,
917 MimeBody *This = impl_from_IMimeBody(iface);
918 FIXME("(%p)->(%d, %p). Ignoring encoding type.\n", This, ietEncoding, ppStream);
920 *ppStream = This->data;
921 IStream_AddRef(*ppStream);
925 static HRESULT WINAPI MimeBody_SetData(
927 ENCODINGTYPE ietEncoding,
933 MimeBody *This = impl_from_IMimeBody(iface);
934 TRACE("(%p)->(%d, %s, %s, %s %p)\n", This, ietEncoding, debugstr_a(pszPriType), debugstr_a(pszSubType),
935 debugstr_guid(riid), pvObject);
937 if(IsEqualIID(riid, &IID_IStream))
938 IStream_AddRef((IStream *)pvObject);
941 FIXME("Unhandled object type %s\n", debugstr_guid(riid));
946 FIXME("release old data\n");
948 This->data_iid = *riid;
949 This->data = pvObject;
951 IMimeBody_SetCurrentEncoding(iface, ietEncoding);
953 /* FIXME: Update the content type.
954 If pszPriType == NULL use 'application'
955 If pszSubType == NULL use 'octet-stream' */
960 static HRESULT WINAPI MimeBody_EmptyData(
967 static HRESULT WINAPI MimeBody_CopyTo(
975 static HRESULT WINAPI MimeBody_GetTransmitInfo(
977 LPTRANSMITINFO pTransmitInfo)
983 static HRESULT WINAPI MimeBody_SaveToFile(
985 ENCODINGTYPE ietEncoding,
992 static HRESULT WINAPI MimeBody_GetHandle(
996 MimeBody *This = impl_from_IMimeBody(iface);
997 TRACE("(%p)->(%p)\n", iface, phBody);
999 *phBody = This->handle;
1000 return This->handle ? S_OK : MIME_E_NO_DATA;
1003 static IMimeBodyVtbl body_vtbl =
1005 MimeBody_QueryInterface,
1008 MimeBody_GetClassID,
1012 MimeBody_GetSizeMax,
1014 MimeBody_GetPropInfo,
1015 MimeBody_SetPropInfo,
1018 MimeBody_AppendProp,
1019 MimeBody_DeleteProp,
1022 MimeBody_DeleteExcept,
1024 MimeBody_GetCharset,
1025 MimeBody_SetCharset,
1026 MimeBody_GetParameters,
1027 MimeBody_IsContentType,
1028 MimeBody_BindToObject,
1034 MimeBody_SetDisplayName,
1035 MimeBody_GetDisplayName,
1036 MimeBody_GetOffsets,
1037 MimeBody_GetCurrentEncoding,
1038 MimeBody_SetCurrentEncoding,
1039 MimeBody_GetEstimatedSize,
1040 MimeBody_GetDataHere,
1045 MimeBody_GetTransmitInfo,
1046 MimeBody_SaveToFile,
1050 static HRESULT MimeBody_set_offsets(MimeBody *body, const BODYOFFSETS *offsets)
1052 TRACE("setting offsets to %d, %d, %d, %d\n", offsets->cbBoundaryStart,
1053 offsets->cbHeaderStart, offsets->cbBodyStart, offsets->cbBodyEnd);
1055 body->body_offsets = *offsets;
1059 #define FIRST_CUSTOM_PROP_ID 0x100
1061 HRESULT MimeBody_create(IUnknown *outer, void **obj)
1064 BODYOFFSETS body_offsets;
1068 if(outer) return CLASS_E_NOAGGREGATION;
1070 This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
1071 if (!This) return E_OUTOFMEMORY;
1073 This->lpVtbl = &body_vtbl;
1075 This->handle = NULL;
1076 list_init(&This->headers);
1077 list_init(&This->new_props);
1078 This->next_prop_id = FIRST_CUSTOM_PROP_ID;
1079 This->content_pri_type = NULL;
1080 This->content_sub_type = NULL;
1081 This->encoding = IET_7BIT;
1083 This->data_iid = IID_NULL;
1085 body_offsets.cbBoundaryStart = body_offsets.cbHeaderStart = 0;
1086 body_offsets.cbBodyStart = body_offsets.cbBodyEnd = 0;
1087 MimeBody_set_offsets(This, &body_offsets);
1089 *obj = (IMimeBody *)&This->lpVtbl;
1095 IStreamVtbl *lpVtbl;
1099 ULARGE_INTEGER pos, start, length;
1102 static inline sub_stream_t *impl_from_IStream( IStream *iface )
1104 return (sub_stream_t *)((char*)iface - FIELD_OFFSET(sub_stream_t, lpVtbl));
1107 static HRESULT WINAPI sub_stream_QueryInterface(
1112 sub_stream_t *This = impl_from_IStream(iface);
1114 TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), ppvObject);
1117 if(IsEqualIID(riid, &IID_IUnknown) ||
1118 IsEqualIID(riid, &IID_ISequentialStream) ||
1119 IsEqualIID(riid, &IID_IStream))
1121 IStream_AddRef(iface);
1125 return E_NOINTERFACE;
1128 static ULONG WINAPI sub_stream_AddRef(
1131 sub_stream_t *This = impl_from_IStream(iface);
1133 TRACE("(%p)\n", This);
1134 return InterlockedIncrement(&This->refs);
1137 static ULONG WINAPI sub_stream_Release(
1140 sub_stream_t *This = impl_from_IStream(iface);
1143 TRACE("(%p)\n", This);
1144 refs = InterlockedDecrement(&This->refs);
1147 IStream_Release(This->base);
1148 HeapFree(GetProcessHeap(), 0, This);
1153 static HRESULT WINAPI sub_stream_Read(
1159 sub_stream_t *This = impl_from_IStream(iface);
1161 ULARGE_INTEGER base_pos;
1162 LARGE_INTEGER tmp_pos;
1164 TRACE("(%p, %d, %p)\n", pv, cb, pcbRead);
1166 tmp_pos.QuadPart = 0;
1167 IStream_Seek(This->base, tmp_pos, STREAM_SEEK_CUR, &base_pos);
1168 tmp_pos.QuadPart = This->pos.QuadPart + This->start.QuadPart;
1169 IStream_Seek(This->base, tmp_pos, STREAM_SEEK_SET, NULL);
1171 if(This->pos.QuadPart + cb > This->length.QuadPart)
1172 cb = This->length.QuadPart - This->pos.QuadPart;
1174 hr = IStream_Read(This->base, pv, cb, pcbRead);
1176 This->pos.QuadPart += *pcbRead;
1178 tmp_pos.QuadPart = base_pos.QuadPart;
1179 IStream_Seek(This->base, tmp_pos, STREAM_SEEK_SET, NULL);
1184 static HRESULT WINAPI sub_stream_Write(
1194 static HRESULT WINAPI sub_stream_Seek(
1196 LARGE_INTEGER dlibMove,
1198 ULARGE_INTEGER *plibNewPosition)
1200 sub_stream_t *This = impl_from_IStream(iface);
1201 LARGE_INTEGER new_pos;
1203 TRACE("(%08x.%08x, %x, %p)\n", dlibMove.u.HighPart, dlibMove.u.LowPart, dwOrigin, plibNewPosition);
1207 case STREAM_SEEK_SET:
1210 case STREAM_SEEK_CUR:
1211 new_pos.QuadPart = This->pos.QuadPart + dlibMove.QuadPart;
1213 case STREAM_SEEK_END:
1214 new_pos.QuadPart = This->length.QuadPart + dlibMove.QuadPart;
1218 if(new_pos.QuadPart < 0) new_pos.QuadPart = 0;
1219 else if(new_pos.QuadPart > This->length.QuadPart) new_pos.QuadPart = This->length.QuadPart;
1221 This->pos.QuadPart = new_pos.QuadPart;
1223 if(plibNewPosition) *plibNewPosition = This->pos;
1227 static HRESULT WINAPI sub_stream_SetSize(
1229 ULARGE_INTEGER libNewSize)
1235 static HRESULT WINAPI sub_stream_CopyTo(
1239 ULARGE_INTEGER *pcbRead,
1240 ULARGE_INTEGER *pcbWritten)
1246 static HRESULT WINAPI sub_stream_Commit(
1248 DWORD grfCommitFlags)
1254 static HRESULT WINAPI sub_stream_Revert(
1261 static HRESULT WINAPI sub_stream_LockRegion(
1263 ULARGE_INTEGER libOffset,
1271 static HRESULT WINAPI sub_stream_UnlockRegion(
1273 ULARGE_INTEGER libOffset,
1281 static HRESULT WINAPI sub_stream_Stat(
1286 sub_stream_t *This = impl_from_IStream(iface);
1287 FIXME("(%p)->(%p, %08x)\n", This, pstatstg, grfStatFlag);
1288 memset(pstatstg, 0, sizeof(*pstatstg));
1289 pstatstg->cbSize = This->length;
1293 static HRESULT WINAPI sub_stream_Clone(
1301 static struct IStreamVtbl sub_stream_vtbl =
1303 sub_stream_QueryInterface,
1313 sub_stream_LockRegion,
1314 sub_stream_UnlockRegion,
1319 static HRESULT create_sub_stream(IStream *stream, ULARGE_INTEGER start, ULARGE_INTEGER length, IStream **out)
1324 This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
1325 if(!This) return E_OUTOFMEMORY;
1327 This->lpVtbl = &sub_stream_vtbl;
1329 This->start = start;
1330 This->length = length;
1331 This->pos.QuadPart = 0;
1332 IStream_AddRef(stream);
1333 This->base = stream;
1335 *out = (IStream*)&This->lpVtbl;
1340 typedef struct body_t
1344 IMimeBody *mime_body;
1346 struct body_t *parent;
1347 struct list children;
1350 typedef struct MimeMessage
1352 const IMimeMessageVtbl *lpVtbl;
1357 struct list body_tree;
1361 static HRESULT WINAPI MimeMessage_QueryInterface(IMimeMessage *iface, REFIID riid, void **ppv)
1363 TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppv);
1365 if (IsEqualIID(riid, &IID_IUnknown) ||
1366 IsEqualIID(riid, &IID_IPersist) ||
1367 IsEqualIID(riid, &IID_IPersistStreamInit) ||
1368 IsEqualIID(riid, &IID_IMimeMessageTree) ||
1369 IsEqualIID(riid, &IID_IMimeMessage))
1372 IUnknown_AddRef(iface);
1376 FIXME("no interface for %s\n", debugstr_guid(riid));
1378 return E_NOINTERFACE;
1381 static ULONG WINAPI MimeMessage_AddRef(IMimeMessage *iface)
1383 MimeMessage *This = (MimeMessage *)iface;
1384 TRACE("(%p)->()\n", iface);
1385 return InterlockedIncrement(&This->refs);
1388 static void empty_body_list(struct list *list)
1390 body_t *body, *cursor2;
1391 LIST_FOR_EACH_ENTRY_SAFE(body, cursor2, list, body_t, entry)
1393 empty_body_list(&body->children);
1394 list_remove(&body->entry);
1395 IMimeBody_Release(body->mime_body);
1396 HeapFree(GetProcessHeap(), 0, body);
1400 static ULONG WINAPI MimeMessage_Release(IMimeMessage *iface)
1402 MimeMessage *This = (MimeMessage *)iface;
1405 TRACE("(%p)->()\n", iface);
1407 refs = InterlockedDecrement(&This->refs);
1410 empty_body_list(&This->body_tree);
1412 if(This->stream) IStream_Release(This->stream);
1413 HeapFree(GetProcessHeap(), 0, This);
1419 /*** IPersist methods ***/
1420 static HRESULT WINAPI MimeMessage_GetClassID(
1421 IMimeMessage *iface,
1424 FIXME("(%p)->(%p)\n", iface, pClassID);
1428 /*** IPersistStreamInit methods ***/
1429 static HRESULT WINAPI MimeMessage_IsDirty(
1430 IMimeMessage *iface)
1432 FIXME("(%p)->()\n", iface);
1436 static body_t *new_body_entry(IMimeBody *mime_body, HBODY hbody, body_t *parent)
1438 body_t *body = HeapAlloc(GetProcessHeap(), 0, sizeof(*body));
1441 body->mime_body = mime_body;
1442 body->hbody = hbody;
1443 list_init(&body->children);
1444 body->parent = parent;
1452 BODYOFFSETS offsets;
1455 static HRESULT create_body_offset_list(IStream *stm, const char *boundary, struct list *body_offsets)
1459 int boundary_len = strlen(boundary);
1460 char *buf, *nl_boundary, *ptr, *overlap;
1461 DWORD total_read = 0;
1462 DWORD start = 0, overlap_no;
1463 offset_entry_t *cur_body = NULL;
1467 list_init(body_offsets);
1468 nl_boundary = HeapAlloc(GetProcessHeap(), 0, 4 + boundary_len + 1);
1469 memcpy(nl_boundary, "\r\n--", 4);
1470 memcpy(nl_boundary + 4, boundary, boundary_len + 1);
1472 overlap_no = boundary_len + 5;
1474 overlap = buf = HeapAlloc(GetProcessHeap(), 0, overlap_no + PARSER_BUF_SIZE + 1);
1477 hr = IStream_Seek(stm, zero, STREAM_SEEK_CUR, &cur);
1478 start = cur.LowPart;
1481 hr = IStream_Read(stm, overlap, PARSER_BUF_SIZE, &read);
1482 if(FAILED(hr)) goto end;
1483 if(read == 0) break;
1485 overlap[read] = '\0';
1489 ptr = strstr(ptr, nl_boundary);
1492 DWORD boundary_start = start + ptr - buf;
1493 char *end = ptr + boundary_len + 4;
1495 if(*end == '\0' || *(end + 1) == '\0')
1498 if(*end == '\r' && *(end + 1) == '\n')
1502 cur_body->offsets.cbBodyEnd = boundary_start;
1503 list_add_tail(body_offsets, &cur_body->entry);
1505 cur_body = HeapAlloc(GetProcessHeap(), 0, sizeof(*cur_body));
1506 cur_body->offsets.cbBoundaryStart = boundary_start + 2; /* doesn't including the leading \r\n */
1507 cur_body->offsets.cbHeaderStart = boundary_start + boundary_len + 6;
1509 else if(*end == '-' && *(end + 1) == '-')
1513 cur_body->offsets.cbBodyEnd = boundary_start;
1514 list_add_tail(body_offsets, &cur_body->entry);
1522 if(overlap == buf) /* 1st iteration */
1524 memcpy(buf, buf + PARSER_BUF_SIZE - overlap_no, overlap_no);
1525 overlap = buf + overlap_no;
1526 start += read - overlap_no;
1530 memcpy(buf, buf + PARSER_BUF_SIZE, overlap_no);
1536 HeapFree(GetProcessHeap(), 0, buf);
1540 static body_t *create_sub_body(MimeMessage *msg, IStream *pStm, BODYOFFSETS *offset, body_t *parent)
1542 IMimeBody *mime_body;
1548 MimeBody_create(NULL, (void**)&mime_body);
1549 IMimeBody_Load(mime_body, pStm);
1551 hr = IStream_Seek(pStm, zero, STREAM_SEEK_CUR, &cur);
1552 offset->cbBodyStart = cur.LowPart + offset->cbHeaderStart;
1553 if(parent) MimeBody_set_offsets(impl_from_IMimeBody(mime_body), offset);
1554 IMimeBody_SetData(mime_body, IET_BINARY, NULL, NULL, &IID_IStream, pStm);
1555 body = new_body_entry(mime_body, msg->next_hbody, parent);
1556 msg->next_hbody = (HBODY)((DWORD)msg->next_hbody + 1);
1558 if(IMimeBody_IsContentType(mime_body, "multipart", NULL) == S_OK)
1560 MIMEPARAMINFO *param_info;
1562 IMimeAllocator *alloc;
1564 hr = IMimeBody_GetParameters(mime_body, "Content-Type", &count, ¶m_info);
1565 if(hr != S_OK || count == 0) return body;
1567 MimeOleGetAllocator(&alloc);
1569 for(i = 0; i < count; i++)
1571 if(!strcasecmp(param_info[i].pszName, "boundary"))
1573 struct list offset_list;
1574 offset_entry_t *cur, *cursor2;
1575 hr = create_body_offset_list(pStm, param_info[i].pszData, &offset_list);
1576 LIST_FOR_EACH_ENTRY_SAFE(cur, cursor2, &offset_list, offset_entry_t, entry)
1579 IStream *sub_stream;
1580 ULARGE_INTEGER start, length;
1582 start.LowPart = cur->offsets.cbHeaderStart;
1583 length.LowPart = cur->offsets.cbBodyEnd - cur->offsets.cbHeaderStart;
1584 create_sub_stream(pStm, start, length, &sub_stream);
1585 sub_body = create_sub_body(msg, sub_stream, &cur->offsets, body);
1586 IStream_Release(sub_stream);
1587 list_add_tail(&body->children, &sub_body->entry);
1588 list_remove(&cur->entry);
1589 HeapFree(GetProcessHeap(), 0, cur);
1594 IMimeAllocator_FreeParamInfoArray(alloc, count, param_info, TRUE);
1595 IMimeAllocator_Release(alloc);
1600 static HRESULT WINAPI MimeMessage_Load(
1601 IMimeMessage *iface,
1604 MimeMessage *This = (MimeMessage *)iface;
1606 BODYOFFSETS offsets;
1610 TRACE("(%p)->(%p)\n", iface, pStm);
1614 FIXME("already loaded a message\n");
1618 IStream_AddRef(pStm);
1619 This->stream = pStm;
1620 offsets.cbBoundaryStart = offsets.cbHeaderStart = 0;
1621 offsets.cbBodyStart = offsets.cbBodyEnd = 0;
1623 root_body = create_sub_body(This, pStm, &offsets, NULL);
1626 IStream_Seek(pStm, zero, STREAM_SEEK_END, &cur);
1627 offsets.cbBodyEnd = cur.LowPart;
1628 MimeBody_set_offsets(impl_from_IMimeBody(root_body->mime_body), &offsets);
1630 list_add_head(&This->body_tree, &root_body->entry);
1635 static HRESULT WINAPI MimeMessage_Save(
1636 IMimeMessage *iface,
1640 FIXME("(%p)->(%p, %s)\n", iface, pStm, fClearDirty ? "TRUE" : "FALSE");
1644 static HRESULT WINAPI MimeMessage_GetSizeMax(
1645 IMimeMessage *iface,
1646 ULARGE_INTEGER *pcbSize)
1648 FIXME("(%p)->(%p)\n", iface, pcbSize);
1652 static HRESULT WINAPI MimeMessage_InitNew(
1653 IMimeMessage *iface)
1655 FIXME("(%p)->()\n", iface);
1659 /*** IMimeMessageTree methods ***/
1660 static HRESULT WINAPI MimeMessage_GetMessageSource(
1661 IMimeMessage *iface,
1665 FIXME("(%p)->(%p, 0x%x)\n", iface, ppStream, dwFlags);
1669 static HRESULT WINAPI MimeMessage_GetMessageSize(
1670 IMimeMessage *iface,
1674 FIXME("(%p)->(%p, 0x%x)\n", iface, pcbSize, dwFlags);
1678 static HRESULT WINAPI MimeMessage_LoadOffsetTable(
1679 IMimeMessage *iface,
1682 FIXME("(%p)->(%p)\n", iface, pStream);
1686 static HRESULT WINAPI MimeMessage_SaveOffsetTable(
1687 IMimeMessage *iface,
1691 FIXME("(%p)->(%p, 0x%x)\n", iface, pStream, dwFlags);
1696 static HRESULT WINAPI MimeMessage_GetFlags(
1697 IMimeMessage *iface,
1700 FIXME("(%p)->(%p)\n", iface, pdwFlags);
1704 static HRESULT WINAPI MimeMessage_Commit(
1705 IMimeMessage *iface,
1708 FIXME("(%p)->(0x%x)\n", iface, dwFlags);
1713 static HRESULT WINAPI MimeMessage_HandsOffStorage(
1714 IMimeMessage *iface)
1716 FIXME("(%p)->()\n", iface);
1720 static HRESULT find_body(struct list *list, HBODY hbody, body_t **body)
1725 if(hbody == HBODY_ROOT)
1727 *body = LIST_ENTRY(list_head(list), body_t, entry);
1731 LIST_FOR_EACH_ENTRY(cur, list, body_t, entry)
1733 if(cur->hbody == hbody)
1738 hr = find_body(&cur->children, hbody, body);
1739 if(hr == S_OK) return S_OK;
1744 static HRESULT WINAPI MimeMessage_BindToObject(
1745 IMimeMessage *iface,
1750 MimeMessage *This = (MimeMessage *)iface;
1754 TRACE("(%p)->(%p, %s, %p)\n", iface, hBody, debugstr_guid(riid), ppvObject);
1756 hr = find_body(&This->body_tree, hBody, &body);
1758 if(hr != S_OK) return hr;
1760 if(IsEqualIID(riid, &IID_IMimeBody))
1762 IMimeBody_AddRef(body->mime_body);
1763 *ppvObject = body->mime_body;
1767 return E_NOINTERFACE;
1770 static HRESULT WINAPI MimeMessage_SaveBody(
1771 IMimeMessage *iface,
1776 FIXME("(%p)->(%p, 0x%x, %p)\n", iface, hBody, dwFlags, pStream);
1780 static HRESULT get_body(MimeMessage *msg, BODYLOCATION location, HBODY pivot, body_t **out)
1782 body_t *root = LIST_ENTRY(list_head(&msg->body_tree), body_t, entry);
1787 if(location == IBL_ROOT)
1793 hr = find_body(&msg->body_tree, pivot, &body);
1800 *out = body->parent;
1804 list = list_head(&body->children);
1806 *out = LIST_ENTRY(list, body_t, entry);
1808 hr = MIME_E_NOT_FOUND;
1812 list = list_tail(&body->children);
1814 *out = LIST_ENTRY(list, body_t, entry);
1816 hr = MIME_E_NOT_FOUND;
1820 list = list_next(&body->parent->children, &body->entry);
1822 *out = LIST_ENTRY(list, body_t, entry);
1824 hr = MIME_E_NOT_FOUND;
1828 list = list_prev(&body->parent->children, &body->entry);
1830 *out = LIST_ENTRY(list, body_t, entry);
1832 hr = MIME_E_NOT_FOUND;
1845 static HRESULT WINAPI MimeMessage_InsertBody(
1846 IMimeMessage *iface,
1847 BODYLOCATION location,
1851 FIXME("(%p)->(%d, %p, %p)\n", iface, location, hPivot, phBody);
1855 static HRESULT WINAPI MimeMessage_GetBody(
1856 IMimeMessage *iface,
1857 BODYLOCATION location,
1861 MimeMessage *This = (MimeMessage *)iface;
1865 TRACE("(%p)->(%d, %p, %p)\n", iface, location, hPivot, phBody);
1867 hr = get_body(This, location, hPivot, &body);
1869 if(hr == S_OK) *phBody = body->hbody;
1874 static HRESULT WINAPI MimeMessage_DeleteBody(
1875 IMimeMessage *iface,
1879 FIXME("(%p)->(%p, %08x)\n", iface, hBody, dwFlags);
1883 static HRESULT WINAPI MimeMessage_MoveBody(
1884 IMimeMessage *iface,
1886 BODYLOCATION location)
1888 FIXME("(%p)->(%d)\n", iface, location);
1892 static void count_children(body_t *body, boolean recurse, ULONG *count)
1896 LIST_FOR_EACH_ENTRY(child, &body->children, body_t, entry)
1899 if(recurse) count_children(child, recurse, count);
1903 static HRESULT WINAPI MimeMessage_CountBodies(
1904 IMimeMessage *iface,
1910 MimeMessage *This = (MimeMessage *)iface;
1913 TRACE("(%p)->(%p, %s, %p)\n", iface, hParent, fRecurse ? "TRUE" : "FALSE", pcBodies);
1915 hr = find_body(&This->body_tree, hParent, &body);
1916 if(hr != S_OK) return hr;
1919 count_children(body, fRecurse, pcBodies);
1924 static HRESULT find_next(IMimeMessage *msg, LPFINDBODY find_body, HBODY *out)
1927 IMimeBody *mime_body;
1930 if(find_body->dwReserved == 0)
1931 find_body->dwReserved = (DWORD)HBODY_ROOT;
1934 hr = IMimeMessage_GetBody(msg, IBL_FIRST, (HBODY)find_body->dwReserved, &next);
1936 find_body->dwReserved = (DWORD)next;
1939 hr = IMimeMessage_GetBody(msg, IBL_NEXT, (HBODY)find_body->dwReserved, &next);
1941 find_body->dwReserved = (DWORD)next;
1943 return MIME_E_NOT_FOUND;
1947 hr = IMimeMessage_BindToObject(msg, (HBODY)find_body->dwReserved, &IID_IMimeBody, (void**)&mime_body);
1948 if(IMimeBody_IsContentType(mime_body, find_body->pszPriType, find_body->pszSubType) == S_OK)
1950 IMimeBody_Release(mime_body);
1951 *out = (HBODY)find_body->dwReserved;
1954 IMimeBody_Release(mime_body);
1955 return find_next(msg, find_body, out);
1958 static HRESULT WINAPI MimeMessage_FindFirst(
1959 IMimeMessage *iface,
1960 LPFINDBODY pFindBody,
1963 TRACE("(%p)->(%p, %p)\n", iface, pFindBody, phBody);
1965 pFindBody->dwReserved = 0;
1966 return find_next(iface, pFindBody, phBody);
1969 static HRESULT WINAPI MimeMessage_FindNext(
1970 IMimeMessage *iface,
1971 LPFINDBODY pFindBody,
1974 TRACE("(%p)->(%p, %p)\n", iface, pFindBody, phBody);
1976 return find_next(iface, pFindBody, phBody);
1979 static HRESULT WINAPI MimeMessage_ResolveURL(
1980 IMimeMessage *iface,
1987 FIXME("(%p)->(%p, %s, %s, 0x%x, %p)\n", iface, hRelated, pszBase, pszURL, dwFlags, phBody);
1991 static HRESULT WINAPI MimeMessage_ToMultipart(
1992 IMimeMessage *iface,
1995 LPHBODY phMultipart)
1997 FIXME("(%p)->(%p, %s, %p)\n", iface, hBody, pszSubType, phMultipart);
2001 static HRESULT WINAPI MimeMessage_GetBodyOffsets(
2002 IMimeMessage *iface,
2004 LPBODYOFFSETS pOffsets)
2006 FIXME("(%p)->(%p, %p)\n", iface, hBody, pOffsets);
2010 static HRESULT WINAPI MimeMessage_GetCharset(
2011 IMimeMessage *iface,
2012 LPHCHARSET phCharset)
2014 FIXME("(%p)->(%p)\n", iface, phCharset);
2018 static HRESULT WINAPI MimeMessage_SetCharset(
2019 IMimeMessage *iface,
2021 CSETAPPLYTYPE applytype)
2023 FIXME("(%p)->(%p, %d)\n", iface, hCharset, applytype);
2027 static HRESULT WINAPI MimeMessage_IsBodyType(
2028 IMimeMessage *iface,
2030 IMSGBODYTYPE bodytype)
2033 IMimeBody *mime_body;
2034 TRACE("(%p)->(%p, %d)\n", iface, hBody, bodytype);
2036 hr = IMimeMessage_BindToObject(iface, hBody, &IID_IMimeBody, (void**)&mime_body);
2037 if(hr != S_OK) return hr;
2039 hr = IMimeBody_IsType(mime_body, bodytype);
2040 MimeBody_Release(mime_body);
2044 static HRESULT WINAPI MimeMessage_IsContentType(
2045 IMimeMessage *iface,
2051 IMimeBody *mime_body;
2052 TRACE("(%p)->(%p, %s, %s)\n", iface, hBody, pszPriType, pszSubType);
2054 hr = IMimeMessage_BindToObject(iface, hBody, &IID_IMimeBody, (void**)&mime_body);
2055 if(FAILED(hr)) return hr;
2057 hr = IMimeBody_IsContentType(mime_body, pszPriType, pszSubType);
2058 IMimeBody_Release(mime_body);
2062 static HRESULT WINAPI MimeMessage_QueryBodyProp(
2063 IMimeMessage *iface,
2068 boolean fCaseSensitive)
2070 FIXME("(%p)->(%p, %s, %s, %s, %s)\n", iface, hBody, pszName, pszCriteria, fSubString ? "TRUE" : "FALSE", fCaseSensitive ? "TRUE" : "FALSE");
2074 static HRESULT WINAPI MimeMessage_GetBodyProp(
2075 IMimeMessage *iface,
2079 LPPROPVARIANT pValue)
2082 IMimeBody *mime_body;
2084 TRACE("(%p)->(%p, %s, 0x%x, %p)\n", iface, hBody, pszName, dwFlags, pValue);
2086 hr = IMimeMessage_BindToObject(iface, hBody, &IID_IMimeBody, (void**)&mime_body);
2087 if(hr != S_OK) return hr;
2089 hr = IMimeBody_GetProp(mime_body, pszName, dwFlags, pValue);
2090 IMimeBody_Release(mime_body);
2095 static HRESULT WINAPI MimeMessage_SetBodyProp(
2096 IMimeMessage *iface,
2100 LPCPROPVARIANT pValue)
2102 FIXME("(%p)->(%p, %s, 0x%x, %p)\n", iface, hBody, pszName, dwFlags, pValue);
2106 static HRESULT WINAPI MimeMessage_DeleteBodyProp(
2107 IMimeMessage *iface,
2111 FIXME("(%p)->(%p, %s)\n", iface, hBody, pszName);
2115 static HRESULT WINAPI MimeMessage_SetOption(
2116 IMimeMessage *iface,
2118 LPCPROPVARIANT pValue)
2120 FIXME("(%p)->(%d, %p)\n", iface, oid, pValue);
2124 static HRESULT WINAPI MimeMessage_GetOption(
2125 IMimeMessage *iface,
2127 LPPROPVARIANT pValue)
2129 FIXME("(%p)->(%d, %p)\n", iface, oid, pValue);
2133 /*** IMimeMessage methods ***/
2134 static HRESULT WINAPI MimeMessage_CreateWebPage(
2135 IMimeMessage *iface,
2137 LPWEBPAGEOPTIONS pOptions,
2138 IMimeMessageCallback *pCallback,
2139 IMoniker **ppMoniker)
2141 FIXME("(%p)->(%p, %p, %p, %p)\n", iface, pRootStm, pOptions, pCallback, ppMoniker);
2146 static HRESULT WINAPI MimeMessage_GetProp(
2147 IMimeMessage *iface,
2150 LPPROPVARIANT pValue)
2152 FIXME("(%p)->(%s, 0x%x, %p)\n", iface, pszName, dwFlags, pValue);
2156 static HRESULT WINAPI MimeMessage_SetProp(
2157 IMimeMessage *iface,
2160 LPCPROPVARIANT pValue)
2162 FIXME("(%p)->(%s, 0x%x, %p)\n", iface, pszName, dwFlags, pValue);
2166 static HRESULT WINAPI MimeMessage_DeleteProp(
2167 IMimeMessage *iface,
2170 FIXME("(%p)->(%s)\n", iface, pszName);
2174 static HRESULT WINAPI MimeMessage_QueryProp(
2175 IMimeMessage *iface,
2179 boolean fCaseSensitive)
2181 FIXME("(%p)->(%s, %s, %s, %s)\n", iface, pszName, pszCriteria, fSubString ? "TRUE" : "FALSE", fCaseSensitive ? "TRUE" : "FALSE");
2185 static HRESULT WINAPI MimeMessage_GetTextBody(
2186 IMimeMessage *iface,
2188 ENCODINGTYPE ietEncoding,
2194 FINDBODY find_struct;
2195 IMimeBody *mime_body;
2196 static char text[] = "text";
2197 static char plain[] = "plain";
2198 static char html[] = "html";
2200 TRACE("(%p)->(%d, %d, %p, %p)\n", iface, dwTxtType, ietEncoding, pStream, phBody);
2202 find_struct.pszPriType = text;
2207 find_struct.pszSubType = plain;
2210 find_struct.pszSubType = html;
2213 return MIME_E_INVALID_TEXT_TYPE;
2216 hr = IMimeMessage_FindFirst(iface, &find_struct, &hbody);
2219 TRACE("not found hr %08x\n", hr);
2224 IMimeMessage_BindToObject(iface, hbody, &IID_IMimeBody, (void**)&mime_body);
2226 IMimeBody_GetData(mime_body, ietEncoding, pStream);
2228 IMimeBody_Release(mime_body);
2232 static HRESULT WINAPI MimeMessage_SetTextBody(
2233 IMimeMessage *iface,
2235 ENCODINGTYPE ietEncoding,
2240 FIXME("(%p)->(%d, %d, %p, %p, %p)\n", iface, dwTxtType, ietEncoding, hAlternative, pStream, phBody);
2244 static HRESULT WINAPI MimeMessage_AttachObject(
2245 IMimeMessage *iface,
2250 FIXME("(%p)->(%s, %p, %p)\n", iface, debugstr_guid(riid), pvObject, phBody);
2254 static HRESULT WINAPI MimeMessage_AttachFile(
2255 IMimeMessage *iface,
2260 FIXME("(%p)->(%s, %p, %p)\n", iface, pszFilePath, pstmFile, phBody);
2264 static HRESULT WINAPI MimeMessage_AttachURL(
2265 IMimeMessage *iface,
2273 FIXME("(%p)->(%s, %s, 0x%x, %p, %p, %p)\n", iface, pszBase, pszURL, dwFlags, pstmURL, ppszCIDURL, phBody);
2277 static HRESULT WINAPI MimeMessage_GetAttachments(
2278 IMimeMessage *iface,
2280 LPHBODY *pprghAttach)
2282 FIXME("(%p)->(%p, %p)\n", iface, pcAttach, pprghAttach);
2286 static HRESULT WINAPI MimeMessage_GetAddressTable(
2287 IMimeMessage *iface,
2288 IMimeAddressTable **ppTable)
2290 FIXME("(%p)->(%p)\n", iface, ppTable);
2294 static HRESULT WINAPI MimeMessage_GetSender(
2295 IMimeMessage *iface,
2296 LPADDRESSPROPS pAddress)
2298 FIXME("(%p)->(%p)\n", iface, pAddress);
2302 static HRESULT WINAPI MimeMessage_GetAddressTypes(
2303 IMimeMessage *iface,
2306 LPADDRESSLIST pList)
2308 FIXME("(%p)->(%d, %d, %p)\n", iface, dwAdrTypes, dwProps, pList);
2312 static HRESULT WINAPI MimeMessage_GetAddressFormat(
2313 IMimeMessage *iface,
2315 ADDRESSFORMAT format,
2318 FIXME("(%p)->(%d, %d, %p)\n", iface, dwAdrTypes, format, ppszFormat);
2322 static HRESULT WINAPI MimeMessage_EnumAddressTypes(
2323 IMimeMessage *iface,
2326 IMimeEnumAddressTypes **ppEnum)
2328 FIXME("(%p)->(%d, %d, %p)\n", iface, dwAdrTypes, dwProps, ppEnum);
2332 static HRESULT WINAPI MimeMessage_SplitMessage(
2333 IMimeMessage *iface,
2335 IMimeMessageParts **ppParts)
2337 FIXME("(%p)->(%d, %p)\n", iface, cbMaxPart, ppParts);
2341 static HRESULT WINAPI MimeMessage_GetRootMoniker(
2342 IMimeMessage *iface,
2343 IMoniker **ppMoniker)
2345 FIXME("(%p)->(%p)\n", iface, ppMoniker);
2349 static const IMimeMessageVtbl MimeMessageVtbl =
2351 MimeMessage_QueryInterface,
2353 MimeMessage_Release,
2354 MimeMessage_GetClassID,
2355 MimeMessage_IsDirty,
2358 MimeMessage_GetSizeMax,
2359 MimeMessage_InitNew,
2360 MimeMessage_GetMessageSource,
2361 MimeMessage_GetMessageSize,
2362 MimeMessage_LoadOffsetTable,
2363 MimeMessage_SaveOffsetTable,
2364 MimeMessage_GetFlags,
2366 MimeMessage_HandsOffStorage,
2367 MimeMessage_BindToObject,
2368 MimeMessage_SaveBody,
2369 MimeMessage_InsertBody,
2370 MimeMessage_GetBody,
2371 MimeMessage_DeleteBody,
2372 MimeMessage_MoveBody,
2373 MimeMessage_CountBodies,
2374 MimeMessage_FindFirst,
2375 MimeMessage_FindNext,
2376 MimeMessage_ResolveURL,
2377 MimeMessage_ToMultipart,
2378 MimeMessage_GetBodyOffsets,
2379 MimeMessage_GetCharset,
2380 MimeMessage_SetCharset,
2381 MimeMessage_IsBodyType,
2382 MimeMessage_IsContentType,
2383 MimeMessage_QueryBodyProp,
2384 MimeMessage_GetBodyProp,
2385 MimeMessage_SetBodyProp,
2386 MimeMessage_DeleteBodyProp,
2387 MimeMessage_SetOption,
2388 MimeMessage_GetOption,
2389 MimeMessage_CreateWebPage,
2390 MimeMessage_GetProp,
2391 MimeMessage_SetProp,
2392 MimeMessage_DeleteProp,
2393 MimeMessage_QueryProp,
2394 MimeMessage_GetTextBody,
2395 MimeMessage_SetTextBody,
2396 MimeMessage_AttachObject,
2397 MimeMessage_AttachFile,
2398 MimeMessage_AttachURL,
2399 MimeMessage_GetAttachments,
2400 MimeMessage_GetAddressTable,
2401 MimeMessage_GetSender,
2402 MimeMessage_GetAddressTypes,
2403 MimeMessage_GetAddressFormat,
2404 MimeMessage_EnumAddressTypes,
2405 MimeMessage_SplitMessage,
2406 MimeMessage_GetRootMoniker,
2409 /***********************************************************************
2410 * MimeOleCreateMessage (INETCOMM.@)
2412 HRESULT WINAPI MimeOleCreateMessage(IUnknown *pUnkOuter, IMimeMessage **ppMessage)
2416 TRACE("(%p, %p)\n", pUnkOuter, ppMessage);
2420 FIXME("outer unknown not supported yet\n");
2426 This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
2427 if (!This) return E_OUTOFMEMORY;
2429 This->lpVtbl = &MimeMessageVtbl;
2431 This->stream = NULL;
2432 list_init(&This->body_tree);
2433 This->next_hbody = (HBODY)1;
2435 *ppMessage = (IMimeMessage *)&This->lpVtbl;
2439 /***********************************************************************
2440 * MimeOleSetCompatMode (INETCOMM.@)
2442 HRESULT WINAPI MimeOleSetCompatMode(DWORD dwMode)
2444 FIXME("(0x%x)\n", dwMode);
2448 /***********************************************************************
2449 * MimeOleCreateVirtualStream (INETCOMM.@)
2451 HRESULT WINAPI MimeOleCreateVirtualStream(IStream **ppStream)
2454 FIXME("(%p)\n", ppStream);
2456 hr = CreateStreamOnHGlobal(NULL, TRUE, ppStream);
2460 typedef struct MimeSecurity
2462 const IMimeSecurityVtbl *lpVtbl;
2467 static HRESULT WINAPI MimeSecurity_QueryInterface(
2468 IMimeSecurity* iface,
2472 TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), obj);
2474 if (IsEqualIID(riid, &IID_IUnknown) ||
2475 IsEqualIID(riid, &IID_IMimeSecurity))
2478 IUnknown_AddRef(iface);
2482 FIXME("no interface for %s\n", debugstr_guid(riid));
2484 return E_NOINTERFACE;
2487 static ULONG WINAPI MimeSecurity_AddRef(
2488 IMimeSecurity* iface)
2490 MimeSecurity *This = (MimeSecurity *)iface;
2491 TRACE("(%p)->()\n", iface);
2492 return InterlockedIncrement(&This->refs);
2495 static ULONG WINAPI MimeSecurity_Release(
2496 IMimeSecurity* iface)
2498 MimeSecurity *This = (MimeSecurity *)iface;
2501 TRACE("(%p)->()\n", iface);
2503 refs = InterlockedDecrement(&This->refs);
2506 HeapFree(GetProcessHeap(), 0, This);
2512 static HRESULT WINAPI MimeSecurity_InitNew(
2513 IMimeSecurity* iface)
2515 FIXME("(%p)->(): stub\n", iface);
2519 static HRESULT WINAPI MimeSecurity_CheckInit(
2520 IMimeSecurity* iface)
2522 FIXME("(%p)->(): stub\n", iface);
2526 static HRESULT WINAPI MimeSecurity_EncodeMessage(
2527 IMimeSecurity* iface,
2528 IMimeMessageTree* pTree,
2531 FIXME("(%p)->(%p, %08x): stub\n", iface, pTree, dwFlags);
2535 static HRESULT WINAPI MimeSecurity_EncodeBody(
2536 IMimeSecurity* iface,
2537 IMimeMessageTree* pTree,
2541 FIXME("(%p)->(%p, %p, %08x): stub\n", iface, pTree, hEncodeRoot, dwFlags);
2545 static HRESULT WINAPI MimeSecurity_DecodeMessage(
2546 IMimeSecurity* iface,
2547 IMimeMessageTree* pTree,
2550 FIXME("(%p)->(%p, %08x): stub\n", iface, pTree, dwFlags);
2554 static HRESULT WINAPI MimeSecurity_DecodeBody(
2555 IMimeSecurity* iface,
2556 IMimeMessageTree* pTree,
2560 FIXME("(%p)->(%p, %p, %08x): stub\n", iface, pTree, hDecodeRoot, dwFlags);
2564 static HRESULT WINAPI MimeSecurity_EnumCertificates(
2565 IMimeSecurity* iface,
2571 FIXME("(%p)->(%p, %08x, %p, %p): stub\n", iface, hc, dwUsage, pPrev, ppCert);
2575 static HRESULT WINAPI MimeSecurity_GetCertificateName(
2576 IMimeSecurity* iface,
2577 const PCX509CERT pX509Cert,
2578 const CERTNAMETYPE cn,
2581 FIXME("(%p)->(%p, %08x, %p): stub\n", iface, pX509Cert, cn, ppszName);
2585 static HRESULT WINAPI MimeSecurity_GetMessageType(
2586 IMimeSecurity* iface,
2587 const HWND hwndParent,
2591 FIXME("(%p)->(%p, %p, %p): stub\n", iface, hwndParent, pBody, pdwSecType);
2595 static HRESULT WINAPI MimeSecurity_GetCertData(
2596 IMimeSecurity* iface,
2597 const PCX509CERT pX509Cert,
2598 const CERTDATAID dataid,
2599 LPPROPVARIANT pValue)
2601 FIXME("(%p)->(%p, %x, %p): stub\n", iface, pX509Cert, dataid, pValue);
2606 static const IMimeSecurityVtbl MimeSecurityVtbl =
2608 MimeSecurity_QueryInterface,
2609 MimeSecurity_AddRef,
2610 MimeSecurity_Release,
2611 MimeSecurity_InitNew,
2612 MimeSecurity_CheckInit,
2613 MimeSecurity_EncodeMessage,
2614 MimeSecurity_EncodeBody,
2615 MimeSecurity_DecodeMessage,
2616 MimeSecurity_DecodeBody,
2617 MimeSecurity_EnumCertificates,
2618 MimeSecurity_GetCertificateName,
2619 MimeSecurity_GetMessageType,
2620 MimeSecurity_GetCertData
2623 /***********************************************************************
2624 * MimeOleCreateSecurity (INETCOMM.@)
2626 HRESULT WINAPI MimeOleCreateSecurity(IMimeSecurity **ppSecurity)
2630 TRACE("(%p)\n", ppSecurity);
2634 This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
2635 if (!This) return E_OUTOFMEMORY;
2637 This->lpVtbl = &MimeSecurityVtbl;
2640 *ppSecurity = (IMimeSecurity *)&This->lpVtbl;
2647 IMimeAllocatorVtbl *lpVtbl;
2650 static HRESULT WINAPI MimeAlloc_QueryInterface(
2651 IMimeAllocator* iface,
2655 TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), obj);
2657 if (IsEqualIID(riid, &IID_IUnknown) ||
2658 IsEqualIID(riid, &IID_IMalloc) ||
2659 IsEqualIID(riid, &IID_IMimeAllocator))
2662 IUnknown_AddRef(iface);
2666 FIXME("no interface for %s\n", debugstr_guid(riid));
2668 return E_NOINTERFACE;
2671 static ULONG WINAPI MimeAlloc_AddRef(
2672 IMimeAllocator* iface)
2677 static ULONG WINAPI MimeAlloc_Release(
2678 IMimeAllocator* iface)
2683 static LPVOID WINAPI MimeAlloc_Alloc(
2684 IMimeAllocator* iface,
2687 return CoTaskMemAlloc(cb);
2690 static LPVOID WINAPI MimeAlloc_Realloc(
2691 IMimeAllocator* iface,
2695 return CoTaskMemRealloc(pv, cb);
2698 static void WINAPI MimeAlloc_Free(
2699 IMimeAllocator* iface,
2702 return CoTaskMemFree(pv);
2705 static ULONG WINAPI MimeAlloc_GetSize(
2706 IMimeAllocator* iface,
2713 static int WINAPI MimeAlloc_DidAlloc(
2714 IMimeAllocator* iface,
2721 static void WINAPI MimeAlloc_HeapMinimize(
2722 IMimeAllocator* iface)
2728 static HRESULT WINAPI MimeAlloc_FreeParamInfoArray(
2729 IMimeAllocator* iface,
2731 LPMIMEPARAMINFO prgParam,
2735 TRACE("(%p)->(%d, %p, %d)\n", iface, cParams, prgParam, fFreeArray);
2737 for(i = 0; i < cParams; i++)
2739 IMimeAllocator_Free(iface, prgParam[i].pszName);
2740 IMimeAllocator_Free(iface, prgParam[i].pszData);
2742 if(fFreeArray) IMimeAllocator_Free(iface, prgParam);
2746 static HRESULT WINAPI MimeAlloc_FreeAddressList(
2747 IMimeAllocator* iface,
2748 LPADDRESSLIST pList)
2754 static HRESULT WINAPI MimeAlloc_FreeAddressProps(
2755 IMimeAllocator* iface,
2756 LPADDRESSPROPS pAddress)
2762 static HRESULT WINAPI MimeAlloc_ReleaseObjects(
2763 IMimeAllocator* iface,
2765 IUnknown **prgpUnknown,
2773 static HRESULT WINAPI MimeAlloc_FreeEnumHeaderRowArray(
2774 IMimeAllocator* iface,
2776 LPENUMHEADERROW prgRow,
2783 static HRESULT WINAPI MimeAlloc_FreeEnumPropertyArray(
2784 IMimeAllocator* iface,
2786 LPENUMPROPERTY prgProp,
2793 static HRESULT WINAPI MimeAlloc_FreeThumbprint(
2794 IMimeAllocator* iface,
2795 THUMBBLOB *pthumbprint)
2802 static HRESULT WINAPI MimeAlloc_PropVariantClear(
2803 IMimeAllocator* iface,
2804 LPPROPVARIANT pProp)
2810 static IMimeAllocatorVtbl mime_alloc_vtbl =
2812 MimeAlloc_QueryInterface,
2820 MimeAlloc_HeapMinimize,
2821 MimeAlloc_FreeParamInfoArray,
2822 MimeAlloc_FreeAddressList,
2823 MimeAlloc_FreeAddressProps,
2824 MimeAlloc_ReleaseObjects,
2825 MimeAlloc_FreeEnumHeaderRowArray,
2826 MimeAlloc_FreeEnumPropertyArray,
2827 MimeAlloc_FreeThumbprint,
2828 MimeAlloc_PropVariantClear
2831 static MimeAllocator mime_allocator =
2836 HRESULT MimeAllocator_create(IUnknown *outer, void **obj)
2838 if(outer) return CLASS_E_NOAGGREGATION;
2840 *obj = &mime_allocator;
2844 HRESULT WINAPI MimeOleGetAllocator(IMimeAllocator **alloc)
2846 return MimeAllocator_create(NULL, (void**)alloc);