// @pymethod |PyIPropertyStorage|SetTimes|Sets the creation, last access, and modification time // @comm Some property sets do not support these times. PyObject *PyIPropertyStorage::SetTimes(PyObject *self, PyObject *args) { IPropertyStorage *pIPS = GetI(self); if ( pIPS == NULL ) return NULL; // @pyparm <o PyTime>|pctime||Creation time // @pyparm <o PyTime>|patime||Last access time // @pyparm <o PyTime>|pmtime||Modification time PyObject *obpctime; PyObject *obpatime; PyObject *obpmtime; FILETIME pctime; FILETIME patime; FILETIME pmtime; if ( !PyArg_ParseTuple(args, "OOO:SetTimes", &obpctime, &obpatime, &obpmtime) ) return NULL; BOOL bPythonIsHappy = TRUE; if (!PyWinObject_AsFILETIME(obpctime, &pctime)) return NULL; if (!PyWinObject_AsFILETIME(obpatime, &patime)) return NULL; if (!PyWinObject_AsFILETIME(obpmtime, &pmtime)) return NULL; HRESULT hr; PY_INTERFACE_PRECALL; hr = pIPS->SetTimes( &pctime, &patime, &pmtime ); PY_INTERFACE_POSTCALL; if ( FAILED(hr) ) return PyCom_BuildPyException(hr, pIPS, IID_IPropertyStorage); Py_INCREF(Py_None); return Py_None; }
// @pymethod |PyIStorage|SetElementTimes|Sets the modification, access, and creation times of the specified storage element, if supported by the underlying file system. PyObject *PyIStorage::SetElementTimes(PyObject *self, PyObject *args) { IStorage *pIS = GetI(self); if ( pIS == NULL ) return NULL; // @pyparm string|name||The name of the storage object element whose times are to be modified. If NULL, the time is set on the root storage rather than one of its elements. // @pyparm <o PyTime>|ctime||Either the new creation time for the element or None if the creation time is not to be modified. // @pyparm <o PyTime>|atime||Either the new access time for the element or None if the access time is not to be modified. // @pyparm <o PyTime>|mtime||Either the new modification time for the element or None if the modification time is not to be modified. PyObject *obName; PyObject *obpctime; PyObject *obpatime; PyObject *obpmtime; if ( !PyArg_ParseTuple(args, "OOOO:SetElementTimes", &obName, &obpctime, &obpatime, &obpmtime) ) return NULL; FILETIME *pctime=NULL, ctime; FILETIME *patime=NULL, atime; FILETIME *pmtime=NULL, mtime; if (obpctime!=Py_None) { if (!PyWinObject_AsFILETIME(obpctime, &ctime)) return NULL; pctime = &ctime; } if (obpatime != Py_None) { if (!PyWinObject_AsFILETIME(obpatime, &atime)) return NULL; patime = &atime; } if (obpmtime != Py_None) { if (!PyWinObject_AsFILETIME(obpmtime, &mtime)) return NULL; pmtime = &mtime; } BSTR bstrName; if (!PyWinObject_AsBstr(obName, &bstrName)) return NULL; PY_INTERFACE_PRECALL; HRESULT hr = pIS->SetElementTimes( bstrName, pctime, patime, pmtime ); PyWinObject_FreeBstr(bstrName); PY_INTERFACE_POSTCALL; if ( FAILED(hr) ) return PyCom_BuildPyException(hr, pIS, IID_IStorage); Py_INCREF(Py_None); return Py_None; }
// @pymethod |PyIPropertyStorage|SetTimes|Sets the creation, last access, and modification time // @comm Some property sets do not support these times. PyObject *PyIPropertyStorage::SetTimes(PyObject *self, PyObject *args) { IPropertyStorage *pIPS = GetI(self); if ( pIPS == NULL ) return NULL; // @pyparm <o PyTime>|ctime||Creation time, or None for no change // @pyparm <o PyTime>|atime||Last access time, or None for no change // @pyparm <o PyTime>|mtime||Modification time, or None for no change PyObject *obctime; PyObject *obatime; PyObject *obmtime; FILETIME ctime, *pctime=NULL; FILETIME atime, *patime=NULL; FILETIME mtime, *pmtime=NULL; if ( !PyArg_ParseTuple(args, "OOO:SetTimes", &obctime, &obatime, &obmtime) ) return NULL; if (obctime != Py_None){ if (!PyWinObject_AsFILETIME(obctime, &ctime)) return NULL; pctime = &ctime; } if (obatime != Py_None){ if (!PyWinObject_AsFILETIME(obatime, &atime)) return NULL; patime = &atime; } if (obmtime != Py_None){ if (!PyWinObject_AsFILETIME(obmtime, &mtime)) return NULL; pmtime = &mtime; } HRESULT hr; PY_INTERFACE_PRECALL; hr = pIPS->SetTimes(pctime, patime, pmtime); PY_INTERFACE_POSTCALL; if ( FAILED(hr) ) return PyCom_BuildPyException(hr, pIPS, IID_IPropertyStorage); Py_INCREF(Py_None); return Py_None; }
// @object PySPropValue|A MAPI property value. Property values can either be passed from // python into MAPI functions, or returned from MAPI functions to Python. BOOL PyMAPIObject_AsSPropValue(PyObject *Valob, SPropValue *pv, void *pAllocMoreLinkBlock) { PyObject *ob; // @pyparm int|propType||The type of the MAPI property // @pyparm object|value||The property value if (!PyArg_ParseTuple(Valob, "lO:SPropValue item", &pv->ulPropTag, &ob )) { PyErr_Clear(); PyErr_SetString(PyExc_TypeError, "An SPropValue item must be a tuple of (integer, object)"); return NULL; } BOOL ok = TRUE; unsigned int i; PyErr_Clear(); // @comm The parameters can be one of the following pairs of values. // @flagh propType|value switch (PROP_TYPE(pv->ulPropTag)) { // @flag PT_I2|An integer case PT_I2: // case PT_SHORT: pv->Value.i = (int)PyInt_AsLong(ob); break; // @flag PT_MV_I2|A sequence of integers case PT_MV_I2: MAKE_MV(short int, pAllocMoreLinkBlock, pv->Value.MVi.lpi, pv->Value.MVi.cValues, PyInt_AsLong) // @flag PT_I4|An integer case PT_I4: // case PT_LONG: pv->Value.l = PyInt_AsLong(ob); break; // @flag PT_MV_I4|A sequence of integers case PT_MV_I4: MAKE_MV(long, pAllocMoreLinkBlock, pv->Value.MVl.lpl, pv->Value.MVl.cValues, PyInt_AsLong) // @flag PT_R4|A float case PT_R4: // case PT_FLOAT: pv->Value.flt = (float)PyFloat_AsDouble(ob); break; // @flag PT_MV_R4|A sequence of floats case PT_MV_R4: MAKE_MV(float, pAllocMoreLinkBlock, pv->Value.MVflt.lpflt, pv->Value.MVflt.cValues, PyFloat_AsDouble) // @flag PT_R8|A float case PT_R8: // case PT_DOUBLE: pv->Value.dbl = PyFloat_AsDouble(ob); break; // @flag PT_MV_R8|A sequence of floats case PT_MV_R8: MAKE_MV(double, pAllocMoreLinkBlock, pv->Value.MVdbl.lpdbl, pv->Value.MVdbl.cValues, PyFloat_AsDouble) // @flag PT_BOOLEAN|A boolean value (or an int) case PT_BOOLEAN: pv->Value.b = PyInt_AsLong(ob) ? VARIANT_TRUE : VARIANT_FALSE; break; /* case PT_CURRENCY: p->Value.cur ?? break; */ // @flag PT_APPTIME|A <o PyTime> object case PT_APPTIME : ok = PyWinObject_AsDATE(ob, &pv->Value.at); break; // @flag PT_MV_APPTIME|An sequence of <o PyTime> object case PT_MV_APPTIME: MAKEB_MV(double, pAllocMoreLinkBlock, pv->Value.MVat.lpat, pv->Value.MVat.cValues, PyWinObject_AsDATE) // @flag PT_SYSTIME|A <o PyTime> object case PT_SYSTIME: ok = PyWinObject_AsFILETIME(ob, &pv->Value.ft); break; // @flag PT_MV_APPTIME|An sequence of <o PyTime> object case PT_MV_SYSTIME: MAKEB_MV(FILETIME, pAllocMoreLinkBlock, pv->Value.MVft.lpft, pv->Value.MVft.cValues, PyWinObject_AsFILETIME) // @flag PT_STRING8|A string or <o PyUnicode> case PT_STRING8: { // Copy into new MAPI memory block DWORD bufLen; char *str; ok = PyWinObject_AsString(ob, &str, FALSE, &bufLen); if (ok) { bufLen++; HRESULT hr = MAPIAllocateMore(bufLen, pAllocMoreLinkBlock, (void **)&pv->Value.lpszA); if (S_OK!=hr) { OleSetOleError(hr); ok = FALSE; } else { memcpy(pv->Value.lpszA, str, bufLen-sizeof(char)); // Null terminate memcpy(((char *)pv->Value.lpszA)+(bufLen-sizeof(char)),"\0", sizeof(char)); } } PyWinObject_FreeString(str); break; } // @flag PT_STRING8|A sequence of string or <o PyUnicode> objects. case PT_MV_STRING8: ok = AllocMVBuffer( ob, sizeof(char *), pAllocMoreLinkBlock, (void **)&pv->Value.MVszA.lppszA, &pv->Value.MVszA.cValues); if (!ok) break; for (i=0; ok && !PyErr_Occurred() && i<pv->Value.MVszA.cValues; i++) { PyObject *obmv=PySequence_GetItem(ob,i); if (obmv==NULL) break; DWORD bufLen; char *str; ok = PyWinObject_AsString(obmv, &str, FALSE, &bufLen); if (ok) { bufLen++; HRESULT hr = MAPIAllocateMore(bufLen, pAllocMoreLinkBlock, (void **)&pv->Value.MVszA.lppszA[i]); if (S_OK!=hr) { OleSetOleError(hr); ok = FALSE; } else { memcpy(pv->Value.MVszA.lppszA[i], str, bufLen-sizeof(char)); // Null terminate memcpy(((char *)pv->Value.MVszA.lppszA[i])+(bufLen-sizeof(char)),"\0", sizeof(char)); } } PyWinObject_FreeString(str); Py_DECREF(obmv); } break; // @flag PT_UNICODE|A string or <o PyUnicode> case PT_UNICODE: { // Bit of a hack - need to copy into MAPI block. BSTR wstr = NULL; ok = PyWinObject_AsBstr(ob, &wstr, FALSE); if (ok) { DWORD bufSize = sizeof(WCHAR) * (SysStringLen(wstr)+1); HRESULT hr = MAPIAllocateMore(bufSize, pAllocMoreLinkBlock, (void **)&pv->Value.lpszW); if (S_OK!=hr) { OleSetOleError(hr); ok = FALSE; } else { memcpy(pv->Value.lpszW, wstr, bufSize-2); // Null terminate memcpy(((char *)pv->Value.lpszW)+(bufSize-2),"\0\0", 2); } } SysFreeString(wstr); break; } // @flag PT_MV_UNICODE|A sequence of string or <o PyUnicode> case PT_MV_UNICODE: ok = AllocMVBuffer( ob, sizeof(char *), pAllocMoreLinkBlock, (void **)&pv->Value.MVszW.lppszW, &pv->Value.MVszW.cValues); if (!ok) break; for (i=0; ok && !PyErr_Occurred() && i<pv->Value.MVszW.cValues; i++) { PyObject *obmv=PySequence_GetItem(ob,i); if (obmv==NULL) break; BSTR wstr = NULL; ok = PyWinObject_AsBstr(obmv, &wstr, FALSE); if (ok) { DWORD bufSize = sizeof(WCHAR) * (SysStringLen(wstr)+1); HRESULT hr = MAPIAllocateMore(bufSize, pAllocMoreLinkBlock, (void **)&pv->Value.MVszW.lppszW[i]); if (S_OK!=hr) { OleSetOleError(hr); ok = FALSE; } else { memcpy(pv->Value.MVszW.lppszW[i], wstr, bufSize-2); // Null terminate memcpy(((char *)pv->Value.MVszW.lppszW[i])+(bufSize-2),"\0\0", 2); } } SysFreeString(wstr); Py_DECREF(obmv); } break; // @flag PT_BINARY|A string containing binary data case PT_BINARY: pv->Value.bin.lpb = (unsigned char *)PyString_AsString(ob); pv->Value.bin.cb = PyString_Size(ob); break; // @flag PT_MV_BINARY|A sequence of strings containing binary data case PT_MV_BINARY: ok = AllocMVBuffer( ob, sizeof(SBinary), pAllocMoreLinkBlock, (void **)&pv->Value.MVbin.lpbin, &pv->Value.MVbin.cValues); for (i=0; !PyErr_Occurred() && i<pv->Value.MVbin.cValues; i++) { PyObject *obmv=PySequence_GetItem(ob,i); if (obmv==NULL) break; pv->Value.MVbin.lpbin[i].lpb = (unsigned char *)PyString_AsString(ob); pv->Value.MVbin.lpbin[i].cb = PyString_Size(ob); Py_DECREF(obmv); } break; // @flag PT_CLSID|A <o PyIID> case PT_CLSID: { HRESULT hr = MAPIAllocateMore(sizeof(CLSID), pAllocMoreLinkBlock, (void **)&pv->Value.lpguid); if (S_OK != hr) { OleSetOleError(hr); ok = FALSE; } else ok = PyWinObject_AsIID(ob, pv->Value.lpguid); break; } // @flag PT_MV_CLSID|A sequence of <o PyIID> objects case PT_MV_CLSID: MAKEB_MV(CLSID, pAllocMoreLinkBlock, pv->Value.MVguid.lpguid, pv->Value.MVguid.cValues, PyWinObject_AsIID) // @flag PT_I8|A <o PyLARGE_INTEGER> case PT_I8: // case PT_LONGLONG: ok = PyWinObject_AsLARGE_INTEGER(ob, &pv->Value.li); break; // @flag PT_MV_I8|A sequence of <o PyLARGE_INTEGER> case PT_MV_I8: MAKEB_MV(LARGE_INTEGER, pAllocMoreLinkBlock, pv->Value.MVli.lpli, pv->Value.MVli.cValues, PyWinObject_AsLARGE_INTEGER) // @flag PT_ERROR|An integer error code. case PT_ERROR: pv->Value.err = (SCODE)PyInt_AsLong(ob); break; // @flag PT_NULL|Anything! case PT_NULL: pv->Value.x = 0; break; default: { char buf[128]; sprintf(buf, "Unsupported MAPI property type 0x%X", PROP_TYPE(pv->ulPropTag)); PyErr_SetString(PyExc_TypeError, buf); ok = FALSE; } } ok = (ok && !PyErr_Occurred()); return ok; }