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

abi <abi/3.0>,

include <tunables/global>

@{exec_path} = @{bin}/claws-mail
profile claws-mail @{exec_path} flags=(complain) {
  include <abstractions/base>
  include <abstractions/audio-client>
  include <abstractions/enchant>
  include <abstractions/fontconfig-cache-read>
  include <abstractions/fonts>
  include <abstractions/freedesktop.org>
  include <abstractions/gtk>
  include <abstractions/nameservice-strict>
  include <abstractions/ssl_certs>
  include <abstractions/thumbnails-cache-read>
  include <abstractions/user-download-strict>

  @{exec_path} mr,

  @{sh_path}        rix,
  @{bin}/which{,.debianutils}      rix,

  @{bin}/gpg{,2}    rCx -> gpg,
  @{bin}/gpgsm      rCx -> gpg,
  @{bin}/gpgconf    rCx -> gpg,

  @{bin}/orage      rPUx,
  @{bin}/exim4  rPUx,
  @{bin}/geany      rPUx,

  /usr/share/publicsuffix/*.dafsa r,

  /etc/fstab r,
  /etc/machine-id r,
  /var/lib/dbus/machine-id r,

  owner /var/mail/* rwk,

  owner @{HOME}/ r,
  owner @{HOME}/.claws-mail/ rw,
  owner @{HOME}/.claws-mail/** rwl -> @{HOME}/.claws-mail/**,
  owner @{user_mail_dirs}/ rw,
  owner @{user_mail_dirs}/** rwl -> @{user_mail_dirs}/**,

  owner @{tmp}/claws-mail-@{int}/ rw,
  owner @{tmp}/claws-mail-@{int}/@{hex} rw,
  owner @{tmp}/claws-mail-@{int}/@{hex}.lock rwk,

  owner @{PROC}/@{pid}/fd/ r,
  owner @{PROC}/@{pid}/mountinfo r,
  owner @{PROC}/@{pid}/mounts r,

  profile gpg {
    include <abstractions/base>

    @{bin}/gpg{,2} mr,
    @{bin}/gpgsm mr,
    @{bin}/gpgconf mr,

    owner @{HOME}/@{XDG_GPG_DIR}/ rw,
    owner @{HOME}/@{XDG_GPG_DIR}/** rwkl -> @{HOME}/@{XDG_GPG_DIR}/**,

  }

  include if exists <local/claws-mail>
}

# vim:syntax=apparmor
