36 hours agoOnly shutdown for the last explorer close master
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.

36 hours 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.

36 hours 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.

36 hours 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.

36 hours 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.

36 hours 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.

2 days 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.

2 days 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.

2 days 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.

2 days 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.

2 days 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.

8 days 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.

8 days 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.

8 days 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.

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


8 days 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

8 days 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

8 days 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

9 days 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.

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


9 days 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

9 days 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.

9 days 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

9 days 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

9 days 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.

10 days 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.

10 days 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

10 days 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

10 days 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

10 days 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.

10 days 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.

13 days 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

13 days 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.

13 days 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.

2 weeks 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.

2 weeks 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

3 weeks 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

3 weeks 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.

3 weeks 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

3 weeks 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.

3 weeks 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.

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


3 weeks 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.

3 weeks 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.

3 weeks 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"

3 weeks 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.



3 weeks 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. :-/

3 weeks 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.

3 weeks 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

3 weeks 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.

3 weeks 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.

3 weeks 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.

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


4 weeks 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.

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


4 weeks 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.

4 weeks 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

4 weeks 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

4 weeks 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

4 weeks 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

4 weeks 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

4 weeks 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.

4 weeks 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

4 weeks agoLocks and more locks
Andre Heinecke [Wed, 20 Jun 2018 11:33:28 +0000 (13:33 +0200)]
Locks and more locks

* src/mail.cpp (mail_map_lock, uid_map_lock): New locks.
(Mail::Mail, Mail::~Mail, Mail::get_mail_for_item),
(Mail::get_mail_for_uuid, Mail::is_valid_ptr),
(Mail::close_all_mails, Mail::revert_all_mails),
(Mail::revert_all_mails, Mail::wipe_all_mails),
(Mail::set_uuid, Mail::locate_all_crypto_recipients)
(Mail::delete_lock, Mail::delete_unlock): New helpers to
ensure a mail pointer stays valid.
* src/mail.h: Update accordingly.

As the mail object is used from more and more threads
and will soon be used even more for autoencryption
we have to be _very_ careful to minimize / remove race
conditions which could lead to a crash.
For autoencryption we will have async code working
on every new mail.

GnuPG-Bug-Id: T3999

4 weeks agoCppinize keycache a bit more
Andre Heinecke [Tue, 19 Jun 2018 13:36:39 +0000 (15:36 +0200)]
Cppinize keycache a bit more

* src/keycache.cpp (setSmimeKeySecret, setSmimeKey, setPgpKey),
(setPgpKeySecret): Use std::string.
(do_locate, locate_secret): Smart pointer for ctx.
std::string for addr.
* src/keycache.h: Update accordingly.

This avoids free / delete errors and here also reduces
std::string allocations.

4 weeks agoFix crash when adding attachment without fileext
Andre Heinecke [Tue, 19 Jun 2018 07:29:11 +0000 (09:29 +0200)]
Fix crash when adding attachment without fileext

* src/mimemaker.cpp (infer_content_type): Check if a suffix
was found and check for the size of the suffix before using it.

The crash was introduced with 94c354a0

GnuPG-Bug-Id: T4032

4 weeks agoPost release version bump
Andre Heinecke [Sun, 17 Jun 2018 10:13:37 +0000 (12:13 +0200)]
Post release version bump


4 weeks agoUpdate NEWS for todays release gpgol-2.2.0
Andre Heinecke [Sun, 17 Jun 2018 10:08:08 +0000 (12:08 +0200)]
Update NEWS for todays release


4 weeks agopo: Update formatting of pt/de
Andre Heinecke [Fri, 15 Jun 2018 06:38:01 +0000 (08:38 +0200)]
po: Update formatting of pt/de

* po/de.po, po/pt.po: Update formatting.

4 weeks agoAdd ukrainian translation
Andre Heinecke [Fri, 15 Jun 2018 06:36:33 +0000 (08:36 +0200)]
Add ukrainian translation

* po/uk.po: New.
* po/LINGUAS: Add it.

Translation provided by Yuri Chornoivan. Thanks!

5 weeks agoUpdate Dutch translation.
Erwin Bronkhorst [Sun, 3 Jun 2018 22:44:09 +0000 (00:44 +0200)]
Update Dutch translation.

5 weeks agopo: Update portugese translation
Andre Heinecke [Tue, 12 Jun 2018 12:14:49 +0000 (14:14 +0200)]
po: Update portugese translation

* po/pt.po: Update translations.

Translations provided by Marco A.G. Pinto. Thanks!

5 weeks agopo: Update german translation
Andre Heinecke [Tue, 12 Jun 2018 11:40:43 +0000 (13:40 +0200)]
po: Update german translation


5 weeks agoAuto update po files
Andre Heinecke [Tue, 12 Jun 2018 09:17:16 +0000 (11:17 +0200)]
Auto update po files

* po: Update.

5 weeks agoRemove engine.c from potfiles
Andre Heinecke [Tue, 12 Jun 2018 09:16:53 +0000 (11:16 +0200)]
Remove engine.c from potfiles

* po/ No more engine.c

5 weeks agoRemove removed bitmaps from extra dist
Andre Heinecke [Tue, 12 Jun 2018 09:15:45 +0000 (11:15 +0200)]
Remove removed bitmaps from extra dist

* src/icons/ Update EXTRA_DIST.

The Icons were required for Outlook < 2010

5 weeks agoClean reply / forwards of unsigned S/MIME Mails
Andre Heinecke [Mon, 11 Jun 2018 16:19:48 +0000 (18:19 +0200)]
Clean reply / forwards of unsigned S/MIME Mails

* src/mailitem-events.cpp (EVENT_SINK_INVOKE): Improve
reply / forward handling and check for HTML Blocked Mails to
clean them.
* src/windowmessages.cpp, src/windowmessages.h
(do_in_ui_thread_async): Extend to take delay as opt. param.
(gpgol_window_proc): Handle it.

This is ugly ugly ugly. As we don't have a reliable
way to detect when a reply / forward is filled with data
we just wait a second before wiping the reply if necessary.

The change in the write event to not invalidate the
last mail also poses a regression risk.

GnuPG-Bug-Id: T3986

5 weeks agoExtend mail class for better reply/forward handling
Andre Heinecke [Mon, 11 Jun 2018 16:17:03 +0000 (18:17 +0200)]
Extend mail class for better reply/forward handling

* src/mail.cpp, src/mail.h (Mail::set_is_reply_crypto_mail),
(Maill::is_reply_crypto_mail, m_is_reply_crypto_mail): New flag for
(Mail::remove_all_attachements): New helper.
(Mail::is_block_html): Expose the flag.

This helps with:
GnuPG-Bug-Id: T3986

5 weeks agoImprove unsigned S/MIME HTML handling
Andre Heinecke [Mon, 11 Jun 2018 16:15:14 +0000 (18:15 +0200)]
Improve unsigned S/MIME HTML handling

* src/mail.cpp (update_body): Improve handling and messages.

GnuPG-Bug-Id: T3986

5 weeks agoCleanup unused options and add a warning shown opt
Andre Heinecke [Mon, 11 Jun 2018 16:12:17 +0000 (18:12 +0200)]
Cleanup unused options and add a warning shown opt

* src/common_indep.h: Update option struct.
* src/main.c (init_options): Removed.
(write_options, read_options): Update accordingly.
* src/mapihelp.cpp (mapi_get_gpgol_body_attachment): Remove
obsolete handling to show body as attachment.

This removes obsolete OL < 2010 Options and adds a new
smime_html_warn_shown flag.

6 weeks agoClarify comment about inline pgp encoding
Andre Heinecke [Fri, 1 Jun 2018 13:00:14 +0000 (15:00 +0200)]
Clarify comment about inline pgp encoding

* src/parsecontroller.cpp (ParseController::parse): Improve

6 weeks agoAdd distinct error for legacy nomdc
Andre Heinecke [Fri, 1 Jun 2018 12:59:25 +0000 (14:59 +0200)]
Add distinct error for legacy nomdc

* src/parsecontroller.cpp (format_error): Check for

GnuPG-Bug-Id: T3714

6 weeks agoTry to convert clearsigned to utf8 on verify fail
Andre Heinecke [Fri, 1 Jun 2018 12:09:07 +0000 (14:09 +0200)]
Try to convert clearsigned to utf8 on verify fail

* src/parsecontroller.cpp (ParseController::parse): Try again
with UTF-8 if verify opaque failed.

We have a bit of a problem in that we access the body
through the 8 bit interface and we need to give it
to GnuPG as 8 bit.

We now try utf8 if the native encoding did not
give us a result. It's a bit of a hack but will
work for messages from gpgol to gpgol and hopefully
for some others, too.

GnuPG-Bug-Id: T3962

6 weeks agoProperly set UTF8 encoding for clearsigned
Andre Heinecke [Fri, 1 Jun 2018 12:07:10 +0000 (14:07 +0200)]
Properly set UTF8 encoding for clearsigned

* src/cryptcontroller.cpp(CryptController::update_mail_mapi):
* src/mail.cpp (Mail::update_body): Fix charset variable.
(Mail::inline_body_to_body): Also set CPID in OOM.
* src/mymapitags.h: Define PR_INTERNET_CPID.


GnuPG-Bug-Id: T3962

6 weeks agoFix encoding for some inline pgp mails
Andre Heinecke [Fri, 1 Jun 2018 09:30:18 +0000 (11:30 +0200)]
Fix encoding for some inline pgp mails

* src/mail.cpp (Mail::update_body): Use InternetCodepage if
charset is not set by the parser.
* src/mlang-charset.cpp (ansi_charset_to_utf8): Add handling
for a directly provided codepage.
* src/rfc2047parse.c (rfc2047_decode_tokens): Update caller.

For PGP Inline the charset is not detected by the parsecontroller
in that case we now just use the InternetCodepage from OOM.
Tests show that this works properly.

GnuPG-Bug-Id: T3962

6 weeks agoShow error status on syserror verify
Andre Heinecke [Fri, 1 Jun 2018 08:11:44 +0000 (10:11 +0200)]
Show error status on syserror verify

* src/mail.cpp (Mail::get_crypto_details): Show error.

This helps with diagnostics. E.g. and ed25519 signature
in vs-nfd mode leads to a sys error with status
Invalid pubkey algorithm.

6 weeks agoBlock HTML for unsigned S/MIME messages
Andre Heinecke [Fri, 1 Jun 2018 08:06:18 +0000 (10:06 +0200)]
Block HTML for unsigned S/MIME messages

* src/mail.cpp (Mail::set_block_status): New. Sets a MAPI prop
to disable automatic HTML external references.
(Mail::set_block_html): New. HTML content should be blocked.
(Mail::parsing_done): check for block html.
(Mail::update_body): Block HTML if necessary.
* src/parsecontroller.cpp (ParseController::shouldBlockHtml): New.
(is_valid_chksum): Check that the sig is valid even if it is
* src/mymapitags.h (PR_BLOCK_STATUS): New.
* src/oomhelp.h (PR_BLOCK_STATUS_DASL): New.

This blocks HTML display in unsigned S/MIME Mails to avoid
attacks that rely on HTML side channels. If there is
no text/plain part it will show the unparsed HTML. Trying
to parse it with Outlook and then inserting at as plain text
left the references intact and appears to be too risky.

GnuPG-Bug-Id: T3986

2 months agoRemove unused engine based code
Andre Heinecke [Thu, 17 May 2018 09:01:16 +0000 (11:01 +0200)]
Remove unused engine based code

* src/gpgoladdin.cpp (getCustomUI_MIME): Remove attachment
decrypt context menu. This should be handled by windows file
registry now.

This removes the decryptattachment callback which was the last
engine based callback and the now unused crypto functions
from mimemaker.

2 months agoRemove GpgOLStr class
Andre Heinecke [Thu, 17 May 2018 07:53:28 +0000 (09:53 +0200)]
Remove GpgOLStr class

This was more of a failed experiment and is mostly uneccesary.

2 months agoRemove no MIME UI
Andre Heinecke [Thu, 17 May 2018 07:23:16 +0000 (09:23 +0200)]
Remove no MIME UI

This should reduce the amount of strings to translate and
also reduce the code lying around.

2 months agoRemove unused bitmap icons
Andre Heinecke [Thu, 17 May 2018 07:08:56 +0000 (09:08 +0200)]
Remove unused bitmap icons

* dialogs.h, dialogs.rc: Update accordingly.

2 months agoCleanup gpgol_Sources
Andre Heinecke [Thu, 17 May 2018 06:59:19 +0000 (08:59 +0200)]
Cleanup gpgol_Sources

* src/ (gpgol_SOURCES): Cleanup / sort.

2 months agoRemove additional OL2007 files
Andre Heinecke [Thu, 17 May 2018 06:58:59 +0000 (08:58 +0200)]
Remove additional OL2007 files


2 months agoRemove files for Outlook 2007 / 2003 support
Andre Heinecke [Wed, 16 May 2018 15:11:35 +0000 (17:11 +0200)]
Remove files for Outlook 2007 / 2003 support

This has been long overdue. Outlook 2007 is no longer supported
by Microsoft for over a year now. Outlook 2003 is well,..

This still leaves a lot of unused code that has to be cleaned
up but it removes all the files that are no longer needed.

GnuPG-Bug-Id: T3984

2 months agoRemove obsolete patch file. outlook-2007-removal
Andre Heinecke [Wed, 16 May 2018 14:16:46 +0000 (16:16 +0200)]
Remove obsolete patch file.

* gpgol-assuan-abi-2.patch: Remove.

2 months agoAdd Dutch translation
Erwin Bronkhorst [Mon, 14 May 2018 20:38:17 +0000 (22:38 +0200)]
Add Dutch translation

* Bump required GPGME version.
* po/LINUGUAS: Add dutch.
* po/nl.po: New.
* po/po/fr.po: Remove spurious file.

(cherry picked from commit 64f0522227fa50a11e44e07d4b07cbef9fb8c126)

Commit message amended and:
Signed-off-by: Andre Heinecke <>
2 months agoStop prasing on non whitepspace before PGP Message
Andre Heinecke [Fri, 11 May 2018 07:05:09 +0000 (09:05 +0200)]
Stop prasing on non whitepspace before PGP Message

* src/mapihelp.cpp (get_msgcls_from_pgp_lines): Again break
on non whitespace before message marker.

The problem here is that for inline messages a full quote in
the response could cause GpgOL to use the full quote as the
message instead of the reply. Outlook itself formats
its quotes in a way that would cause this.

While this might break again MTA's which insert stuff above
a Message we have to do this.

GnuPG-Bug-Id: T3964

2 months agoFix crash when looking at msgs without content type
Andre Heinecke [Fri, 4 May 2018 07:23:38 +0000 (09:23 +0200)]
Fix crash when looking at msgs without content type

* src/mapihelp.cpp (change_message_class_ipm_note): Check
for ct before using it in string comparison.

The codepath is reached for temporary, discarded mails, e.g.
when a Reply All in the Inline editor is canceled through

This fixes: dc48589b3d429d7d156c75b4e7bc784b140f40ce
GnuPG-Bug-Id: T3960

2 months agoLaunch Kleopatra config dialog with parent
Andre Heinecke [Mon, 30 Apr 2018 09:44:54 +0000 (11:44 +0200)]
Launch Kleopatra config dialog with parent

* src/addin-options.cpp (launch_kleo_config): New.
(options_window_proc): Use it.

This fixes that the config dialog might be opened in the
background, or that the assuan communication fails.

GnuPG-Bug-Id: T3946

2 months agopo: Translate print decrypted in pt
Andre Heinecke [Fri, 27 Apr 2018 07:40:31 +0000 (09:40 +0200)]
po: Translate print decrypted in pt

* po/pt.po: Add a translation.