16 months agostrdup -> xstrdup
Andre Heinecke [Mon, 23 Jul 2018 11:04:34 +0000 (13:04 +0200)]
strdup -> xstrdup


16 months agoRemove unused code
Andre Heinecke [Mon, 23 Jul 2018 07:42:59 +0000 (09:42 +0200)]
Remove unused code

* src/main.c (create_initialization_vector)
(get_crypt_random): Removed.

16 months agoMake async encryption optional
Andre Heinecke [Mon, 23 Jul 2018 07:31:51 +0000 (09:31 +0200)]
Make async encryption optional

* src/common_indep.h (opt): Add sync_enc.
* src/mail.cpp (Mail::isAsynCryptDisabled_o): Respect it.
* src/main.c (read_options): Read it.

If we have users where GpgOL crashes on send we or the
user might want to disable async encryption.

GnuPG-Bug-Id: T3838

16 months agoImprove invalidation blocking
Andre Heinecke [Mon, 23 Jul 2018 06:15:30 +0000 (08:15 +0200)]
Improve invalidation blocking

* src/mail.cpp (do_parsing): Don't use invalidation_lock. We now have
block invalidation.
* src/mailitem-events.cpp (Read): Delay invalidate.
* src/windowmessages.cpp (delayed_invalidate_ui): Take sleep param.
(INVALIDATE_UI): Respect invalidation blocked.
* src/windowmessages.h: Update accordingly.

This works much better then the try to archive minimizing
invalidations by using a lock.

16 months agoTrace return of UI callbacks
Andre Heinecke [Mon, 23 Jul 2018 06:12:16 +0000 (08:12 +0200)]
Trace return of UI callbacks

* src/ribbon-callbacks.cpp: Trace returns.

These functions are often times the last functions in the
log of a crash as they are called whenever the UI changed.
There is no crash in them but to better see it anway we
log when they are done.

16 months agoFix invalidate UI only on unselect
Andre Heinecke [Mon, 23 Jul 2018 06:09:26 +0000 (08:09 +0200)]
Fix invalidate UI only on unselect

* src/explorer-events.cpp (start_watchdog): Only invalidate
UI on unselect.

16 months agounique_ptr++
Andre Heinecke [Mon, 23 Jul 2018 06:08:06 +0000 (08:08 +0200)]

* src/parsecontroller.cpp (ParseController::get_ultimate_keys): Use
unique ptr for context.

16 months agoFix make dist
Andre Heinecke [Fri, 20 Jul 2018 13:52:52 +0000 (15:52 +0200)]
Fix make dist

* po/ Update file list.

16 months agoNext version will be 2.3.0
Andre Heinecke [Fri, 20 Jul 2018 13:52:09 +0000 (15:52 +0200)]
Next version will be 2.3.0

* Bump minor version.

Lots of traumatic changes.

16 months agoDon't print error in memdbg if caller changes
Andre Heinecke [Fri, 20 Jul 2018 13:24:11 +0000 (15:24 +0200)]
Don't print error in memdbg if caller changes

* src/memdbg.cpp (register_name): Don't print error
if the name changed and the calling function was used as the name.

16 months agoMake UI invalidation more deterministic
Andre Heinecke [Fri, 20 Jul 2018 13:21:34 +0000 (15:21 +0200)]
Make UI invalidation more deterministic

* src/explorer-events.cpp (hasSelection, startWatchdog, changeSeen):
* src/mail.cpp (do_parsing): Block invalidation while parsing.
* src/windowmessages.cpp (blockInv, unblockInv): New.
(delayed_invalidate_ui): Handle block inv state.
* src/windowmessages.h: Update accordingly.

UI Invalidation is extremly expensive and often a cause for
crashes. So we should avoid it as much as possible. This
code aims just to do that while still not skipping any
required invalidation.

16 months agoAdd tracing for update body
Andre Heinecke [Fri, 20 Jul 2018 13:00:05 +0000 (15:00 +0200)]
Add tracing for update body

* src/mail.cpp (Mail::updateBody_o): Trace calls.

This seems to hang sometimes so lets make sure that it
is actually the oom call that hangs.

16 months agoPrint error if addin is accessed after shutdown
Andre Heinecke [Fri, 20 Jul 2018 12:58:15 +0000 (14:58 +0200)]
Print error if addin is accessed after shutdown

* src/gpgoladdin.cpp (GpgolAddin::get_instace): Print error
when accessed.

I thought this might be happening.

16 months agoImplement cpp ctor / dtor counting
Andre Heinecke [Fri, 20 Jul 2018 12:57:34 +0000 (14:57 +0200)]
Implement cpp ctor / dtor counting

* src/memdbg.cpp (memdbg_ctor, memdbg_dtor): Implement.

16 months agoUse reffing function as name for IUnknown
Andre Heinecke [Fri, 20 Jul 2018 12:55:27 +0000 (14:55 +0200)]
Use reffing function as name for IUnknown

* src/memdbg.cpp (_memdbg_addRef, register_name): Use
calling function as the name for IUnknwon refs.

This is very useful to see at a glance which refs are
open. E.g. to see the event sink references.

16 months agoAdd simple dtor / ctor counting of Cpp objs
Andre Heinecke [Fri, 20 Jul 2018 12:53:53 +0000 (14:53 +0200)]
Add simple dtor / ctor counting of Cpp objs

This adds memdbg trace function to the important objects
to double check that we don't loose / leak any.

16 months agoAccept multipart/mixed application/pgp-encrypted
Andre Heinecke [Fri, 20 Jul 2018 12:51:30 +0000 (14:51 +0200)]
Accept multipart/mixed application/pgp-encrypted

* src/mapihelp.cpp (change_message_class_ipm_note): Accept
multipart/mixed with protocol application/pgp-encrypted.

This happens when an encrypted mail is moved by Outlooks
local filter move rules.

GnuPG-Bug-Id: T4070

16 months agoRemove dead code and add some addRefs
Andre Heinecke [Fri, 20 Jul 2018 12:01:43 +0000 (14:01 +0200)]
Remove dead code and add some addRefs

* src/mapihel.cpp, src/mapihelp.h (has_gpgol_body_name)
(mapi_get_gpgol_body_attachment, mapi_delete_gpgol_body_attachment),
(mapi_attachment_to_body): Removed.

16 months agoFix ref leak on no object error
Andre Heinecke [Fri, 20 Jul 2018 11:15:49 +0000 (13:15 +0200)]
Fix ref leak on no object error

* src/oomhelp.cpp (get_oom_object): Release pDisp always.

This fixes a common reference leak from the check_inline_response
codepath. Where it would leak for everything that is not an
inline response.

16 months agoFix minor ref leaks
Andre Heinecke [Fri, 20 Jul 2018 10:04:50 +0000 (12:04 +0200)]
Fix minor ref leaks

* src/oomhelp.cpp (get_account_for_mail): Release account.
(ensure_category_exists): Release categories on error.

16 months agoFix ref leak in get_oom_recipients
Andre Heinecke [Fri, 20 Jul 2018 10:04:10 +0000 (12:04 +0200)]
Fix ref leak in get_oom_recipients

* src/oomhelp.cpp (get_oom_recipients): Release addrEntry.

16 months agoAdd missing memdbg_addRefs
Andre Heinecke [Fri, 20 Jul 2018 10:03:03 +0000 (12:03 +0200)]
Add missing memdbg_addRefs

* src/mapihelp.cpp (mapi_get_attach): Add missing addRef.
* src/mimemaker.cpp (create_mapi_attachment): Ditto.

16 months agoAdd ptr and line to addRef dbg output
Andre Heinecke [Fri, 20 Jul 2018 10:02:10 +0000 (12:02 +0200)]
Add ptr and line to addRef dbg output

* src/memdbg.h (memdbg_addRef): Debug out the line.

This makes it easy to find where leaked objects were

16 months agoFix attach table leak
Andre Heinecke [Fri, 20 Jul 2018 10:01:23 +0000 (12:01 +0200)]
Fix attach table leak

* src/cryptcontroller.cpp (CryptController::collect_data): Fix
table leak.

16 months agoFix ref leak in setDoAutosecure_m
Andre Heinecke [Fri, 20 Jul 2018 09:18:34 +0000 (11:18 +0200)]
Fix ref leak in setDoAutosecure_m

* src/mail.cpp (Mail::setDoAutosecure_m): Release msg.

16 months agoFix big reference leak of cipherstream / message
Andre Heinecke [Fri, 20 Jul 2018 08:48:02 +0000 (10:48 +0200)]
Fix big reference leak of cipherstream / message

* src/mail.cpp (get_attachment_stream_o): Release
message and mapi_attachment after obtaining the stream.

This is a big leak. It probably means that Outlook kept
the original Message fully in the memory.

For this the memdbg interface might already be worth it.

16 months agoImprove memdbg name output
Andre Heinecke [Fri, 20 Jul 2018 08:46:13 +0000 (10:46 +0200)]
Improve memdbg name output

* src/memdbg.cpp (register_name): Handle name changes.
(memdbg_addRef): Handle name change.

16 months agoChange an error to debug
Andre Heinecke [Fri, 20 Jul 2018 08:45:00 +0000 (10:45 +0200)]
Change an error to debug

* src/mail.cpp (Mail::installFolderEventHandler_o): Don't
print the success message as error.

16 months agoUnref application unload / shutdown
Andre Heinecke [Fri, 20 Jul 2018 08:43:02 +0000 (10:43 +0200)]
Unref application unload / shutdown

* src/gpgoladdin.cpp (GpgolAddin::shutdown): Release

Minor and should not have been a problem.

16 months agoFix reference error on Explorer / Explorers object
Andre Heinecke [Fri, 20 Jul 2018 08:40:40 +0000 (10:40 +0200)]
Fix reference error on Explorer / Explorers object

* src/gpgoladdin.cpp (install_explorer_sinks): Release
explorer and explorers after installing the sinks.

The sinks handle the ref counting by themself. The
reference leak should be not a real problem because
the sinks keep them anyway until the end of the

16 months agoAdd memdbg handling for MAPI
Andre Heinecke [Fri, 20 Jul 2018 08:34:00 +0000 (10:34 +0200)]
Add memdbg handling for MAPI

* src/gpgoladdin.cpp (GpgolAddin::OnConnection): Ref application.
* src/mapihelp.cpp: Replace OpenProperty by gpgol_openProperty.
memdbg_addRef for some MAPI functions that return an object.
* src/mimemaker.cpp: Replace OpenProperty by gpgol_openProperty.
* src/mlang-charset.cpp (ansi_charset_to_utf8): Mark multilang
as reffed.
* src/olflange.cpp (install_forms): Mark formcontainer as reffed.
* src/oomhelp.cpp, src/oomhelp.h (gpgol_queryInterface): New.
(get_oom_iunknown): Add ref.
(get_oom_base_message_from_mapi): Add ref.
* src/ribbon-callbacks.cpp (getIcon): Add ref on stream and
change it to be automatically freed as we don't free it.

16 months agoImprove GpgolAddin debug output
Andre Heinecke [Fri, 20 Jul 2018 08:30:23 +0000 (10:30 +0200)]
Improve GpgolAddin debug output

* src/gpgoladdin.cpp (DllCanUnloadNow): Trace call.
(GpgolRibbonExtender::~GpgolRibbonExtender): Dump memory map.
(GpgolAddinFactory::~GpgolAddinFactory): Debug dtor.

16 months agoDon't export DllCanUnloadNow at all
Andre Heinecke [Fri, 20 Jul 2018 08:28:42 +0000 (10:28 +0200)]
Don't export DllCanUnloadNow at all

* src/gpgol.def (DllCanUnloadNow): Don't export.

We don't want to be unloaded by com cleanup. And
while we should have returned false always I
saw one crash immediately after a Dll can unload

16 months agoAlso debug oom if debug oom_extra is set
Andre Heinecke [Fri, 20 Jul 2018 08:27:26 +0000 (10:27 +0200)]
Also debug oom if debug oom_extra is set

* src/common_indep.h (gpgol_release): Add line.
(debug_oom): Also debug for oom_extra

Debug oom is one of the debug settings that need to go
in the future.

16 months agoDecorate eventsink with memdbg helpers
Andre Heinecke [Fri, 20 Jul 2018 08:26:48 +0000 (10:26 +0200)]
Decorate eventsink with memdbg helpers

* src/eventsink.h: Add memdbg helpers

16 months agoFix minor ref leak
Andre Heinecke [Fri, 20 Jul 2018 06:28:58 +0000 (08:28 +0200)]
Fix minor ref leak

* src/oomhelp.cpp (get_ol_ui_language): Release langsettings.

16 months agoStart memdbg interface for COM ref counting
Andre Heinecke [Fri, 20 Jul 2018 06:20:18 +0000 (08:20 +0200)]
Start memdbg interface for COM ref counting

* src/ Add memdbg files.
* src/common_indep.h (gpgol_release): Call memdbg_released.
* src/eventsink.h (install..sink): Use gpgol_queryInterface
* src/mailitem-events.cpp (Unload): Dump memdbg maps after unload.
* src/oomhelp.h (gpgol_queryInterface): New.
* src/mimedataprovider.cpp (MimeDataProvider::MimeDataProvider):
Register ref add.
* src/oomhelp.cpp (gpgol_queryInterface): New.
(get_object_name): Use non memdbg aware functions.
(get_oom_object): Use gpgol_queryInterface.
(get_oom_object): Print out refs when obtaining if.
(get_oom_control_bytag, get_object_by_id),
(get_oom_mapi_session): Use mdbg functions.

The idea is that in the end we will trace all
com reference obtains and releases to find mismatchs
and additionally all malloc / frees and C++ dtor / ctor
to find memory leaks and hopefully random instability or
crashes caused by invalid ref counting.

As we can't use valgrind or decent debugging in
Outlook on Windows tracking it ourself seems
to be useful.

16 months agoOnly shutdown for the last explorer close
Andre Heinecke [Wed, 18 Jul 2018 12:32:40 +0000 (14:32 +0200)]
Only shutdown for the last explorer close

* src/windowmessages.cpp (gpgol_hook): Only shutdown if
the last explorer is closed.

This acidentally mostly worked before as we only registered
the first explorer for this function in the past.

Also added a comment remembering what this function actually
intends and why it is needed.

16 months agoMinor performance improvement
Andre Heinecke [Wed, 18 Jul 2018 12:04:03 +0000 (14:04 +0200)]
Minor performance improvement

* src/parsecontroller.cpp (ParseController::parse): Check that
get_ultimate_keys is only called once even for multisigs.

16 months agoPrint binary mime data as hex
Andre Heinecke [Wed, 18 Jul 2018 12:03:23 +0000 (14:03 +0200)]
Print binary mime data as hex

* src/mimedataprovider.cpp (MimeDataProvider::read): Dump
binary as hex.

16 months agoMinor perfomance improvement
Andre Heinecke [Wed, 18 Jul 2018 12:02:26 +0000 (14:02 +0200)]
Minor perfomance improvement

* src/mail.cpp (level_4_check): Reduce copies
of get_ultimate_keys vector.

16 months agoOnly treat unknown sigs as lvl2 if they are valid
Andre Heinecke [Wed, 18 Jul 2018 12:00:53 +0000 (14:00 +0200)]
Only treat unknown sigs as lvl2 if they are valid

* src/mail.cpp (Mail::updateSigstate): Check for sigsum valid
before using WKD as shortcut to lvl 2.

Using GPGME's sigstate is clunky.

16 months agoAdd helper functions for hexdump
Andre Heinecke [Wed, 18 Jul 2018 11:59:45 +0000 (13:59 +0200)]
Add helper functions for hexdump

* src/cpphelp.cpp, src/cpphelp.h (is_binary, string_to_hex): New.

16 months agoRewrite get_tmp_outfile to fix a crash
Andre Heinecke [Tue, 17 Jul 2018 14:54:43 +0000 (16:54 +0200)]
Rewrite get_tmp_outfile to fix a crash

* src/common.cpp (get_tmp_outfile): Rewrite using c++.
(getTmpPathUtf8, CreateFileUtf8): New helpers.

This fixes a crash because somehow snwprintf didn't
always work as I expeted it to. In that case it would
only concatenate the first chars of the attachment filenames
this caused the wcsrchr of the backslash to return NULL and
the following wcschr to find the extension to crash.

This happend on a name conflict in the tmp folder. E.g.
if two mails were open with the same attachment filenames.

16 months agoAdd wchar_to_utf8_string function
Andre Heinecke [Tue, 17 Jul 2018 14:53:43 +0000 (16:53 +0200)]
Add wchar_to_utf8_string function

* src/w32-gettext.cpp, src/w32-gettext.h (wchar_to_utf8_string):
Wrap the c to c++ conversion in a function.

16 months agoLoad gpgconf in a background thread
Andre Heinecke [Tue, 17 Jul 2018 13:04:19 +0000 (15:04 +0200)]
Load gpgconf in a background thread

* src/cpphelp.cpp (is_de_vs): Set checked earlier for
better reentrancy.
* src/gpgoladdin.cpp (OnStartupComplete): init_gpgme_config.

GpgME++ already handles caching for us. All we have to
do is trigger loading early and in a non-blocking manner.

16 months agoFix possible invalid CloseHandle and DeleteFile
Andre Heinecke [Tue, 17 Jul 2018 12:53:24 +0000 (14:53 +0200)]
Fix possible invalid CloseHandle and DeleteFile

* src/mail.cpp (add_attachments_o): Guard CloseHandle and

CloseHandle may only be called on valid handles.

16 months agoCleanup shutdown and fix potential crashes
Andre Heinecke [Tue, 17 Jul 2018 12:43:12 +0000 (14:43 +0200)]
Cleanup shutdown and fix potential crashes

* src/explorer-events.cpp (Close): Unregister sink with addin.
* src/explorers-events.cpp (NewInstance): Register sink.
* src/gpgoladdin.cpp (GpgolAddin::~GpgolAddin): Remove shutdown
(GpgolAddin::OnConnection): Mark shutdown state as false.
(GpgolAddin::OnDisconnection): Call shutdown.
(install_explorer_sinks): Register created sinks.
(GpgolAddin::shutdown): New. Handle shutdown.
(GpgolAddin::unregisterExplorerSink): Track explorer sinks.
* src/gpgoladdin.h: Update accordingly.
* src/mail.cpp (Mail::closeAllMails_o): Fix folder events
detach and do it earlier.
(Mail::installFolderEventHandler_o): Use sink instead of folder
to track event handler.
* src/windowmessages.cpp (add_explorer, remove_explorer): removed.
(gpgol_hook): Interate over actual explorers instead of variables.
* src/windowmessages.h: Update accordingly.

This fixes Explorer events release / deletion on unload / shutdown.
Previously this was only done on close, which came after GpgOL
was unloaded. Maybe this resulted in a jump to an unmapped location?

It also fixes that the gpgol_hook was only enabled for all explorers
at start time. Maybe we will see a regression now that it works
as intended on all explorers.

Explorers Events and Application Events were never deleted / released
because they were not detached before release. (But the release
then didn't delete them).

Definitely fixed is a race condition on shutdown which would be:
-> Shutdown detected
-> Close all mails
-> The currently visible mail is closed
-> Outlook loads it again because it is currently visible
-> But we are in shutdown mode.

Now we would start to parse while actually shutting down. This
could lead to hangs / crashes. The reason for this was that
we closed the mails before we detached the Application event
handler and thus captured the item load again.

17 months agoTune down error to debug
Andre Heinecke [Wed, 11 Jul 2018 14:48:21 +0000 (16:48 +0200)]
Tune down error to debug

* src/mail.cpp (get_uid_for_sender): It's common for S/MIME
to have two uids where one does not have an email. So don't
error but just debug it.

17 months agoCheck for wchar_t conversion success for attach
Andre Heinecke [Wed, 11 Jul 2018 14:47:32 +0000 (16:47 +0200)]
Check for wchar_t conversion success for attach

* src/mail.cpp (add_attachments_o): Check wchar_name.

17 months agoLog sent windowmessages
Andre Heinecke [Wed, 11 Jul 2018 14:46:37 +0000 (16:46 +0200)]
Log sent windowmessages

* src/windowmessages.cpp (do_in_ui_thread): Log message sending.

17 months agoMinor improvement to debug output
Andre Heinecke [Wed, 11 Jul 2018 14:46:14 +0000 (16:46 +0200)]
Minor improvement to debug output


17 months agoCheck if someone tries to set null as att name
Andre Heinecke [Wed, 11 Jul 2018 14:45:22 +0000 (16:45 +0200)]
Check if someone tries to set null as att name

* src/attachment.cpp (Attachment::set_display_name): Check for NULL.

Should not happen but better save then sorry

17 months agoAbort attachment process chain in case of error
Andre Heinecke [Wed, 11 Jul 2018 06:32:57 +0000 (08:32 +0200)]
Abort attachment process chain in case of error

* src/mail.cpp (add_attachments_o): Don't continue with attachment
processing if something failed.

This should make the errors clearer and avoid undefined behavior
in case e.g. obtaining an attachment tmp name fails.

GnuPG-Bug-Id: T4063

17 months agoLog w32 error and tried filename for tmp attach
Andre Heinecke [Wed, 11 Jul 2018 06:31:54 +0000 (08:31 +0200)]
Log w32 error and tried filename for tmp attach

* src/common.cpp (get_tmp_outfile): Log error and tried filename.

This will help analyse issues like:
GnuPG-Bug-Id: T4063

17 months agoConvert common to cpp and clean it up
Andre Heinecke [Tue, 10 Jul 2018 12:26:12 +0000 (14:26 +0200)]
Convert common to cpp and clean it up

* src/ Remove config-dialog.c
* src/common.c, src/common.cpp: Cppify, cleanup.
* src/config-dialog.c: Remove it.
* src/gpgoladdin.cpp (GetCustomUI_MIME): Use normal utf8_to_wchar.

17 months agoRemove accidentally commited dev debug
Andre Heinecke [Tue, 10 Jul 2018 11:47:52 +0000 (13:47 +0200)]
Remove accidentally commited dev debug


17 months agoAdd support for distribution lists (groups)
Andre Heinecke [Tue, 10 Jul 2018 10:25:45 +0000 (12:25 +0200)]
Add support for distribution lists (groups)

* src/oomhelp.cpp (get_recipient_addr_fallbacks):
Handle distributionb lists and plit into
(get_recipient_addr_entry_fallbacks_ex): New. Handle
the exchange stuff.
(try_resolve_group): Resolve distribution lists.
(get_oom_recipients): Check for distribution lists.
* src/oomhelp.h: Add some new defines.

This adds support for contact groups / distribution lists.
Not tested with exchange yet but it should work as the code
for the exchange fallbacks is still used.

GnuPG-Bug-Id: T4065

17 months agoLog keys used in internal resolution
Andre Heinecke [Tue, 10 Jul 2018 10:24:45 +0000 (12:24 +0200)]
Log keys used in internal resolution

* src/cryptcontroller.cpp (CryptController::resolve_keys_cached):
Log used keys.

Can be helpful to detect problems.

17 months agoImprove recipient handling
Andre Heinecke [Tue, 10 Jul 2018 08:50:33 +0000 (10:50 +0200)]
Improve recipient handling

* src/cryptcontroller.cpp (CryptController::CryptController),
src/keycache.cpp (KeyCache::isMailResolvable),
src/wks-helper.cpp (WKSHelper::handle_confirmation_read):
Update call to mail->getRecipients.
* src/mail.h (Mail::getRecipients): Renamed to
* src/mail.cpp (Mail::getRecipients_o): Adapt to vector.
Add error handling.
(Mail::updateOOMData_o): Use vector directly.
* src/oomhelp.cpp, src/oomhelp.h (get_oom_recipients):
Use vector and provide an error.

Downstream we already used the recipients mostly as a
vector anyway to avoid the memory mangement hassle.
This gives us more flexibility.

Additionally we now report an error for the case
GnuPG-Bug-Id: T4065

17 months agoUse unique ptr for parser context
Andre Heinecke [Tue, 10 Jul 2018 08:30:51 +0000 (10:30 +0200)]
Use unique ptr for parser context

* src/parsecontroller.cpp (ParseController::parse): Use unique
ptr for GpgME Context.

Wherever I see it I tend to change it. Makes the code

17 months agoUse c++ linkage for oomhelp and conv w32getttext
Andre Heinecke [Tue, 10 Jul 2018 08:27:50 +0000 (10:27 +0200)]
Use c++ linkage for oomhelp and conv w32getttext

* src/mapihelp.h: Don't include oomhelp with c linkage.
* src/oomhelp.h: Use C++ linkage.
* src/ Update accordingly.
* src/w32-gettext.c, src/w32-gettext.cpp: Renamed. Added
casts for c++ and removed trailing whitespace.
* src/w32-gettext.h: Use C linkage for gettext.

We have some few C only files like common and main but
mostly we are fully c++. Using C++ linkage will allow
us to change oomhelp functions to work with C++ data
types for better memory management.

17 months agoClarify logging for empty UID emails
Andre Heinecke [Mon, 9 Jul 2018 14:24:32 +0000 (16:24 +0200)]
Clarify logging for empty UID emails

* src/mail.cpp (get_uid_for_sender): Check that email is
not empty.

17 months agoImplement "prefer-smime" option
Andre Heinecke [Mon, 9 Jul 2018 14:22:34 +0000 (16:22 +0200)]
Implement "prefer-smime" option

* src/cryptcontroller.cpp (CryptController::resolve_keys_cached):
Respect prefer smime setting.

Some prefer SM.

GnuPG-Bug-Id: T3961

17 months agoMore options / config cleanup
Andre Heinecke [Mon, 9 Jul 2018 14:19:35 +0000 (16:19 +0200)]
More options / config cleanup

* src/main.cpp (write_options): Remove most options now
controlled by the external dialog.
(get_conf_bool): New helper.
(read_options): Use it.
* src/common_indep.c (set_default_key): Removed.
* src/common_indep.h (opt): Remove obsolete values and
add some new ones.

Most of the removed options were already obsolete for

GnuPG-Bug-Id: T3944

17 months agoFix crash for attachment names > 76 chars
Andre Heinecke [Mon, 9 Jul 2018 13:37:28 +0000 (15:37 +0200)]
Fix crash for attachment names > 76 chars

* src/rfc2047parse.c (rfc2047_decode_tokens): Use return
value of realloc.

This was introduced by me when porting rfc2047parse away from
glib. *blushes*

GnuPG-Bug-Id: T4062

17 months agotests: Don't override GNUPGHOME in run-parser
Andre Heinecke [Mon, 9 Jul 2018 13:16:07 +0000 (15:16 +0200)]
tests: Don't override GNUPGHOME in run-parser

* tests/run-parser.c (main): Don't override the GNUPGHOME

This was useful back when I ran the parser test mostly on
KMail's testcorpus but now when I use it to debug other
errors it is better to let the user set the homedir.

17 months agoFix linux build
Andre Heinecke [Mon, 9 Jul 2018 13:09:13 +0000 (15:09 +0200)]
Fix linux build

* src/parsecontroller.cpp (ParseController::parse): Ifdef
native encoding workaround.

17 months agoSwitch back to old check for reading pane for ol16
Andre Heinecke [Fri, 6 Jul 2018 09:54:11 +0000 (11:54 +0200)]
Switch back to old check for reading pane for ol16

* src/ribbon-callbacks.cpp (get_mail_from_control): Use the
same codepath as OL2010 and 13 for 2016 again, too.

The crash in Outlook 2016 started to appear at some point.
Now after various updates to Outlook I can no longer reproduce it.
As the previewpane.wordeditor is not reliable. see:
GnuPG-Bug-Id: T4056

We disable that codepath again. The crash report was
GnuPG-Bug-Id: T3484

17 months agoAdd log_addins oomhelp function
Andre Heinecke [Fri, 6 Jul 2018 09:16:19 +0000 (11:16 +0200)]
Add log_addins oomhelp function

* src/oomhelp.cpp, src/oomhelp.h (log_addins): New.
(get_oom_object): Debug dispid.

I could not find a place where the call to Item(x) does
not result in the general 80020009 exception. Strange.
There is something fishy here because "Item" has dispid 0. But
this is also what OutlookSpy shows.

17 months agoAdd missing i18n for conf dialog
Andre Heinecke [Fri, 6 Jul 2018 09:15:12 +0000 (11:15 +0200)]
Add missing i18n for conf dialog

* src/addin-options.cpp (i18n_noops): Add another option string.

17 months agoRemove now unused WinAPI dialog resource
Andre Heinecke [Tue, 3 Jul 2018 14:21:38 +0000 (16:21 +0200)]
Remove now unused WinAPI dialog resource

* src/dialogs.rc: Remove last winapi dialog.

17 months agoChange addion-options to use external dialog
Andre Heinecke [Tue, 3 Jul 2018 14:14:43 +0000 (16:14 +0200)]
Change addion-options to use external dialog

* src/addin-options.cpp (open_gpgolgui): New.
(options_dialog_box): Open gpgolgui or bring it to foreground.
(i18n_noops): Add strings.
(launch_kleo_config): Removed.
(options_window_proc): Removed.

This adds a new config dialog which is a dynamic qt application.
It uses the translations from GpgOL.

GnuPG-Bug-Id: T3944

17 months agoMake it possible to move decrypted mails
Andre Heinecke [Tue, 26 Jun 2018 14:18:38 +0000 (16:18 +0200)]
Make it possible to move decrypted mails

* src/ Add folder-events.cpp
* src/eventsinks.h (install_FolderEvents_sink),
(detach_FolderEvents_sink): New.
* src/folder-events.cpp: New event handler.
* src/mail.cpp (s_folder_events_map): New map to track
registered handlers.
(Mail::isAboutToBeMoved, Mail::setIsAboutToBeMoved): New.
(Mail::installFolderEventHandler_o): New.
(Mail::closeAllMails_o): detach folder handler.
* src/mail.h: Update accordingly.
* src/mailitem-events.cpp (Write): Pass if mail is about to
be moved.
* src/oomhelp.h (IID_FolderEvents): New.

While the application has the item copy events the folder
has a before item move event. To catch this we register an
event handler for each folder in which a mail was decrypted.
If a crypto mail is then about to be moved we close it with
discard changes to discard the plaintext, then we pass
the write event to allow the move.

Works flawlessly in the first tests.

GnuPG-Bug-Id: T3459
GnuPG-Bug-Id: T3956
GnuPG-Bug-Id: T3418

17 months agoEnable auto-key-retrieve if autoresolve is set
Andre Heinecke [Tue, 26 Jun 2018 12:46:49 +0000 (14:46 +0200)]
Enable auto-key-retrieve if autoresolve is set

* src/parsecontroller.cpp (ParseController::parse): Enable
auto-key-retrieve if autoresolve is set to true.

With autoresolve we do network lookups already so it makes
sense to reuse the option here.

17 months agoFix bring to foreground logic
Andre Heinecke [Tue, 26 Jun 2018 12:43:10 +0000 (14:43 +0200)]
Fix bring to foreground logic

* src/mail.cpp (do_crypt): Bring to foreground with delay.
* src/windowmessages.cpp (gpgol_window_proc): Don't sleep in the
UI thread.

Sleeping in the UI thread to wait for the UI thread to do something
(close a window) was stupid.

GnuPG-Bug-Id: T3771

17 months agoAdd i18n noops for config dialog
Andre Heinecke [Tue, 26 Jun 2018 11:03:03 +0000 (13:03 +0200)]
Add i18n noops for config dialog

* src/addin-options.cpp (i18n_noops): New. Strings to be used
from the config dialog.

17 months agoImprove state handling of WKS Mails
Andre Heinecke [Tue, 26 Jun 2018 09:17:24 +0000 (11:17 +0200)]
Improve state handling of WKS Mails

* src/wks-helper.cpp: Add new PublishInProgress state. This
avoids the possibility of multiple notifications due to the
late advancement out of the needspublish state.

17 months agoMinor improvement to german string
Andre Heinecke [Tue, 26 Jun 2018 09:17:00 +0000 (11:17 +0200)]
Minor improvement to german string


17 months agoIgnore propchanges on custom mails
Andre Heinecke [Tue, 26 Jun 2018 09:15:28 +0000 (11:15 +0200)]
Ignore propchanges on custom mails

* src/mail.h (Mail::hasOverrideMimeData): New.
* src/mailitem-events.cpp (PropertyChange): Ignore changes
for mails with override mime data.
* src/wks-helper.cpp (WKSHelper::send_mail): Set override
MIME data earlier.

This removes auto key locates for our custom WKS Mails.

17 months agoImprove handling of UID origin
Andre Heinecke [Tue, 26 Jun 2018 09:05:34 +0000 (11:05 +0200)]
Improve handling of UID origin

* src/mail.cpp (Mail::getCryptoDetails_o, Mail::updateSigstate):
Treat WKD origin as "shortcut to level 2.

As described on we
treat WKD already as a shortcut to level 2 as we have an
HTTPS secure indication from the provider that the key matches
the mail address.

This sets the green bar "verified sender" already for such mails,
because the senders address was verified through the provider.

To protect against phishing attacks this does not help but for
these Level 3 and 4 are required.

17 months agoFix potential crash in do autosecure
Andre Heinecke [Tue, 26 Jun 2018 09:03:18 +0000 (11:03 +0200)]
Fix potential crash in do autosecure

* src/mail.cpp (Mail::setDoAutosecure_m): Return if msg
is not found.

This happens for example if we programatically created a
mail and then set the "to"

17 months agoFix passing std::string to asprintf
Andre Heinecke [Fri, 22 Jun 2018 15:27:33 +0000 (17:27 +0200)]
Fix passing std::string to asprintf

* src/wks-helper.cpp (WKSHelper::notifiy): Fix asprintf call.



17 months agoEnable async crypto again (for now)
Andre Heinecke [Fri, 22 Jun 2018 15:10:32 +0000 (17:10 +0200)]
Enable async crypto again (for now)

* src/mail.cpp (DO_ASYNC_CRYPTO): Define.

This works soo much better. But I still have not figured out
why it crashes reliably for some users. :-/

17 months agoNote mbox in WKS message
Andre Heinecke [Fri, 22 Jun 2018 15:09:27 +0000 (17:09 +0200)]
Note mbox in WKS message

* src/wks-helper.cpp (WKSHelper::notify): Note for which
mbox the message applies.

With multiple accounts this can otherwise be confusing. We
also avoid the word "domain" which is too technical for most.

17 months agoTake language from Outlook instead of the system
Andre Heinecke [Fri, 22 Jun 2018 15:06:21 +0000 (17:06 +0200)]
Take language from Outlook instead of the system

* src/oomhelp.cpp (invoke_oom_method_with_parms_type): New.
Helper to allow invokes with a custom type.
(invoke_oom_method_with_parms): Use it.
(get_ol_ui_language): New. Read out the UI language of outlook.
* src/w32-gettext.c (_nl_locale_name): Use it.
* src/oomhelp.h: Update accordingly.

It makes sense to use the same language as outlook does. Users
will find anything else confusing and broken.

This also makes it easier to switch languages for screenshots :-P

17 months agoRemove code about compat flags
Andre Heinecke [Fri, 22 Jun 2018 15:05:19 +0000 (17:05 +0200)]
Remove code about compat flags

* src/main.c (read_options): Remove compat flags handling.

This was no longer used and contained the only i18n call
before the "OnStartupComplete" callback.

17 months agoMove i18n_init after the addin connecction
Andre Heinecke [Fri, 22 Jun 2018 15:03:08 +0000 (17:03 +0200)]
Move i18n_init after the addin connecction

* src/common.h (i18n_init): Expose.
* src/main.c (DllMain): Don't init here.
(i18n_init): No longer static.
* src/gpgoladdin.cpp (GpgolAddin::OnStartupComplete): Call it.

This ensures that the Application object is accessible when
initializing i18n.

17 months agoFix WKS when async enc is disabled
Andre Heinecke [Fri, 22 Jun 2018 13:19:34 +0000 (15:19 +0200)]
Fix WKS when async enc is disabled

* src/mailitem-events.cpp (Send): Allow notify after the
* src/windowmessages.cpp (CRYPTO_DONE): Don't do allow notify here.

17 months agoMore cleanup and convetional naming
Andre Heinecke [Fri, 22 Jun 2018 12:46:04 +0000 (14:46 +0200)]
More cleanup and convetional naming


17 months agoUse convention for MAPI/OOM active functs
Andre Heinecke [Thu, 21 Jun 2018 14:31:57 +0000 (16:31 +0200)]
Use convention for MAPI/OOM active functs

This should make it easier to see if a function accesses
MAPI or OOM somewhere internally. For now this is only
done for our main Mail class.

17 months agoConstify some calls
Andre Heinecke [Thu, 21 Jun 2018 12:34:21 +0000 (14:34 +0200)]
Constify some calls


17 months agoIntroduce naming conventions
Andre Heinecke [Thu, 21 Jun 2018 12:28:26 +0000 (14:28 +0200)]
Introduce naming conventions

* src/mail.h: Add comment explaining naming convetions and
explain window message and OOM interaction.

17 months agoSet UUID when auto toggling secure
Andre Heinecke [Thu, 21 Jun 2018 11:11:11 +0000 (13:11 +0200)]
Set UUID when auto toggling secure

* src/mail.cpp (Mail::set_do_autosecure_mapi): set uuid.

Setting the UUID is neccessary to find the Mail object from
the toggle button to mark that the state was manually set.

GnuPG-Bug-Id: T3999

17 months agoFix flicker when locate threads are running
Andre Heinecke [Thu, 21 Jun 2018 11:10:40 +0000 (13:10 +0200)]
Fix flicker when locate threads are running

* src/mail.cpp (Mail::autoresolve_s): Check locate thread count.
GnuPG-Bug-Id: T3999

17 months agoSimplify isMailResolvable and accept keygen
Andre Heinecke [Thu, 21 Jun 2018 09:22:47 +0000 (11:22 +0200)]
Simplify isMailResolvable and accept keygen

* src/keycache.cpp (isMailResolvable): Return bool. Accept
potential keygen.
* src/keycache.h: Update accordingly.
* src/mail.cpp (Mail::autoresolve_check_s): Update for new API.

This inly check for a self key for SMIME. For OpenPGP we can
generate a key.

GnuPG-Bug-Id: T3999

17 months agoImplement auto secure feature
Andre Heinecke [Thu, 21 Jun 2018 08:40:39 +0000 (10:40 +0200)]
Implement auto secure feature

* src/common_indep.h (opt): Add autosecure.
* src/cryptcontroller.cpp (CryptController::CryptController): Adopt
new API.
* src/keycache.cpp (do_locate, do_locate_secret): Fix broken handling
of args.
(locate_secret): Add check for empty mbox. Otherwise it could
select the first secret key if the sender address could not be
(KeyCache::startLocate): Take recipients as vector.
(KeyCache::isMailResolvable): New. Check if all keys are found
in the cache.
* src/keycache.h: Update accordingly.
* src/mail.cpp (m_cached_recipients): Use a vector instead of
a carray.
(m_first_autoresolve_check): Track state of autoresolve.
(Mail::~Mail): No need to free cached recipients.
(Mail::update_oom_data): Use vector for cached recipients.
(Mail::locate_keys): Adapt to new recipients API. Do
(Mail::take_cached_recipients): Removed.
(Mail::get_cached_recipents): New. Get a copy of the recipients.
(Mail::decrement_locate_count): Trigger autoresolve check.
(Mail::autoresolve_check_s): New. Check if mail is resolvable.
* src/mail.h: Update accordingly.
* src/mailitem-events.cpp (RecipientAdded): Handle opt.autosecure.
* src/main.c (read_options): Read autosecure.
* src/ribbon-callbacks.cpp (mark_mime_action): Use more modern
style. Mark if crypto state was set manually.
* src/windowmessages.cpp (DO_AUTO_SECURE, DONT_AUTO_SECURE): New
messages to set state.

This is a first implementation of opportunistic encryption
in GpgOL. If we have enough keys with marginal validity
or if the keys come from WKD we can select "secure" automatically.

GnuPG-Bug-Id: T3999

17 months agoHandle always sign/encrypt for inline reply/fw
Andre Heinecke [Wed, 20 Jun 2018 12:58:16 +0000 (14:58 +0200)]
Handle always sign/encrypt for inline reply/fw

* src/mailitem-events.cpp (reply, forward, replyall): Handle
the always sign/encrypt options.

If the option reply_crypt is set and the reply is to
a crypto mail the settings from that mail will override
the always options.

Previously this only worked in the Open command so only
if a new message composer window was opened.

This fixes a problem noticed in:
GnuPG-Bug-Id: T4037

17 months agoAdd clarifying comment about forward reply detect
Andre Heinecke [Wed, 20 Jun 2018 12:21:02 +0000 (14:21 +0200)]
Add clarifying comment about forward reply detect

I just looked at it and at first could not remember why
I didn't just use the pdispVal.

17 months agoPrepare keycache for autoencryption
Andre Heinecke [Wed, 20 Jun 2018 11:56:19 +0000 (13:56 +0200)]
Prepare keycache for autoencryption

* src/keycache.cpp,
* src/mail.cpp, src/mail.h (set_crypto_selected_manually),
(increment_locate_count, decrement_locate_count): New stateholders.
* src/keycache.cpp (LocateArgs): Argument helper to carry mail.
(startLocate, startLocateSecret): Add mail argument and use it.
* src/keycache.h: Update accordingly.

This keeps track of how many locate threads are running
on a mail. So that we can handle the state where
all locates for a mail are done.

This prepares:
GnuPG-Bug-Id: T3999