// ###########################################
//  
//  Author:	Santiago Rilova
//  Date:	20/08/2003
//
//  This tests Sirocco PREQ98- Storing received mail messages.  User MUST be able to change the character set
//                             without loosing data independently of original character set. 
//  It downloads emails from a server, some of which have corrupted charset information. It then dumps the messages
//  and compares the output against reference files to verify it is correct.
//
// Execution:
// 1. Copy this file to c:\msgtest\emailsmoke
//  and execute "t_email -testparams imapCharsetTests"
//
//
// Pre-requisites:
// 1. The mail account specified in imap_service_MsgExchange must contain the required emails
// 2. The PREQ98 feature must be activated in the IMCM.RSC file (edit IMCM.RSS to update flag store_8bit_body_text
//    to value=1 and recompile the resource file)
//   
// ####################################################

[main]
email_client_test email

// Perform the test steps.

[email]
imap_client_test imap_init_mail_folders
imap_client_test create_IMAP_service
imap_client_test imap_do_inbox_sync_service
//imap_client_test dump_mail_store
imap_client_test dump_bodies
imap_client_test verify_body_text
imap_client_test verify_attachment_names
imap_client_test verify_header_fields

// Delete the mail folder
[imap_init_mail_folders]
add_comment Clean message folder in C drive
clean_message_folder
add_comment Start client session
start_client_session

//
// Create IMAP service
// 
[create_IMAP_service]
add_comment Create IMAP service for testing
select_root_folder
imap_service imap_service_MsgExchange
select_folder test_imap_service
add_comment Connecting
connect
check_imap_error 0
add_comment Synchronising tree
sync_tree
check_imap_error 0
add_comment Disconnecting
disconnect
check_imap_error 0

[imap_do_inbox_sync_service]
add_comment Do sync
select_root_folder
select_folder test_imap_service
add_comment Connecting
connect
check_imap_error 0
select_root_folder
select_folder test_imap_service
select_folder Inbox
add_comment Sync Inbox
sync_folder
select_all_messages
add_comment Populate the message (download the body text)
populate_folder
add_comment Message downloaded
add_comment Disconnecting
disconnect
check_imap_error 0

[dump_mail_store]
dump_mail_store dump1\

[dump_bodies]
add_comment Do sync
select_root_folder
select_folder test_imap_service
add_comment Connecting
connect
check_imap_error 0
select_root_folder
select_folder test_imap_service
select_folder Inbox
select_all_messages
//
//  Change to the correct charset
//
// change to gb2312, KCharacterSetIdentifierGb2312=0x10000fbe (=268439486)
// Change to ISO 88591 KCharacterSetIdentifierIso88591=0x10003b10  (=268450576)
//change_charset 268450576
//
//   Dump the bodies
//
select_entry plain_text_non_mime
dump_body_text plain_text_non_mime.txt
change_charset 268450576
dump_body_text plain_text_non_mime2.txt
//
select_entry test_plain_bodytext_no_encoding
dump_body_text test_plain_bodytext_no_encoding.txt
//
select_entry corrupted_charset_test_plain_bodytext_no_encoding
change_charset 268450576
dump_body_text corrupted_charset_test_plain_bodytext_no_encoding.txt
//
select_entry test_plain_bodytext_with_attach_no_encoding
dump_body_text test_plain_bodytext_with_attach_no_encoding.txt
//
select_entry corrupted_charset_test_plain_bodytext_with_attach_no_encoding
change_charset 268450576
dump_body_text corruptd_charset_test_plain_bodytext_with_attach_no_encoding.txt
//
select_entry test_plain_bodytext_qp_encoding
dump_body_text test_plain_bodytext_qp_encoding.txt
//
// no need to change charset on this one because it has invalid charset info, so default charset (which is
// the correct one, is used anyway)
select_entry corrupted_charset_test_plain_bodytext_qp_encoding
dump_body_text corrupted_charset_test_plain_bodytext_qp_encoding.txt
//
// lets try changing it anyway...should come up with the same output
//
select_entry corrupted_charset_test_plain_bodytext_qp_encoding
dump_body_text corrupted_charset_test_plain_bodytext_qp_encoding2.txt
//
select_entry test_plain_bodytext_base64_encoding
dump_body_text test_plain_bodytext_base64_encoding.txt
//
select_entry corrupted_charset_test_plain_bodytext_base64_encoding
change_charset 268450576
dump_body_text corrupted_charset_test_plain_bodytext_base64_encoding.txt
//
//
select_entry html_no_encoding_with_attachments
dump_body_text html_no_encoding_with_attachments.txt
dump_attachment_names attachment_names3.txt
//
select_entry corrupted_charset_html_no_encoding_with_attachments
change_charset 268450576
dump_body_text corrupted_charset_html_no_encoding_with_attachments.txt
dump_attachment_names attachment_names4.txt
//
select_entry html_base64_with_attachment
dump_body_text html_base64_with_attachment.txt
dump_attachment_names single_attachment_name.txt
//
select_entry corrupted_charset_html_base64_with_attachment
change_charset 268450576
dump_body_text corrupted_charset_html_base64_with_attachment.txt
dump_attachment_names single_attachment_name2.txt
//
//
select_entry html_qp_encoding_looking_french
change_charset 268450576
dump_body_text html_qp_encoding_bodytext.txt
dump_header_fields html_qp_encoding_headers.txt
//
// Some more attachments....
//
select_entry test_attachment1
dump_attachment_names attachment_names.txt
//
select_entry test_attachment1_corrupted
change_charset 268450576
dump_attachment_names attachment_names2.txt
//
//
add_comment Disconnect
disconnect
check_imap_error 0


[verify_body_text]
compare_files plain_text_non_mime.txt plain_text_non_mime.txt
compare_files plain_text_non_mime2.txt plain_text_non_mime.txt
compare_files test_plain_bodytext_no_encoding.txt test_plain_bodytext_no_encoding.txt
compare_files corrupted_charset_test_plain_bodytext_no_encoding.txt test_plain_bodytext_no_encoding.txt
compare_files test_plain_bodytext_with_attach_no_encoding.txt test_plain_bodytext_with_attach_no_encoding.txt
compare_files corruptd_charset_test_plain_bodytext_with_attach_no_encoding.txt test_plain_bodytext_with_attach_no_encoding.txt
compare_files test_plain_bodytext_qp_encoding.txt test_plain_bodytext_qp_encoding.txt
compare_files corrupted_charset_test_plain_bodytext_qp_encoding.txt test_plain_bodytext_qp_encoding.txt
compare_files corrupted_charset_test_plain_bodytext_qp_encoding2.txt test_plain_bodytext_qp_encoding.txt
compare_files test_plain_bodytext_base64_encoding.txt test_plain_bodytext_base64_encoding.txt
compare_files corrupted_charset_test_plain_bodytext_base64_encoding.txt test_plain_bodytext_base64_encoding.txt
compare_files html_no_encoding_with_attachments.txt html_with_attachments_bodytext.txt
compare_files corrupted_charset_html_no_encoding_with_attachments.txt html_with_attachments_bodytext.txt
compare_files html_base64_with_attachment.txt html_with_attachments_bodytext.txt
compare_files corrupted_charset_html_base64_with_attachment.txt html_with_attachments_bodytext.txt
compare_files html_qp_encoding_bodytext.txt html_qp_encoding_bodytext.txt

[verify_attachment_names]
compare_files attachment_names.txt attachment_names.txt
compare_files attachment_names2.txt attachment_names.txt
compare_files attachment_names3.txt attachment_names.txt
compare_files attachment_names4.txt attachment_names.txt
compare_files single_attachment_name.txt single_attachment_name.txt
compare_files single_attachment_name2.txt single_attachment_name.txt

[verify_header_fields]
compare_files html_qp_encoding_headers.txt html_qp_encoding_headers.txt

//
// mail service definition
//
[imap_service_MsgExchange]
set_name test_imap_service
set_server lon-msgtest06.intra
set_user santi
set_pass password
set_tls 0


