We are implementing a service that copies the attachments received in an email to the file system. The attachments we receive can be in text or binary format. Basically we process the mail using the mime functions in the pub package, extract the attachment contents with pub.mime:getBodyPartContent and save the contents to the file. Text files they must remain in their original encoding.
The problem we are having is that when we receive text files with special characters (accented characters for example) and we save the contents to a file, these characters are not saved correctly. We first thought the problem was that we were saving the file in text format and not in binary format. But after examining the service we are using to save the contents of the attachment (PSUtilities.file:streamToFile) we noticed it is saving the contents in binary format. We also made our own saving service to perform a test and we still got the same problem.
After some time debugging we determined the problem is that the function getBodyPartContent is already returning the contents with the encoding problem. Is there a way to specify to the getBodyPartContent service that all attachments must be handled in binary format? I read that you can defined custom content handlers for webMethods but I am not sure if this will apply to the getBodyPartContent service.