# apparmor.d - Full set of apparmor profiles
# Copyright (C) 2015-2021 Mikhail Morfikov
# Copyright (C) 2021-2024 Alexandre Pujol <alexandre@pujol.io>
# SPDX-License-Identifier: GPL-2.0-only

abi <abi/4.0>,

include <tunables/global>

@{name} = thunderbird{,-bin}
@{lib_dirs} = @{lib}/@{name}
@{config_dirs} = @{HOME}/.@{name}/
@{cache_dirs} = @{user_cache_dirs}/@{name}/

@{exec_path} = @{bin}/@{name} @{lib_dirs}/@{name}
profile thunderbird @{exec_path} {
  include <abstractions/base>
  include <abstractions/app/firefox>
  include <abstractions/user-download-strict>
  include <abstractions/user-read-strict>

  #aa:dbus own bus=session name=org.mozilla.thunderbird

  @{exec_path} mrix,

  @{lib_dirs}/glxtest    rPx,
  @{lib_dirs}/vaapitest  rPx,

  @{lib}/@{multiarch}/qt5/plugins/kf5/org.kde.kwindowsystem.platforms/KF5WindowSystemKWaylandPlugin.so mr,
  @{lib}/@{multiarch}/qt5/plugins/kf5/org.kde.kwindowsystem.platforms/KF5WindowSystemX11Plugin.so mr,

  # GPG integration
  @{bin}/gpg{,2}     rPx,
  @{bin}/gpgconf     rPx,
  @{bin}/gpgsm       rPx,

  # Desktop integration
  @{open_path}       rPx -> child-open,

  /usr/share/lightning/{,**} r,

  owner /var/mail/** rwk,

  owner @{user_mail_dirs}/ rw,
  owner @{user_mail_dirs}/** rwl -> @{user_mail_dirs}/**,

  owner @{user_config_dirs}/gtk-{3,4}.0/assets/*.svg r,
  owner @{user_config_dirs}/ibus/bus/ r,
  owner @{user_config_dirs}/ibus/bus/@{hex32}-unix-{,wayland-}@{int} r,
  owner @{user_config_dirs}/kioslaverc r,
  owner @{user_config_dirs}/mimeapps.list{,.@{rand6}} rw,

  owner @{tmp}/MozillaMailnews/ rw,
  owner @{tmp}/MozillaMailnews/*.msf rw,
  owner @{tmp}/nscopy.tmp rw,
  owner @{tmp}/nsemail{,-@{int}}.eml rw,
  owner @{tmp}/nsma{,-@{int}} rw,
  owner @{tmp}/pid-@{pid}/{,**} w,

  /dev/urandom w,

  # Silencer
  deny capability sys_ptrace,
  deny @{lib_dirs}/** w,
  deny @{lib_dirs}/crashreporter x,
  deny @{lib_dirs}/minidump-analyzer x,
  deny @{HOME}/.mozilla/** mrwkl,

  include if exists <local/thunderbird>
}

# vim:syntax=apparmor
