Commit 1a374c8c 1a374c8cbea21dabe2f7db123a559576531238db by Wojciech Polak

Reflect recent RFC compatibility changes in Python/C++.

* examples/python/mimetest.py: Update.
* include/mailutils/cpp/message.h (get_attachment_name): Overload.
* libmu_cpp/message.cc (Message::get_attachment_name): Overload.
* python/libmu_py/message.c (api_message_get_attachment_name): Update.
* python/mailutils/message.py (Message.get_attachment_name):
Add optional charset parameter. Return (name, lang) tuple.
1 parent d8ab03b0
...@@ -90,7 +90,7 @@ def message_display_parts (msg, indent): ...@@ -90,7 +90,7 @@ def message_display_parts (msg, indent):
90 else: 90 else:
91 # Save the attachements. 91 # Save the attachements.
92 try: 92 try:
93 fname = part.get_attachment_name () 93 fname, lang = part.get_attachment_name ()
94 except: 94 except:
95 fname = util.tempname () 95 fname = util.tempname ()
96 96
......
...@@ -68,6 +68,8 @@ class Message ...@@ -68,6 +68,8 @@ class Message
68 void save_attachment (const std::string& filename); 68 void save_attachment (const std::string& filename);
69 Message& unencapsulate (); 69 Message& unencapsulate ();
70 std::string get_attachment_name (); 70 std::string get_attachment_name ();
71 std::string get_attachment_name (const std::string& charset,
72 char* lang=NULL);
71 }; 73 };
72 74
73 } 75 }
......
...@@ -224,8 +224,25 @@ Message :: get_attachment_name () ...@@ -224,8 +224,25 @@ Message :: get_attachment_name ()
224 char *c_name; 224 char *c_name;
225 std::string name; 225 std::string name;
226 226
227 /* FIXME: CS/Lang info is ignored */ 227 int status = mu_message_aget_decoded_attachment_name (msg, NULL, &c_name,
228 int status = mu_message_aget_attachment_name (msg, &c_name, NULL); 228 NULL);
229 if (status)
230 throw Exception ("Message::get_attachment_name", status);
231 if (c_name) {
232 name = c_name;
233 free (c_name);
234 }
235 return name;
236 }
237
238 std::string
239 Message :: get_attachment_name (const std::string& charset, char *lang)
240 {
241 char *c_name;
242 std::string name;
243
244 int status = mu_message_aget_decoded_attachment_name (msg, charset.c_str (),
245 &c_name, &lang);
229 if (status) 246 if (status)
230 throw Exception ("Message::get_attachment_name", status); 247 throw Exception ("Message::get_attachment_name", status);
231 if (c_name) { 248 if (c_name) {
......
...@@ -282,14 +282,22 @@ api_message_get_attachment_name (PyObject *self, PyObject *args) ...@@ -282,14 +282,22 @@ api_message_get_attachment_name (PyObject *self, PyObject *args)
282 { 282 {
283 int status; 283 int status;
284 char *name = NULL; 284 char *name = NULL;
285 char *charset = NULL;
286 char *lang = NULL;
287 PyObject *py_ret;
285 PyMessage *py_msg; 288 PyMessage *py_msg;
286 289
287 if (!PyArg_ParseTuple (args, "O!", &PyMessageType, &py_msg)) 290 if (!PyArg_ParseTuple (args, "O!|z", &PyMessageType, &py_msg, &charset))
288 return NULL; 291 return NULL;
289 292
290 /* FIXME: CS/Lang info is ignored */ 293 status = mu_message_aget_decoded_attachment_name (py_msg->msg, charset,
291 status = mu_message_aget_attachment_name (py_msg->msg, &name, NULL); 294 &name, &lang);
292 return status_object (status, PyString_FromString (name ? name : "")); 295
296 py_ret = PyTuple_New (3);
297 PyTuple_SetItem (py_ret, 0, PyInt_FromLong (status));
298 PyTuple_SetItem (py_ret, 1, PyString_FromString (name ? name : ""));
299 PyTuple_SetItem (py_ret, 2, lang ? PyString_FromString (lang) : Py_None);
300 return _ro (py_ret);
293 } 301 }
294 302
295 static PyObject * 303 static PyObject *
...@@ -314,12 +322,10 @@ static PyObject * ...@@ -314,12 +322,10 @@ static PyObject *
314 api_message_unencapsulate (PyObject *self, PyObject *args) 322 api_message_unencapsulate (PyObject *self, PyObject *args)
315 { 323 {
316 int status; 324 int status;
317 char *filename = NULL;
318 PyMessage *py_msg; 325 PyMessage *py_msg;
319 PyMessage *py_unen = PyMessage_NEW (); 326 PyMessage *py_unen = PyMessage_NEW ();
320 327
321 if (!PyArg_ParseTuple (args, "O!|s", &PyMessageType, &py_msg, 328 if (!PyArg_ParseTuple (args, "O!", &PyMessageType, &py_msg))
322 &filename))
323 return NULL; 329 return NULL;
324 330
325 Py_INCREF (py_unen); 331 Py_INCREF (py_unen);
......
...@@ -138,11 +138,11 @@ class Message: ...@@ -138,11 +138,11 @@ class Message:
138 raise MessageError (status) 138 raise MessageError (status)
139 return uidl 139 return uidl
140 140
141 def get_attachment_name (self): 141 def get_attachment_name (self, charset=None):
142 status, name = message.get_attachment_name (self.msg) 142 status, name, lang = message.get_attachment_name (self.msg, charset)
143 if status: 143 if status:
144 raise MessageError (status) 144 raise MessageError (status)
145 return name 145 return name, lang
146 146
147 def save_attachment (self, filename = ''): 147 def save_attachment (self, filename = ''):
148 status = message.save_attachment (self.msg, filename) 148 status = message.save_attachment (self.msg, filename)
......