%global     commit     d576a6ba7aac36506bae61dd8c54ea82ee3d9bf3
%global     githash    %(c=%{commit}; echo ${c:0:7})
%global     gitdate    20180601
%global     gittime    1925

Name:           mailnag
Version:        1.3.0
Release:        1.%{gitdate}%{gittime}git%{githash}%{?dist}
Summary:        Mail notification daemon

License:        GPLv2
URL:            https://github.com/pulb/%{name}
Source:         https://github.com/pulb/%{name}/archive/%{commit}/%{name}-v%{version}-%{githash}.tar.gz

# python3 won't work (as of 0.4.2)
Requires:       python2
Requires:       pygobject2
Requires:       gstreamer1-python
Requires:       notify-python
Requires:       pyxdg
Requires:       gnome-keyring

BuildArch:      noarch
BuildRequires:  pkgconfig(python-2.7)
BuildRequires:  gettext
BuildRequires:  desktop-file-utils libappstream-glib

%description
Mailnag checks POP3 and IMAP servers for new mail and when it finds one
creates a proper GNOME 3 notification that mentions sender and subject.


%prep
%setup -q -n %{name}-%{commit}

# avoid rpmlint error wrong-script-end-of-line-encoding for these files
sed -i -e 's/\r//' Mailnag/{common/config,configuration/accountdialog,configuration/plugindialog}.py

# sooner or later python3 might be the default in Fedora; be prepared
sed -i 's_#!.*/usr/bin/env.*python_#!%{_bindir}/env python2_' $(find . -name '*.py')

%build
CFLAGS="$RPM_OPT_FLAGS" %{__python2} setup.py build

%install
rm -rf %{buildroot}
%{__python2} setup.py install --skip-build --root $RPM_BUILD_ROOT
desktop-file-validate $RPM_BUILD_ROOT/%{_datadir}/applications/mailnag-config.desktop
appstream-util validate-relax --nonet %{buildroot}/%{_datadir}/appdata/*.appdata.xml

%find_lang %{name}


%post
%{_bindir}/touch --no-create %{_datadir}/icons/hicolor &>/dev/null || :

%postun
if [ $1 -eq 0 ] ; then
    %{_bindir}/touch --no-create %{_datadir}/icons/hicolor &>/dev/null
    %{_bindir}/gtk-update-icon-cache -f %{_datadir}/icons/hicolor &>/dev/null || :
fi

%posttrans
%{_bindir}/gtk-update-icon-cache -f %{_datadir}/icons/hicolor &>/dev/null || :


%files -f %{name}.lang
%license LICENSE
%doc AUTHORS NEWS README.md
%{_bindir}/%{name}*
%{_datadir}/%{name}
%{python2_sitelib}/Mailnag
%{python2_sitelib}/%{name}-%{version}-*.egg-info
%{_datadir}/applications/*
%{_datadir}/icons/hicolor/*/apps/%{name}*png
%{_datadir}/appdata/mailnag.appdata.xml

%changelog
* Sun Jun 29 2014 Thorsten Leemhuis <fedora@leemhuis.info> - 1.0.0-1
- update to 1.0.0
- drop patches

* Sat Jun 07 2014 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 0.5.2-5
- Rebuilt for https://fedoraproject.org/wiki/Fedora_21_Mass_Rebuild

* Wed Nov 06 2013 Thorsten Leemhuis <fedora@leemhuis.info> - 0.5.2-4
- add patch to fix sound problem (rhbz #1015900 comment 4)

* Sun Nov 03 2013 Thorsten Leemhuis <fedora@leemhuis.info> - 0.5.2-3
- add patch to work around a API change in NotifyNotification (rhbz #1015900)

* Sat Aug 03 2013 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 0.5.2-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_20_Mass_Rebuild

* Sun Nov 25 2012 Thorsten Leemhuis <fedora@leemhuis.info> - 0.5.2-1
- update to 0.5.2

* Sun Nov 25 2012 Thorsten Leemhuis <fedora@leemhuis.info> - 0.4.4-1
- update to 0.4.4

* Sun Oct 07 2012 Thorsten Leemhuis <fedora@leemhuis.info> - 0.4.3-1
- update to 0.4.3
- use the newly added setup.py for install, which simplifies the spec file
  a lot

* Mon Aug 13 2012 Thorsten Leemhuis <fedora@leemhuis.info> - 0.4.2-2
- apply patch that fixes a issue found during review #847512

* Sat Aug 11 2012 Thorsten Leemhuis <fedora@leemhuis.info> - 0.4.2-1
- initial build