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
00036 #ifndef WINMAINCPP
00037 #define WINMAINCPP
00038
00043 #define OUTLOOK 1
00044
00045
00046
00047 #define SYNC_MUTEX_NAME "fol-SyncInProgress"
00048 #define EMPTY_WSTRING L""
00049
00050
00051
00052 #define VCARD_DEFAULT_NAME L"card"
00053 #define VCALENDAR_DEFAULT_NAME L"event"
00054 #define VTODO_DEFAULT_NAME L"task"
00055 #define VNOTE_DEFAULT_NAME L"note"
00056
00057 #define SIFC_DEFAULT_NAME L"scard"
00058 #define SIFE_DEFAULT_NAME L"scal"
00059 #define SIFT_DEFAULT_NAME L"stask"
00060 #define SIFN_DEFAULT_NAME L"snote"
00061
00062 #define CALENDAR_REMOTE_NAME L"calendar"
00063 #define CONTACTS_REMOTE_NAME L"contacts"
00064 #define TASKS_REMOTE_NAME L"tasks"
00065 #define NOTES_REMOTE_NAME L"notes"
00066
00067 #define SHARED_SUFFIX L"-shared"
00068
00069
00070 #define MAX_PATH_LENGTH 512
00071
00072
00073
00074
00076 #define MAIL L"mail"
00077 #define CONTACT L"contact"
00078 #define APPOINTMENT L"appointment"
00079 #define TASK L"task"
00080 #define JOURNAL L"journal"
00081 #define NOTE L"note"
00082 #define PICTURE L"picture"
00083 #define POST L"post"
00084 #define DISTRIBUTION_LIST L"distribution list"
00085
00086 #define MAIL_ "mail"
00087 #define CONTACT_ "contact"
00088 #define APPOINTMENT_ "appointment"
00089 #define TASK_ "task"
00090 #define JOURNAL_ "journal"
00091 #define NOTE_ "note"
00092 #define PICTURE_ "picture"
00093 #define POST_ "post"
00094 #define DISTRIBUTION_LIST_ "distribution list"
00095
00096
00098 #define APPOINTMENT_FORCED_MODIFIED L"appointment_modified"
00099
00101 #define DEFAULT_FOLDER L"DEFAULT_FOLDER"
00102
00103 #define SYNCSOURCE_STATE_OK 1
00104 #define SYNCSOURCE_STATE_NOT_SYNCED 2
00105 #define SYNCSOURCE_STATE_CANCELED 3
00106
00107 #define ERR_CODE_DROPPED_ITEMS 2100
00108 #define ERR_CODE_DROPPED_ITEMS_SERVER 2101
00109 #define ERR_CODE_NO_SOURCES 2102
00110
00114
00117 #define SCHED_PARAM L"schedule"
00118 #define NEVER "Never"
00119 #define EVERY_DAY "Every day"
00120
00124
00125
00126
00128
00129 #define MSG_BOX_CANCEL_SYNC "Are you really sure you want to cancel current synchronization?"
00130 #define WMSG_BOX_CANCEL_SYNC L"Are you really sure you want to cancel current synchronization?"
00131 #define WMSG_BOX_ASK_SLOW_1 L"The server has requested a full sync of all items for "
00132 #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.\n\nDo you wish to proceed? (YES in %d seconds...)"
00133 #define WMSG_BOX_ASK_SLOW_3 L".\nThis process may take up to a few minutes depending on the number of items\nand network bandwidth.\nYou are configured to perform a one-way sync, this can change data\non both the client and server.\n\nDo you wish to proceed?"
00134 #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?"
00135 #define WMSG_BOX_REFRESH_FROM_CLIENT L"A sync to replace your server data with your local data has been requested.\nAll the data will be deleted on the server before adding the local items.\nThis may result in the loss of data in any fields supported by other devices, but not by Outlook.\nAre you sure you want to continue?"
00136
00137
00138
00139 #define ERR_UNKNOWN "Unknown error."
00140 #define ERR_OPEN_OUTLOOK "Error opening Outlook application."
00141 #define ERR_ATTACH_OUTLOOK "Error attaching to Outlook application."
00142 #define ERR_TAG_NOT_FOUND "Bad XML format: tag '%ls' not found."
00143 #define ERR_BAD_FOLDER_PATH "Bad folder path: %ls"
00144 #define ERR_INSTALL_DIR "Error retrieving the install directory path."
00145 #define ERR_THREAD_PRIORITY "Error setting sync thread priority: code %d (%s)."
00146 #define ERR_THREAD_NOT_TERMINATED "Could not terminate the synchronization process. %s"
00147 #define ERR_MUTEX_CREATE "Could not create the mutex for synchronization process. %s"
00148 #define ERR_MUTEX_ALREADY_EXISTS "Error creating the mutex for sync process: mutex already exists. %s"
00149 #define ERR_MUTEX_NOT_RELEASED "Could not release the mutex of synchronization process. %s"
00150 #define ERR_MUTEX_OPEN "Could not open the mutex of synchronization process. %s"
00151 #define ERR_CLASS_REG_FAILED "Class Registration Failed! class name = %s"
00152 #define ERR_ENCRYPT_DATA "Error occurred encrypting private data"
00153 #define ERR_DECRYPT_DATA "Error occurred decrypting private data"
00154 #define ERR_NO_SOURCES_TO_SYNC "No sources to synchronize."
00155
00156 #define ERR_BEGIN_SYNC "Error in begin sync of source '%ls'."
00157 #define ERR_CLOSE_OUTLOOK "Some error occurred closing Outlook session. Outlook may become unstable."
00158 #define ERR_COM_INITIALIZE "Error occurred initializing COM library."
00159 #define ERR_COM_CREATE_INSTANCE "Error occurred creating an instance for COM library."
00160 #define ERR_END_SYNC "Error in end sync of source '%ls'."
00161 #define ERR_APPDATA_PATH "Error retrieving current user application data path: code %d (%s)"
00162 #define ERR_FILE_OPEN "Error opening file: %s"
00163 #define ERR_WFILE_OPEN "Error opening file: %ls"
00164 #define ERR_FILE_WRITE_ON "Error writing file: %s"
00165 #define ERR_WFILE_WRITE_ON "Error writing file: %ls"
00166 #define ERR_FILE_OPEN_MODE "Error writing file: bad fopen mode."
00167 #define ERR_DIR_CREATE "Error creating directory: %ls"
00168 #define ERR_DEFAULT_SSCONFIG "Error creating default config for %s: %s"
00169 #define ERR_MACHINE_NAME "GetComputerName error: code %d (%s)"
00170 #define ERR_USER_NAME "GetUserName error: code %d (%s)"
00171 #define ERR_USER_NAME_EX "GetUserNameEx error: code %d (%s)"
00172 #define ERR_INIT_LOG "Could not create the LOG file."
00173 #define ERR_INVALID_REG_PATH "Invalid windows registry path: %s."
00174 #define ERR_HKLM_KEYNOTFOUND "Error reading HKLM registry key '%s'.\nPlease reinstall the application."
00175
00176 #define ERR_FOLDER_OPEN "Error opening Outlook folder for source '%ls' with path '%ls'."
00177 #define ERR_FOLDER_PATH "'%ls' is not a folder selected for synchronization (see configuration of %ls source). Item received will be ignored."
00178 #define ERR_FOLDER_DEFAULT_PATH "Warning! No default folder found for %lss!"
00179 #define ERR_ITEM_GET "Error getting item \"%ls\" for source '%ls'."
00180 #define ERR_ITEM_GET_NEW "Error getting new item \"%ls\" for source '%ls'."
00181 #define ERR_ITEM_GET_MOD "Error getting modified item \"%ls\" for source '%ls'."
00182 #define ERR_ITEM_CREATE "Could not create a new %ls item into folder '%ls'"
00183 #define ERR_ITEM_FILL "Error setting properties of %ls item \"%ls\". Item not saved."
00184 #define ERR_INPUT_ITEM_FILTERED "Incoming %ls item \"%ls\" discarded because it doesn't verify current filters. Item not saved."
00185 #define ERR_INPUT_ITEM_DEL_FILTERED "Incoming %ls item \"%ls\" not deleted because it doesn't verify current filters."
00186 #define ERR_ITEM_BAD_TYPE "Mime type not supported: \"%ls\""
00187 #define ERR_ITEM_SAVE "Could not save %ls item \"%ls\" into folder '%ls'"
00188 #define ERR_ITEM_DELETE "Could not delete %ls item \"%ls\" from folder '%ls'"
00189 #define ERR_ITEM_DELETE_INTERNALLY L"Error removing internally the item."
00190 #define ERR_ITEM_UPDATE_NOT_FOUND "Could not update %ls item: ID = %ls not found."
00191 #define ERR_ITEM_DELETE_NOT_FOUND "Could not delete %ls item: ID = %ls not found."
00192 #define ERR_EVENTS_CREATED "Error occurred while checking if Outlook created a birthday/anniversary event."
00193 #define ERR_SOURCE_TOO_MANY_ERRORS "%d errors occurred on source %ls: source will not be used any more."
00194 #define ERR_SOURCE_LASTSYNCTIME_NOT_FOUND "Error reading \"%ls\": <LastSyncTime> not found."
00195 #define ERR_OCCURRENCE_NOT_FOUND "Error creating the appointment exception: occurrence \"%ls\" not found."
00196 #define ERR_OCCURRENCE_NOT_DELETED "Could not delete one occurrence (date = %ls)."
00197 #define ERR_OCCURRENCE_NOT_SAVED "Could not save one occurrence (date = %ls)."
00198 #define ERR_EXCEPTIONS_DEADLOCK "Detected too many dependences between appointment exceptions (%d). Exceptions not saved correctly."
00199 #define ERR_PROPERTY_REQUIRED "Error creating %ls item: property \"%ls\" is required."
00200
00201 #define ERR_PARSE_SIF_TAG_NOT_FOUND "Parsing error: SIF tag \"%ls\" not found."
00202 #define ERR_PARSE_PROPERTY_NOT_FOUND "Parsing error: property \"%ls\" not found."
00203 #define ERR_PARSE_PROPERTY_EMPTY "Parsing error: property \"%ls\" should not be empty."
00204 #define ERR_PARSE_APP_EXCEPTION "Error parsing appointment exception: %s"
00205 #define ERR_PARSE_EXC_NOREC "Could not add exceptions on a not-recurring appointment."
00206 #define ERR_NORMALIZE_EXCEPTIONS "Error normalizing appointment exceptions: %s"
00207
00208 #define ERR_SCHED_INIT_TASK "Error initializing Windows task scheduler."
00209 #define ERR_SCHED_SAVE "Scheduler error - failed to save the task, code = 0x%x - %s"
00210 #define ERR_SCHED_DELETE "Scheduler error - failed to delete the task, code = 0x%x - %s"
00211 #define ERR_SCHED_NEWWORKITEM "Scheduler error - failed calling ITask::NewWorkItem, code = 0x%x - %s"
00212 #define ERR_SCHED_CREATE_TRIGGER "Scheduler error - failed calling ITask::CreateTrigger, code = 0x%x - %s"
00213 #define ERR_SCHED_GET_TRIGGER "Scheduler error - failed calling ITask::GetTrigger, code = 0x%x - %s"
00214 #define ERR_SCHED_GET_TRIGGER2 "Scheduler error - failed calling ITaskTrigger::GetTrigger, code = 0x%x - %s"
00215 #define ERR_SCHED_SET_TRIGGER "Scheduler error - failed calling ITaskTrigger::SetTrigger, code = 0x%x - %s"
00216 #define ERR_SCHED_QUERY_INTERFACE "Scheduler error - failed calling ITask::QueryInterface, code = 0x%x - %s"
00217 #define ERR_SCHED_ACTIVATE "Scheduler error - failed calling ITaskScheduler::Activate, code = 0x%x - %s"
00218 #define ERR_SCHED_INVALID_PARAM "One or more arguments are invalid - please select a correct interval for scheduler"
00219 #define E_OBJECT_NOT_FOUND 0x80070002L // This should be mapped in winerror.h ??
00220
00221
00222 #define INFO_ITEM_ADDED "Added %ls item: \"%ls\""
00223 #define INFO_ITEM_UPDATED "Updated %ls item: \"%ls\""
00224 #define INFO_ITEM_DELETED "Deleted %ls item: \"%ls\""
00225 #define INFO_GET_ITEM "Retrieved %ls item: \"%ls\""
00226 #define INFO_GET_NEW_ITEM "Retrieved new %ls item: \"%ls\""
00227 #define INFO_GET_UPDATED_ITEM "Retrieved updated %ls item: \"%ls\""
00228 #define INFO_CONFIG_GENERATED "Configuration not found: default configuration will be used."
00229 #define INFO_SWV_UPGRADED "Configuration upgraded to new software version: v.%s (Funambol v.%s)"
00230 #define INFO_CONFIG_DEVID_SAVED "Set configuration deviceID = %s"
00231 #define INFO_OLD_ITEMS_NOT_FOUND "Cannot find list of items from previous sync. All items will be sent as modified."
00232 #define INFO_SYNC_COMPLETED "Syncronization process completed."
00233 #define INFO_SYNC_COMPLETED_ERRORS "Syncronization process completed with errors (code = %d)."
00234 #define INFO_EXIT "Exiting from Outlook client."
00235 #define INFO_SYNC_ABORTING "Aborting synchronization session..."
00236 #define INFO_SYNC_ABORTED_BY_USER "Synchronization aborted by user."
00237 #define INFO_SYNC_ABORTED_BY_USER_SLOW "Synchronization aborted by user to avoid full-sync of %ls."
00238 #define INFO_SCHED_TASK_CREATED "Scheduler task created."
00239 #define INFO_SCHED_TASK_DELETED "Scheduler task deleted."
00240 #define INFO_WRONG_MIME_TYPE "Warning: mime type not recognized: \"%ls\""
00241 #define INFO_REMOVING_ALL_ITEMS "Removing all existing %lss (%d items to delete)..."
00242 #define INFO_REMOVED_INTERNALLY L"Removed internally before sync"
00243
00244
00245 #define DBG_OUTLOOK_OPEN "beginSync of %ls source: opening Outlook session..."
00246 #define DBG_READ_ALL_ITEMS "Reading ALL %lss from folder '%ls' (%d found)..."
00247 #define DBG_CONFIG_CLOSED "Outlook configuration closed."
00248 #define DBG_STATE_ERR_ITEM_IGNORED "Source state is ERROR -> item will be ignored."
00249 #define DBG_LAST_SYNC_ABORTED "Last synchronization has been aborted, mutex of sync process will be released now."
00250 #define DBG_SYNC_ABORT_REQUEST "User requested to abort synchronization process..."
00251 #define DBG_THREAD_TERMINATED "Synchronization thread has been terminated."
00252 #define DBG_RRULE_BAD_FORMAT "Error parsing RRULE, bad format: %ls"
00253 #define DBG_SAFE_ITEM_NAME "Client Exception on getSafeName: %s"
00254 #define DBG_ANNIVERSARY_DELETED "While saving contact \"%ls\" an anniversary event was automatically created by Outlook and then just deleted!"
00255 #define DBG_BIRTHDAY_DELETED "While saving contact \"%ls\" a birthday event was automatically created by Outlook and then just deleted!"
00256 #define DBG_SCHED_TASK_NOT_FOUND "Scheduled task not found."
00257 #define DBG_SCHED_LAST_EXECUTION "The last task excecution was not performed. Please check windows task scheduler for more details"
00258 #define DBG_SCHED_TASK_MANUALLY_CHANGED "Scheduled task has been manually modified."
00259 #define DBG_NORMALIZING_EXCEPTION "Normalizing appointment exception: item \"%ls\", occurrence = %ls. A new item is created in Outlook."
00260 #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."
00261 #define DBG_PARSING_SIF_DATA "Parsing SIF %ls..."
00262 #define DBG_PARSING_EXCEPTIONS "Parsing appointment exceptions..."
00263 #define DBG_PARSING_VOBJ_DATA "Parsing VObject %ls (mime type = \"%ls\")..."
00264
00265
00266
00267 #define SBAR_CHECK_ALL_ITEMS 1
00268 #define SBAR_CHECK_MOD_ITEMS 2
00269 #define SBAR_CHECK_MOD_ITEMS2 3
00270 #define SBAR_WRITE_OLD_ITEMS 4
00271 #define SBAR_SENDDATA_BEGIN 5
00272 #define SBAR_SENDDATA_END 6
00273 #define SBAR_RECEIVE_DATA_BEGIN 7
00274 #define SBAR_RECEIVE_DATA_END 8
00275 #define SBAR_DELETE_CLIENT_ITEMS 9
00276 #define SBAR_ENDING_SYNC 10
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 #include "defs.h"
00291
00292
00293 #include <mstask.h>
00294 #include "spds/SyncItem.h"
00295 #include "vocl/WinItem.h"
00296 #include "outlook/ClientItem.h"
00297 #include "outlook/ClientAppointment.h"
00298 #include "OutlookConfig.h"
00299 #include "WindowsSyncSource.h"
00300
00301 #include <string>
00302
00303
00304
00305
00306
00307 int initializeClient (bool isScheduled, bool justRead = false);
00308 int initLog (bool isScheduled);
00309 int startSync ();
00310 int closeClient ();
00311 void closeOutlook ();
00312 void checkAbortedSync ();
00313 bool checkSyncInProgress();
00314 void softTerminateSync ();
00315 int hardTerminateSync (HANDLE hSyncThread);
00316 int exitSyncThread (int code);
00317 void endSync();
00318 void upgradePlugin (const int oldVersion, const int oldFunambolVersion);
00319 void upgradeScheduledTask();
00320
00321
00322
00325 __declspec(dllexport) OutlookConfig* getConfig();
00326 void createDefaultConfig();
00327 std::wstring pickOutlookFolder (const std::wstring& itemType);
00328 std::wstring getDefaultFolderPath(const std::wstring& itemType);
00332
00335 void initWinItems ();
00336 WinItem* createWinItem (bool useSIF, const std::wstring itemType);
00337 WinItem* createWinItem (bool useSIF, const std::wstring itemType, const std::wstring& data, const WCHAR** sifFields);
00338 SyncItem* convertToSyncItem (ClientItem* cItem, const char* dataType, const std::wstring& defaultFolder, bool addUserProperties = true);
00339 int fillClientItem (const std::wstring& sif, ClientItem* cItem, const std::wstring& itemType, const WCHAR* dataType);
00340 WCHAR** getProperSifArray (const std::wstring& type);
00341 int normalizeExceptions(ClientItem* cItem, itemKeyList& allItems, itemKeyList& allItemsPaths);
00342 int deleteOccurrencesInInterval(const DATE startDate, const DATE originalDate, ClientRecurrence* cRec);
00343 int setRecurrenceExceptions(ClientItem * cItem, ClientRecurrence * cRec, std::list<std::wstring> &excludeDates, std::list<std::wstring> &includeDates);
00344 int checkIllegalXMLChars(char* data);
00345 std::wstring getVPropertyValue (const std::wstring& dataString, const std::wstring& propertyName);
00346 void replaceDefaultPath(std::wstring& path, const std::wstring& defaultFolder);
00350
00353 int setScheduler (const bool enable, const int minutes);
00354 bool getScheduler (int* minutes);
00355 int setScheduleTask (const char* frequency, const int dayNum, const int minNum);
00356 int getScheduleTask (bool* active, int* dayNum, int* minNum);
00357 int deleteScheduleTask();
00358 ITaskScheduler* initScheduleInstance();
00359 int getScheduledTaskName(std::wstring& taskName);
00360 void setProgramNameForScheduledTask(std::wstring name);
00363 const char* getClientLastErrorMsg ();
00364 const int getClientLastErrorCode();
00365
00366 int OpenMessageBox(HWND hwnd, UINT type, UINT msg);
00367 _declspec(dllexport) int checkUpdate(const char *infoURL, char *availableVersionData, char *updateURLData);
00368
00379 int updateProcedure(HWND hwnd, bool manual = false);
00380
00386 bool isNewSwVersionAvailable();
00387
00393 int checkUpdate();
00394
00395 bool checkForMandatoryUpdateBeforeStartingSync();
00396
00400 ArrayList* getVTodoProperties();
00401 ArrayList* getVCalendarProperties();
00402 ArrayList* getVCardProperties();
00403 ArrayList* getNoteProperties();
00404 ArrayList* getVNoteProperties();
00405
00406
00411 __declspec(dllexport) StringBuffer getOutlookVersion();
00412
00415 #endif