/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/util/simplemapi.py

  • Committer: John Ferlito
  • Date: 2009-09-02 04:31:45 UTC
  • mto: (4665.7.1 serve-init)
  • mto: This revision was merged to the branch mainline in revision 4913.
  • Revision ID: johnf@inodes.org-20090902043145-gxdsfw03ilcwbyn5
Add a debian init script for bzr --serve

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
LPLHANDLE = POINTER(LHANDLE)
45
45
 
46
46
# Return codes
47
 
SUCCESS_SUCCESS = 0
48
 
MAPI_USER_ABORT = 1
49
 
MAPI_E_USER_ABORT = MAPI_USER_ABORT
50
 
MAPI_E_FAILURE = 2
51
 
MAPI_E_LOGON_FAILURE = 3
52
 
MAPI_E_LOGIN_FAILURE = MAPI_E_LOGON_FAILURE
53
 
MAPI_E_DISK_FULL = 4
54
 
MAPI_E_INSUFFICIENT_MEMORY = 5
55
 
MAPI_E_ACCESS_DENIED = 6
56
 
MAPI_E_TOO_MANY_SESSIONS = 8
57
 
MAPI_E_TOO_MANY_FILES = 9
58
 
MAPI_E_TOO_MANY_RECIPIENTS = 10
59
 
MAPI_E_ATTACHMENT_NOT_FOUND = 11
60
 
MAPI_E_ATTACHMENT_OPEN_FAILURE = 12
 
47
SUCCESS_SUCCESS                 = 0
 
48
MAPI_USER_ABORT                 = 1
 
49
MAPI_E_USER_ABORT               = MAPI_USER_ABORT
 
50
MAPI_E_FAILURE                  = 2
 
51
MAPI_E_LOGON_FAILURE            = 3
 
52
MAPI_E_LOGIN_FAILURE            = MAPI_E_LOGON_FAILURE
 
53
MAPI_E_DISK_FULL                = 4
 
54
MAPI_E_INSUFFICIENT_MEMORY      = 5
 
55
MAPI_E_ACCESS_DENIED            = 6
 
56
MAPI_E_TOO_MANY_SESSIONS        = 8
 
57
MAPI_E_TOO_MANY_FILES           = 9
 
58
MAPI_E_TOO_MANY_RECIPIENTS      = 10
 
59
MAPI_E_ATTACHMENT_NOT_FOUND     = 11
 
60
MAPI_E_ATTACHMENT_OPEN_FAILURE  = 12
61
61
MAPI_E_ATTACHMENT_WRITE_FAILURE = 13
62
 
MAPI_E_UNKNOWN_RECIPIENT = 14
63
 
MAPI_E_BAD_RECIPTYPE = 15
64
 
MAPI_E_NO_MESSAGES = 16
65
 
MAPI_E_INVALID_MESSAGE = 17
66
 
MAPI_E_TEXT_TOO_LARGE = 18
67
 
MAPI_E_INVALID_SESSION = 19
68
 
MAPI_E_TYPE_NOT_SUPPORTED = 20
69
 
MAPI_E_AMBIGUOUS_RECIPIENT = 21
70
 
MAPI_E_AMBIG_RECIP = MAPI_E_AMBIGUOUS_RECIPIENT
71
 
MAPI_E_MESSAGE_IN_USE = 22
72
 
MAPI_E_NETWORK_FAILURE = 23
73
 
MAPI_E_INVALID_EDITFIELDS = 24
74
 
MAPI_E_INVALID_RECIPS = 25
75
 
MAPI_E_NOT_SUPPORTED = 26
 
62
MAPI_E_UNKNOWN_RECIPIENT        = 14
 
63
MAPI_E_BAD_RECIPTYPE            = 15
 
64
MAPI_E_NO_MESSAGES              = 16
 
65
MAPI_E_INVALID_MESSAGE          = 17
 
66
MAPI_E_TEXT_TOO_LARGE           = 18
 
67
MAPI_E_INVALID_SESSION          = 19
 
68
MAPI_E_TYPE_NOT_SUPPORTED       = 20
 
69
MAPI_E_AMBIGUOUS_RECIPIENT      = 21
 
70
MAPI_E_AMBIG_RECIP              = MAPI_E_AMBIGUOUS_RECIPIENT
 
71
MAPI_E_MESSAGE_IN_USE           = 22
 
72
MAPI_E_NETWORK_FAILURE          = 23
 
73
MAPI_E_INVALID_EDITFIELDS       = 24
 
74
MAPI_E_INVALID_RECIPS           = 25
 
75
MAPI_E_NOT_SUPPORTED            = 26
76
76
# Recipient class
77
 
MAPI_ORIG = 0
78
 
MAPI_TO = 1
 
77
MAPI_ORIG       = 0
 
78
MAPI_TO         = 1
79
79
# Send flags
80
 
MAPI_LOGON_UI = 1
81
 
MAPI_DIALOG = 8
82
 
 
 
80
MAPI_LOGON_UI   = 1
 
81
MAPI_DIALOG     = 8
83
82
 
84
83
class MapiRecipDesc(Structure):
85
84
    _fields_ = [
86
 
        ('ulReserved', c_ulong),
87
 
        ('ulRecipClass', c_ulong),
88
 
        ('lpszName', c_char_p),
89
 
        ('lpszAddress', c_char_p),
90
 
        ('ulEIDSize', c_ulong),
91
 
        ('lpEntryID', c_void_p),
 
85
        ('ulReserved',      c_ulong),
 
86
        ('ulRecipClass',    c_ulong),
 
87
        ('lpszName',        c_char_p),
 
88
        ('lpszAddress',     c_char_p),
 
89
        ('ulEIDSize',       c_ulong),
 
90
        ('lpEntryID',       c_void_p),
92
91
    ]
93
 
 
94
 
 
95
 
lpMapiRecipDesc = POINTER(MapiRecipDesc)
 
92
lpMapiRecipDesc  = POINTER(MapiRecipDesc)
96
93
lppMapiRecipDesc = POINTER(lpMapiRecipDesc)
97
94
 
98
 
 
99
95
class MapiFileDesc(Structure):
100
96
    _fields_ = [
101
 
        ('ulReserved', c_ulong),
102
 
        ('flFlags', c_ulong),
103
 
        ('nPosition', c_ulong),
104
 
        ('lpszPathName', c_char_p),
105
 
        ('lpszFileName', c_char_p),
106
 
        ('lpFileType', c_void_p),
 
97
        ('ulReserved',      c_ulong),
 
98
        ('flFlags',         c_ulong),
 
99
        ('nPosition',       c_ulong),
 
100
        ('lpszPathName',    c_char_p),
 
101
        ('lpszFileName',    c_char_p),
 
102
        ('lpFileType',      c_void_p),
107
103
    ]
108
 
 
109
 
 
110
104
lpMapiFileDesc = POINTER(MapiFileDesc)
111
105
 
112
 
 
113
106
class MapiMessage(Structure):
114
107
    _fields_ = [
115
 
        ('ulReserved', c_ulong),
116
 
        ('lpszSubject', c_char_p),
117
 
        ('lpszNoteText', c_char_p),
118
 
        ('lpszMessageType', c_char_p),
119
 
        ('lpszDateReceived', c_char_p),
120
 
        ('lpszConversationID', c_char_p),
121
 
        ('flFlags', FLAGS),
122
 
        ('lpOriginator', lpMapiRecipDesc),
123
 
        ('nRecipCount', c_ulong),
124
 
        ('lpRecips', lpMapiRecipDesc),
125
 
        ('nFileCount', c_ulong),
126
 
        ('lpFiles', lpMapiFileDesc),
 
108
        ('ulReserved',          c_ulong),
 
109
        ('lpszSubject',         c_char_p),
 
110
        ('lpszNoteText',        c_char_p),
 
111
        ('lpszMessageType',     c_char_p),
 
112
        ('lpszDateReceived',    c_char_p),
 
113
        ('lpszConversationID',  c_char_p),
 
114
        ('flFlags',             FLAGS),
 
115
        ('lpOriginator',        lpMapiRecipDesc),
 
116
        ('nRecipCount',         c_ulong),
 
117
        ('lpRecips',            lpMapiRecipDesc),
 
118
        ('nFileCount',          c_ulong),
 
119
        ('lpFiles',             lpMapiFileDesc),
127
120
    ]
128
 
 
129
 
 
130
121
lpMapiMessage = POINTER(MapiMessage)
131
122
 
132
 
MAPI = windll.mapi32
133
 
MAPISendMail = MAPI.MAPISendMail
134
 
MAPISendMail.restype = c_ulong
135
 
MAPISendMail.argtypes = (LHANDLE, c_ulong, lpMapiMessage, FLAGS, c_ulong)
 
123
MAPI                    = windll.mapi32
 
124
MAPISendMail            = MAPI.MAPISendMail
 
125
MAPISendMail.restype    = c_ulong
 
126
MAPISendMail.argtypes   = (LHANDLE, c_ulong, lpMapiMessage, FLAGS, c_ulong)
136
127
 
137
 
MAPIResolveName = MAPI.MAPIResolveName
 
128
MAPIResolveName         = MAPI.MAPIResolveName
138
129
MAPIResolveName.restype = c_ulong
139
 
MAPIResolveName.argtypes = (
140
 
    LHANDLE, c_ulong, c_char_p, FLAGS, c_ulong, lppMapiRecipDesc)
 
130
MAPIResolveName.argtypes= (LHANDLE, c_ulong, c_char_p, FLAGS, c_ulong, lppMapiRecipDesc)
141
131
 
142
 
MAPIFreeBuffer = MAPI.MAPIFreeBuffer
143
 
MAPIFreeBuffer.restype = c_ulong
 
132
MAPIFreeBuffer          = MAPI.MAPIFreeBuffer
 
133
MAPIFreeBuffer.restype  = c_ulong
144
134
MAPIFreeBuffer.argtypes = (c_void_p, )
145
135
 
146
 
MAPILogon = MAPI.MAPILogon
147
 
MAPILogon.restype = c_ulong
148
 
MAPILogon.argtypes = (LHANDLE, c_char_p, c_char_p, FLAGS, c_ulong, LPLHANDLE)
 
136
MAPILogon               = MAPI.MAPILogon
 
137
MAPILogon.restype       = c_ulong
 
138
MAPILogon.argtypes      = (LHANDLE, c_char_p, c_char_p, FLAGS, c_ulong, LPLHANDLE)
149
139
 
150
 
MAPILogoff = MAPI.MAPILogoff
151
 
MAPILogoff.restype = c_ulong
152
 
MAPILogoff.argtypes = (LHANDLE, c_ulong, FLAGS, c_ulong)
 
140
MAPILogoff              = MAPI.MAPILogoff
 
141
MAPILogoff.restype      = c_ulong
 
142
MAPILogoff.argtypes     = (LHANDLE, c_ulong, FLAGS, c_ulong)
153
143
 
154
144
 
155
145
class MAPIError(WindowsError):
166
156
    pSession = LHANDLE()
167
157
    rc = MAPILogon(0, profileName, password, MAPI_LOGON_UI, 0, byref(pSession))
168
158
    if rc != SUCCESS_SUCCESS:
169
 
        raise MAPIError(rc)
 
159
        raise MAPIError, rc
170
160
    return pSession
171
161
 
172
162
 
173
163
def _logoff(session):
174
164
    rc = MAPILogoff(session, 0, 0, 0)
175
165
    if rc != SUCCESS_SUCCESS:
176
 
        raise MAPIError(rc)
 
166
        raise MAPIError, rc
177
167
 
178
168
 
179
169
def _resolveName(session, name):
180
170
    pRecipDesc = lpMapiRecipDesc()
181
171
    rc = MAPIResolveName(session, 0, name, 0, 0, byref(pRecipDesc))
182
172
    if rc != SUCCESS_SUCCESS:
183
 
        raise MAPIError(rc)
 
173
        raise MAPIError, rc
184
174
    rd = pRecipDesc.contents
185
175
    name, address = rd.lpszName, rd.lpszAddress
186
176
    rc = MAPIFreeBuffer(pRecipDesc)
187
177
    if rc != SUCCESS_SUCCESS:
188
 
        raise MAPIError(rc)
 
178
        raise MAPIError, rc
189
179
    return name, address
190
180
 
191
181
 
227
217
 
228
218
    rc = MAPISendMail(session, 0, byref(msg), MAPI_DIALOG, 0)
229
219
    if rc != SUCCESS_SUCCESS:
230
 
        raise MAPIError(rc)
 
220
        raise MAPIError, rc
231
221
 
232
222
 
233
223
def SendMail(recipient, subject="", body="", attachfiles=""):
241
231
 
242
232
    attach = []
243
233
    AttachWork = attachfiles.split(';')
244
 
    for f in AttachWork:
245
 
        if os.path.exists(f):
246
 
            attach.append(os.path.abspath(f))
 
234
    for file in AttachWork:
 
235
        if os.path.exists(file):
 
236
            attach.append(file)
 
237
    attach = map(os.path.abspath, attach)
247
238
 
248
239
    restore = os.getcwd()
249
240
    try:
263
254
    body = "Hi,\r\n\r\nthis is a quick test message,\r\n\r\ncheers,\r\nJohn."
264
255
    attachment = sys.argv[0]
265
256
    SendMail(recipient, subject, body, attachment)
 
257