00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include "customization.h"
00036 #ifndef WINMAINCPP
00037 #define WINMAINCPP
00038
00043
00044
00045 #define PROGRAM_NAME_EXE "OutlookPlugin.exe"
00046 #define SYNC_MUTEX_NAME "fol-SyncInProgress"
00047 #define ASK_SLOW_TIMEOUT 25
00048 #define SCHED_DEFAULT_REPEAT_MINS 15
00049 #define SCHED_DURATION_DAYS 1
00050 #define SYNC_TIMEOUT 120
00051 #define MAX_LOG_SIZE 10000000
00052 #define EMPTY_WSTRING L""
00053 #define DISPLAY_SLOWSYNC_WARNING 0
00056 // Default remote names:
00057 #define VCARD_DEFAULT_NAME L"card"
00058 #define VCALENDAR_DEFAULT_NAME L"event"
00059 #define VTODO_DEFAULT_NAME L"task"
00060 #define VNOTE_DEFAULT_NAME L"note"
00061
00062 #define SIFC_DEFAULT_NAME L"scard"
00063 #define SIFE_DEFAULT_NAME L"scal"
00064 #define SIFT_DEFAULT_NAME L"stask"
00065 #define SIFN_DEFAULT_NAME L"snote"
00066
00067
00068
00069 #define MAX_PATH_LENGTH 512
00070
00071
00072
00073
00075 #define MAIL L"mail"
00076 #define CONTACT L"contact"
00077 #define APPOINTMENT L"appointment"
00078 #define TASK L"task"
00079 #define JOURNAL L"journal"
00080 #define NOTE L"note"
00081 #define POST L"post"
00082 #define DISTRIBUTION_LIST L"distribution list"
00083
00084 #define MAIL_ "mail"
00085 #define CONTACT_ "contact"
00086 #define APPOINTMENT_ "appointment"
00087 #define TASK_ "task"
00088 #define JOURNAL_ "journal"
00089 #define NOTE_ "note"
00090 #define POST_ "post"
00091 #define DISTRIBUTION_LIST_ "distribution list"
00092
00094 static WCHAR* itemTypesUsed[] = {
00095 {CONTACT },
00096 {APPOINTMENT },
00097 {TASK },
00098 {NOTE },
00099 {NULL}
00100 };
00101
00103 #define APPOINTMENT_FORCED_MODIFIED L"appointment_modified"
00104
00106 #define DEFAULT_FOLDER L"DEFAULT_FOLDER"
00107
00108 #define SYNCSOURCE_STATE_OK 1
00109 #define SYNCSOURCE_STATE_NOT_SYNCED 2
00110 #define SYNCSOURCE_STATE_CANCELED 3
00111
00112 #define ERR_CODE_DROPPED_ITEMS 2100
00113 #define ERR_CODE_DROPPED_ITEMS_SERVER 2101
00114 #define ERR_CODE_NO_SOURCES 2102
00115
00118
00121 #define SCHED_PARAM L"schedule"
00122 #define NEVER "Never"
00123 #define EVERY_DAY "Every day"
00124
00128
00129
00130
00132
00133 #define MSG_BOX_CANCEL_SYNC "Are you really sure you want to cancel current synchronization?"
00134 #define WMSG_BOX_CANCEL_SYNC L"Are you really sure you want to cancel current synchronization?"
00135 #define WMSG_BOX_ASK_SLOW_1 L"The server has requested a full sync of all items for "
00136 #define WMSG_BOX_ASK_SLOW_2 L".\nThis process may take up to a few minutes depending on the number of items\nand network bandwidth. Do you wish to proceed? (YES in %d seconds...)"
00137 #define WMSG_BOX_REFRESH_FROM_SERVER L"A sync to replace your local data with your server data has been requested.\nAll the local items will be deleted before adding the server items.\nAre you sure you want to continue?"
00138
00139
00140
00141 #define ERR_UNKNOWN "Unknown error."
00142 #define ERR_OPEN_OUTLOOK "Error opening Outlook application."
00143 #define ERR_TAG_NOT_FOUND "Bad XML format: tag '%ls' not found."
00144 #define ERR_BAD_FOLDER_PATH "Bad folder path: %ls"
00145 #define ERR_INSTALL_DIR "Error retrieving the install directory path."
00146 #define ERR_THREAD_PRIORITY "Error setting sync thread priority: code %d (%s)."
00147 #define ERR_THREAD_NOT_TERMINATED "Could not terminate the synchronization process. %s"
00148 #define ERR_MUTEX_CREATE "Could not create the mutex for synchronization process. %s"
00149 #define ERR_MUTEX_ALREADY_EXISTS "Error creating the mutex for sync process: mutex already exists. %s"
00150 #define ERR_MUTEX_NOT_RELEASED "Could not release the mutex of synchronization process. %s"
00151 #define ERR_MUTEX_OPEN "Could not open the mutex of synchronization process. %s"
00152 #define ERR_CLASS_REG_FAILED "Class Registration Failed! class name = %s"
00153 #define ERR_ENCRYPT_DATA "Error occurred encrypting private data"
00154 #define ERR_DECRYPT_DATA "Error occurred decrypting private data"
00155 #define ERR_NO_SOURCES_TO_SYNC "No sources to synchronize."
00156
00157 #define ERR_BEGIN_SYNC "Error in begin sync of source '%ls'."
00158 #define ERR_CLOSE_OUTLOOK "Some error occurred closing Outlook session. Outlook may become unstable."
00159 #define ERR_COM_INITIALIZE "Error occurred initializing COM library."
00160 #define ERR_COM_CREATE_INSTANCE "Error occurred creating an instance for COM library."
00161 #define ERR_END_SYNC "Error in end sync of source '%ls'."
00162 #define ERR_APPDATA_PATH "Error retrieving current user application data path: code %d (%s)"
00163 #define ERR_FILE_OPEN "Error opening file: %s"
00164 #define ERR_WFILE_OPEN "Error opening file: %ls"
00165 #define ERR_FILE_WRITE_ON "Error writing file: %s"
00166 #define ERR_WFILE_WRITE_ON "Error writing file: %ls"
00167 #define ERR_FILE_OPEN_MODE "Error writing file: bad fopen mode."
00168 #define ERR_DIR_CREATE "Error creating directory: %ls"
00169 #define ERR_DEFAULT_SSCONFIG "Error creating default config for %s: %s"
00170 #define ERR_MACHINE_NAME "GetComputerName error: code %d (%s)"
00171 #define ERR_USER_NAME "GetUserName error: code %d (%s)"
00172 #define ERR_USER_NAME_EX "GetUserNameEx error: code %d (%s)"
00173 #define ERR_INIT_LOG "Could not create the LOG file."
00174 #define ERR_INVALID_REG_PATH "Invalid windows registry path: %s."
00175 #define ERR_HKLM_KEYNOTFOUND "Error reading HKLM registry key '%s'.\nPlease reinstall the application."
00176
00177 #define ERR_FOLDER_OPEN "Error opening Outlook folder for source '%ls' with path '%ls'."
00178 #define ERR_FOLDER_PATH "'%ls' is not a folder selected for synchronization (see configuration of %ls source). Item received will be ignored."
00179 #define ERR_FOLDER_DEFAULT_PATH "Warning! No default folder found for %lss!"
00180 #define ERR_ITEM_GET "Error getting item \"%ls\" for source '%ls'."
00181 #define ERR_ITEM_GET_NEW "Error getting new item \"%ls\" for source '%ls'."
00182 #define ERR_ITEM_GET_MOD "Error getting modified item \"%ls\" for source '%ls'."
00183 #define ERR_ITEM_CREATE "Could not create a new %ls item into folder '%ls'"
00184 #define ERR_ITEM_FILL "Error setting properties of %ls item \"%ls\". Item not saved."
00185 #define ERR_INPUT_ITEM_FILTERED "Incoming %ls item \"%ls\" discarded because it doesn't verify current filters. Item not saved."
00186 #define ERR_INPUT_ITEM_DEL_FILTERED "Incoming %ls item \"%ls\" not deleted because it doesn't verify current filters."
00187 #define ERR_ITEM_BAD_TYPE "Mime type not supported: \"%ls\""
00188 #define ERR_ITEM_SAVE "Could not save %ls item \"%ls\" into folder '%ls'"
00189 #define ERR_ITEM_DELETE "Could not delete %ls item \"%ls\" from folder '%ls'"
00190 #define ERR_ITEM_DELETE_INTERNALLY L"Error removing internally the item."
00191 #define ERR_ITEM_UPDATE_NOT_FOUND "Could not update %ls item: ID = %ls not found."
00192 #define ERR_ITEM_DELETE_NOT_FOUND "Could not delete %ls item: ID = %ls not found."
00193 #define ERR_EVENTS_CREATED "Error occurred while checking if Outlook created a birthday/anniversary event."
00194 #define ERR_SOURCE_TOO_MANY_ERRORS "%d errors occurred on source %ls: source will not be used any more."
00195 #define ERR_SOURCE_LASTSYNCTIME_NOT_FOUND "Error reading \"%ls\": <LastSyncTime> not found."
00196 #define ERR_OCCURRENCE_NOT_FOUND "Error creating the appointment exception: occurrence \"%ls\" not found."
00197 #define ERR_OCCURRENCE_NOT_DELETED "Could not delete one occurrence (date = %ls)."
00198 #define ERR_OCCURRENCE_NOT_SAVED "Could not save one occurrence (date = %ls)."
00199 #define ERR_EXCEPTIONS_DEADLOCK "Detected too many dependences between appointment exceptions (%d). Exceptions not saved correctly."
00200 #define ERR_PROPERTY_REQUIRED "Error creating %ls item: property \"%ls\" is required."
00201
00202 #define ERR_PARSE_SIF_TAG_NOT_FOUND "Parsing error: SIF tag \"%ls\" not found."
00203 #define ERR_PARSE_PROPERTY_NOT_FOUND "Parsing error: property \"%ls\" not found."
00204 #define ERR_PARSE_PROPERTY_EMPTY "Parsing error: property \"%ls\" should not be empty."
00205 #define ERR_PARSE_APP_EXCEPTION "Error parsing appointment exception: %s"
00206 #define ERR_PARSE_EXC_NOREC "Could not add exceptions on a not-recurring appointment."
00207 #define ERR_NORMALIZE_EXCEPTIONS "Error normalizing appointment exceptions: %s"
00208
00209 #define ERR_SCHED_INIT_TASK "Error initializing Windows task scheduler."
00210 #define ERR_SCHED_SAVE "Scheduler error - failed to save the task, code = 0x%x - %s"
00211 #define ERR_SCHED_DELETE "Scheduler error - failed to delete the task, code = 0x%x - %s"
00212 #define ERR_SCHED_NEWWORKITEM "Scheduler error - failed calling ITask::NewWorkItem, code = 0x%x - %s"
00213 #define ERR_SCHED_CREATE_TRIGGER "Scheduler error - failed calling ITask::CreateTrigger, code = 0x%x - %s"
00214 #define ERR_SCHED_GET_TRIGGER "Scheduler error - failed calling ITask::GetTrigger, code = 0x%x - %s"
00215 #define ERR_SCHED_GET_TRIGGER2 "Scheduler error - failed calling ITaskTrigger::GetTrigger, code = 0x%x - %s"
00216 #define ERR_SCHED_SET_TRIGGER "Scheduler error - failed calling ITaskTrigger::SetTrigger, code = 0x%x - %s"
00217 #define ERR_SCHED_QUERY_INTERFACE "Scheduler error - failed calling ITask::QueryInterface, code = 0x%x - %s"
00218 #define ERR_SCHED_ACTIVATE "Scheduler error - failed calling ITaskScheduler::Activate, code = 0x%x - %s"
00219 #define ERR_SCHED_INVALID_PARAM "One or more arguments are invalid - please select a correct interval for scheduler"
00220 #define E_OBJECT_NOT_FOUND 0x80070002L // This should be mapped in winerror.h ??
00221
00222
00223 #define INFO_ITEM_ADDED "Added %ls item: \"%ls\""
00224 #define INFO_ITEM_UPDATED "Updated %ls item: \"%ls\""
00225 #define INFO_ITEM_DELETED "Deleted %ls item: \"%ls\""
00226 #define INFO_GET_ITEM "Retrieved %ls item: \"%ls\""
00227 #define INFO_GET_NEW_ITEM "Retrieved new %ls item: \"%ls\""
00228 #define INFO_GET_UPDATED_ITEM "Retrieved updated %ls item: \"%ls\""
00229 #define INFO_CONFIG_GENERATED "Configuration not found: default configuration will be used."
00230 #define INFO_SWV_UPGRADED "Configuration upgraded to new software version: %s"
00231 #define INFO_CONFIG_DEVID_SAVED "Set configuration deviceID = %s"
00232 #define INFO_OLD_ITEMS_NOT_FOUND "Cannot find list of items from previous sync. All items will be sent as modified."
00233 #define INFO_SYNC_COMPLETED "Syncronization process completed."
00234 #define INFO_SYNC_COMPLETED_ERRORS "Syncronization process completed with errors (code = %d)."
00235 #define INFO_EXIT "Exiting from Outlook client."
00236 #define INFO_SYNC_ABORTING "Aborting synchronization session..."
00237 #define INFO_SYNC_ABORTED_BY_USER "Synchronization aborted by user."
00238 #define INFO_SYNC_ABORTED_BY_USER_SLOW "Synchronization aborted by user to avoid full-sync of %ls."
00239 #define INFO_SCHED_TASK_CREATED "Scheduler task created."
00240 #define INFO_SCHED_TASK_DELETED "Scheduler task deleted."
00241 #define INFO_WRONG_MIME_TYPE "Warning: mime type not recognized: \"%ls\""
00242 #define INFO_REMOVING_ALL_ITEMS "Removing all existing %lss (%d items to delete)..."
00243 #define INFO_REMOVED_INTERNALLY L"Removed internally before sync"
00244
00245
00246 #define DBG_OUTLOOK_OPEN "beginSync of %ls source: opening Outlook session..."
00247 #define DBG_READ_ALL_ITEMS "Reading ALL %lss from folder '%ls' (%d found)..."
00248 #define DBG_CONFIG_CLOSED "Outlook configuration closed."
00249 #define DBG_STATE_ERR_ITEM_IGNORED "Source state is ERROR -> item will be ignored."
00250 #define DBG_LAST_SYNC_ABORTED "Last synchronization has been aborted, mutex of sync process will be released now."
00251 #define DBG_SYNC_ABORT_REQUEST "User requested to abort synchronization process..."
00252 #define DBG_THREAD_TERMINATED "Synchronization thread has been terminated."
00253 #define DBG_RRULE_BAD_FORMAT "Error parsing RRULE, bad format: %ls"
00254 #define DBG_SAFE_ITEM_NAME "Client Exception on getSafeName: %s"
00255 #define DBG_ANNIVERSARY_DELETED "While saving contact \"%ls\" an anniversary event was automatically created by Outlook and then just deleted!"
00256 #define DBG_BIRTHDAY_DELETED "While saving contact \"%ls\" a birthday event was automatically created by Outlook and then just deleted!"
00257 #define DBG_SCHED_TASK_NOT_FOUND "Scheduled task not found."
00258 #define DBG_SCHED_LAST_EXECUTION "The last task excecution was not performed. Please check windows task scheduler for more details"
00259 #define DBG_SCHED_TASK_MANUALLY_CHANGED "Scheduled task has been manually modified."
00260 #define DBG_NORMALIZING_EXCEPTION "Normalizing appointment exception: item \"%ls\", occurrence = %ls. A new item is created in Outlook."
00261 #define DBG_ITEM_CREATED_FROM_EXCEPTION "A new appointment \"%ls\" has been created from an event exception. Will be sent as NEW item next sync."
00262 #define DBG_PARSING_SIF_DATA "Parsing SIF %ls..."
00263 #define DBG_PARSING_EXCEPTIONS "Parsing appointment exceptions..."
00264 #define DBG_PARSING_VOBJ_DATA "Parsing VObject %ls (mime type = \"%ls\")..."
00265
00266
00267
00268 #define SBAR_CHECK_ALL_ITEMS 1
00269 #define SBAR_CHECK_MOD_ITEMS 2
00270 #define SBAR_CHECK_MOD_ITEMS2 3
00271 #define SBAR_WRITE_OLD_ITEMS 4
00272 #define SBAR_SENDDATA_BEGIN 5
00273 #define SBAR_SENDDATA_END 6
00274 #define SBAR_RECEIVE_DATA_BEGIN 7
00275 #define SBAR_RECEIVE_DATA_END 8
00276 #define SBAR_DELETE_CLIENT_ITEMS 9
00277
00278
00279
00280 #define SBAR_READING_ALLITEMS "Reading all items from Outlook (%d)..."
00281 #define SBAR_CHECKING_MODITEMS "Checking changes since last successful sync..."
00282 #define SBAR_CHECKING_MODITEMS2 "Checking changes since last successful sync (%d) ..."
00283 #define SBAR_WRITING_OLDITEMS "Writing all items list for next sync..."
00284 #define SBAR_DELETING_ITEMS "Deleting %ss from Outlook..."
00285 #define SBAR_SENDING_DATA "Sending data to the Server..."
00286 #define SBAR_RECEIVING_DATA "Receiving data from the Server..."
00287 #define SBAR_WAITING "Waiting for Server response..."
00288
00289
00290
00291 #include <mstask.h>
00292 #include "spds/SyncItem.h"
00293 #include "vocl/WinItem.h"
00294 #include "outlook/ClientItem.h"
00295 #include "outlook/ClientAppointment.h"
00296 #include "OutlookConfig.h"
00297 #include "WindowsSyncSource.h"
00298
00299 #include <string>
00300
00301
00302
00303
00304
00305 int initializeClient (bool isScheduled);
00306 int initLog (bool isScheduled);
00307 int startSync ();
00308 int closeClient ();
00309 void closeOutlook ();
00310 void checkAbortedSync ();
00311 bool checkSyncInProgress();
00312 void softTerminateSync ();
00313 int hardTerminateSync (HANDLE hSyncThread);
00314 int exitSyncThread (int code);
00315 void endSync();
00316 void upgradePlugin (int oldVersion);
00317
00318
00319
00322 __declspec(dllexport) OutlookConfig* getConfig();
00323 void createDefaultConfig();
00324 std::wstring pickOutlookFolder (const std::wstring& itemType);
00325 std::wstring getDefaultFolderPath(const std::wstring& itemType);
00329
00332 WinItem* createWinItem (bool useSIF, const std::wstring itemType);
00333 WinItem* createWinItem (bool useSIF, const std::wstring itemType, const std::wstring& data, const WCHAR** sifFields);
00334 SyncItem* convertToSyncItem (ClientItem* cItem, const char* dataType, const std::wstring& defaultFolder);
00335 int fillClientItem (const std::wstring& sif, ClientItem* cItem, const std::wstring& itemType, const WCHAR* dataType);
00336 WCHAR** getProperSifArray (const std::wstring& type);
00337 int normalizeExceptions(ClientItem* cItem, itemKeyList& allItems, itemKeyList& allItemsPaths);
00338 int deleteOccurrencesInInterval(const DATE startDate, const DATE originalDate, ClientRecurrence* cRec);
00339 int setRecurrenceExceptions (ClientItem* cItem, std::list<std::wstring> &excludeDates, std::list<std::wstring> &includeDates);
00340 int checkIllegalXMLChars(char* data);
00341 std::wstring getVPropertyValue (const std::wstring& dataString, const std::wstring& propertyName);
00342 void replaceDefaultPath(std::wstring& path, const std::wstring& defaultFolder);
00346
00349 int setScheduler (const bool enable, const int minutes);
00350 bool getScheduler (int* minutes);
00351 int setScheduleTask (const char* frequency, const int dayNum, const int minNum);
00352 int getScheduleTask (bool* active, int* dayNum, int* minNum);
00353 int deleteScheduleTask();
00354 ITaskScheduler* initScheduleInstance();
00355 int getScheduledTaskName(std::wstring& taskName);
00358 const char* getClientLastErrorMsg ();
00359 const int getClientLastErrorCode();
00360
00361
00364 #endif