Not able to convert .ics file to PST format using aspose lib getting below error.
C:\Users\Tejas>python calendarissue.py
Traceback (most recent call last):
File “mailissue.py”, line 57, in
run()
File “mailissue.py”, line 49, in run
appointment = Appointment.load(f.file_directory)
Proxy error(FormatException): The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters.
Code
from aspose.email import MailMessage
from aspose.email.mime import HeaderCollection
import aspose.email.mapi.msg as msg
from aspose.email.mapi import MapiMessage, MapiContact
from aspose.email.personalinfo.vcard import VCardContact
import aspose.email as ae
import os
import shutil
import tempfile
from aspose.email.calendar import Appointment
class TempFileManager:
"""
Manager that creates a file in temporary directory. Removes temporary directory on exit.
"""
def __init__(self, file_content, file_name):
self.content = file_content
self.file_name = file_name
def __enter__(self):
self.folder_directory = tempfile.mkdtemp()
self.file_directory = os.path.join(self.folder_directory, self.file_name)
with open(self.file_directory, "w+", encoding="utf-8-sig") as f:
f.write(self.content)
return self
def __exit__(self, exc_type, exc_val, exc_tb):
shutil.rmtree(self.folder_directory)
def prepare_file(file_dir):
with open(file_dir, "r+", encoding="utf-8-sig") as f:
readed_file = f.read()
readed_file = readed_file.replace("ACTION:Display\n", "ACTION:DISPLAY\n")
return readed_file
def run():
#dataDir = "Data/"
#ExStart: LoadingContactFromVCardWithSpecifiedEncoding
#print(MailMessage.load('Undeliverable_ repro test-1727695419 (2).eml'))
#result = MapiMessage.from_mail_message(MailMessage.load('Undeliverable_ repro test-1727695419 (2).eml'))
#print(result)
#ExEnd: LoadingContactFromVCardWithSpecifiedEncoding
prepared_file = prepare_file('testinvalidmail.ics')
with TempFileManager(prepared_file, os.path.basename('testinvalidmail.ics')) as f:
appointment = Appointment.load(f.file_directory)
mail_message = ae.MailMessage()
mail_message.add_alternate_view(appointment.request_apointment())
mapi_message = MapiMessage.from_mail_message(mail_message)
if __name__ == '__main__':
run()