2 OpenChange MAPI torture suite implementation.
4 Delete mail from an Exchange server
6 Copyright (C) Fabien Le Mentec 2007
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include <libmapi/libmapi.h>
23 #include <libmapi/defs_private.h>
25 #include <credentials.h>
26 #include <torture/mapi_torture.h>
28 #include <torture/torture_proto.h>
29 #include <samba/popt.h>
35 bool torture_rpc_mapi_deletemail(struct torture_context *torture)
37 enum MAPISTATUS retval;
40 const char *s_subject = lp_parm_string(torture->lp_ctx, NULL, "mapi", "subject");
42 struct mapi_session *session;
43 mapi_object_t obj_store;
44 mapi_object_t obj_inbox;
45 mapi_object_t obj_table;
47 mapi_id_t *id_messages;
48 unsigned long cn_messages;
49 struct SRowSet rowset;
51 unsigned long cn_rows;
52 struct SPropTagArray *SPropTagArray;
56 mem_ctx = talloc_named(NULL, 0, "torture_rpc_mapi_deletemail");
59 if ((session = torture_init_mapi(mem_ctx, torture->lp_ctx)) == NULL) return false;
62 mapi_object_init(&obj_store);
63 mapi_object_init(&obj_inbox);
64 mapi_object_init(&obj_table);
66 /* session::OpenMsgStore() */
67 retval = OpenMsgStore(session, &obj_store);
68 mapi_errstr("OpenMsgStore", GetLastError());
69 if (retval != MAPI_E_SUCCESS) return false;
70 mapi_object_debug(&obj_store);
72 /* id_inbox = store->GetReceiveFolder */
73 retval = GetReceiveFolder(&obj_store, &id_inbox, NULL);
74 mapi_errstr("GetReceiveFolder", GetLastError());
75 if (retval != MAPI_E_SUCCESS) return false;
77 /* inbox = store->OpenFolder()
79 retval = OpenFolder(&obj_store, id_inbox, &obj_inbox);
80 mapi_errstr("OpenFolder", GetLastError());
81 if (retval != MAPI_E_SUCCESS) return false;
82 mapi_object_debug(&obj_inbox);
84 /* table = inbox->GetContentsTable() */
85 retval = GetContentsTable(&obj_inbox, &obj_table, 0, NULL);
86 mapi_errstr("GetContentsTable", GetLastError());
87 if (retval != MAPI_E_SUCCESS) return false;
88 mapi_object_debug(&obj_table);
90 /* rowset = table->QueryRows() */
91 SPropTagArray = set_SPropTagArray(mem_ctx, 0x5,
97 retval = SetColumns(&obj_table, SPropTagArray);
98 mapi_errstr("SetColumns", GetLastError());
99 if (retval != MAPI_E_SUCCESS) return false;
101 while ((retval = QueryRows(&obj_table, CN_ROWS, TBL_ADVANCE, &rowset)) == MAPI_E_SUCCESS) {
102 cn_rows = rowset.cRows;
104 id_messages = talloc_array(mem_ctx, uint64_t, cn_rows);
108 s_subject = "default_subject";
109 len_subject = strlen(s_subject);
111 for (i_row = 0; i_row < cn_rows; ++i_row) {
112 if (strncmp(rowset.aRow[i_row].lpProps[4].value.lpszA, s_subject, len_subject) == 0) {
113 id_messages[cn_messages] = rowset.aRow[i_row].lpProps[1].value.d;
115 DEBUG(0, ("delete(%"PRIx64")\n", id_messages[cn_messages - 1]));
119 /* IMessage::DeleteMessages() */
121 retval = DeleteMessage(&obj_inbox, id_messages, cn_messages);
122 if (retval != MAPI_E_SUCCESS) {
123 mapi_errstr("DeleteMessages", GetLastError());
130 mapi_object_release(&obj_store);
131 mapi_object_release(&obj_inbox);
132 mapi_object_release(&obj_table);
137 talloc_free(mem_ctx);