OpenChange: Avoid crashing when creating embedded message in attachment

Signed-off-by: Kamen Mazdrashki <kamenim@samba.org>
(cherry picked from commit 15a55f9f707247c9164e8fa7a102639744f686e5)
add try catch to all functions on struct mapistore_backend
use execinfo.h to get backtrace

Really poor backtrace because it will only have the frames from oc side,
I don't know why callStackSymbols is returning null, compilation flags?
oc-sogo: try/catch to guard only the actual impelementation rather than *everything*

Signed-off-by: Kamen Mazdrashki <kmazdrashki@zentyal.com>
oc-sogo: Clean up AutoRelease pool and unregister threads in Catch handler

Most of the time we have "not yet implemented" kind of exceptions,
so it is better to clean up allocated resources

Signed-off-by: Kamen Mazdrashki <kmazdrashki@zentyal.com>
oc-sogo: Use [e name] and [e reason] selectors

Signed-off-by: Kamen Mazdrashki <kmazdrashki@zentyal.com>
oc-sogo: Move memory clean up *after* handling the exception

Otherwise the mess is full :)

Signed-off-by: Kamen Mazdrashki <kmazdrashki@zentyal.com>
oc-sogo: Print both [NSException callStackSymbols] and execinfo.h stack trace

Signed-off-by: Kamen Mazdrashki <kmazdrashki@zentyal.com>
oc-sogo: pretty print Exceptions in sogo_backend_handle_objc_exception()

Now we have a nice stack trace printed out from [NSException callStackSymbols]

Signed-off-by: Kamen Mazdrashki <kmazdrashki@zentyal.com>
openchange: getMessageData - replace int literals with ulRecipClass values

Signed-off-by: Kamen Mazdrashki <kmazdrashki@zentyal.com>
openchange: FillMessageHeadersFromProperties fix skipping of last value in
possible range of recepients

IMHO, this fixes a bug, that when saving a meessage, it  is saved
without BCC fields.

Signed-off-by: Kamen Mazdrashki <kmazdrashki@zentyal.com>
openchange/MAPIStoreFolder: Add private selector for actual folder delete action

Usually, it is a bad idea for an object to call its own public methods
(just like in this case). Thus separating impelementation for deleteFolder:
would allow MAPIStoreFolder to call only private implementation when needed

Signed-off-by: Kamen Mazdrashki <kmazdrashki@zentyal.com>
openchange: Fix submitWithFlags to submit to BCC-ed recipients also

this reintroduces commit 7efb263c659451d2c781547a5b38cb5d01ed837f

Signed-off-by: Kamen Mazdrashki <kmazdrashki@zentyal.com>
openchange: don't overflow possible recipient type while creating message headers

Signed-off-by: Kamen Mazdrashki <kmazdrashki@zentyal.com>
oc/MAPIStoreContext: Fix log messages to actually print 64bit FMIDs

Signed-off-by: Kamen Mazdrashki <kmazdrashki@zentyal.com>
oc/MAPIStoreSOGo: Do not destroy current thread context after any API call

We have thread context already in place during *_init() function.
Thus guarding every API call with TreadInit/Destroy is:
- a bit redundand
- makes SOGo backend not reentrant even on single thread and leads
  to hard to find use-after-free crashes

Signed-off-by: Kamen Mazdrashki <kmazdrashki@zentyal.com>
oc: Log when mapistore backend is successfully initialized
oc: Protect backend initialization to happen only once
oc/TallocWrapper: don't handle Threading initialization here

It is SOGo backend module responsibility to setup/teardonw all
ObjC specific initialization

Signed-off-by: Kamen Mazdrashki <kmazdrashki@zentyal.com>
Error message only when initialization hadn't been done

In a multithread environment, sogo_backend_init is registering the thread
only for the first one that calls this function, then the others threads
(even if they call sogo_backend_init) won't be registered because
moduleInitialized was YES.

We just want to ensure sogo_backend_init is called at least once (per process,
not per thread).