* Re: Limiting number of Incomingxxxx mails
[not found] ` <ulm0i27hs.fsf_-_@hschmi22.userfqdn.rz-online.de>
@ 2003-02-19 21:12 ` Reiner Steib
2003-02-22 22:05 ` Lars Magne Ingebrigtsen
0 siblings, 1 reply; 12+ messages in thread
From: Reiner Steib @ 2003-02-19 21:12 UTC (permalink / raw)
[-- Attachment #1: Type: text/plain, Size: 1499 bytes --]
On Fri, Feb 14 2003, Frank Schmitt wrote:
> We have been talking in gnu.emacs.gnus about possibilities of reducing
> the amount of diskspace the Incoming* files need. Perhaps there's
> somebody who thinks our ideas are cool and wants to implement them?
>
> Reiner Steib <4.uce.03.r.s@nurfuerspam.de> writes:
[...]
>> (defcustom mail-source-delete-incoming nil
>> "*If t, delete incoming files after handling.
>> If a positive number, delete files, older than number days. If set to the
>> symbol `compress', compress the files. If it is a negative number, compress
>> the files and delete compressed files older than that number of
>> days. If nil, never delete."
I have write `mail-source-delete-old-incoming' but the function *needs
review* and testing. I haven't worked with elisp times and
file-attributes before, so my approach might be too complicated or
complete nonsense. ;-) *Feedback welcome*!
With the attached patch, old (>= 3 days) incoming files will be
deleted (after confirmation!). You may also test the function without
applying the patch[1]:
,----[ C-h f mail-source-delete-old-incoming RET ]
| mail-source-delete-old-incoming is an interactive Lisp function in `...'.
| (mail-source-delete-old-incoming &optional AGE CONFIRM)
|
| Remove incoming files older than AGE days.
| If CONFIRM is non-nil, ask for confirmation before removing a file.
`----
`M-: (mail-source-delete-old-incoming 7 t) RET'
If you set gnus-verbose to 10 you'll get lots of debugging output.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: mail-source.delete-old-incoming.01.patch --]
[-- Type: text/x-patch, Size: 3844 bytes --]
--- mail-source.el.~6.29.~ Mon Feb 17 11:37:23 2003
+++ mail-source.el Wed Feb 19 20:45:23 2003
@@ -262,8 +262,20 @@
:group 'mail-source
:type 'integer)
-(defcustom mail-source-delete-incoming nil
- "*If non-nil, delete incoming files after handling."
+(defcustom mail-source-delete-incoming 3; nil
+ "*If non-nil, delete incoming files after handling.
+If t, delete immediately, if nil, never delete. If a positive number, delete
+files older than number of days."
+ ;; Note: The removing happens in `mail-source-callback', i.e. no old
+ ;; incoming files will be deleted, unless you receive new mail.
+ ;;
+ ;; You may also set this to `t' and call `mail-source-delete-old-incoming'
+ ;; from a hook or interactively.
+ :group 'mail-source
+ :type 'integer)
+
+(defcustom mail-source-delete-old-incoming-confirm t; nil
+ "*If non-nil, ask for for confirmation before deleting old incoming files."
:group 'mail-source
:type 'boolean)
@@ -506,6 +518,44 @@
(setq newname (make-temp-name newprefix)))
newname))))
+(defun mail-source-delete-old-incoming (&optional age confirm)
+ "Remove incoming files older than AGE days.
+If CONFIRM is non-nil, ask for confirmation before removing a file."
+ (interactive "P")
+ (let ((ddays 30) ;; fallback, if no valid AGE given
+ (high2days (/ 65536.0 60 60 24));; convert high bits to days
+ (low2days (/ 1.0 65536.0)) ;; convert low bits to days
+ diff
+ files ffile bfile filetime fileday currday)
+ (setq diff (if (and (numberp age) (>= age 0))
+ age
+ ddays))
+ ;; (gnus-message 1 "Setting `confirm' to `t' (testing!)") ;; To be removed
+ ;; (setq confirm t) (sit-for 1) ;; To be removed
+ (setq
+ files (directory-files
+ mail-source-directory t
+ (concat mail-source-incoming-file-prefix "*"))
+ currday (* (car (current-time)) high2days)
+ currday (+ currday (* low2days (nth 1 (current-time)))))
+ (gnus-message 8 "diff=`%s', currday=`%s'" diff currday);; To be removed
+ (while files
+ (setq
+ ffile (car files)
+ bfile (gnus-replace-in-string ffile "\\`.*/\\([^/]+\\)\\'" "\\1")
+ filetime (nth 5 (file-attributes ffile))
+ fileday (* (car filetime) high2days)
+ fileday (+ fileday (* low2days (nth 1 filetime)))
+ files (cdr files))
+ (gnus-message 9 "File `%s', fileday=`%s', `-c f'=`%s'";; To be removed
+ bfile fileday (- currday fileday));; To be removed
+ (when (and (> (- currday fileday) diff)
+ (gnus-message 8 "File `%s' is older than %s day(s)"
+ bfile diff)
+ (or (not confirm)
+ (y-or-n-p (concat "Remove file `" bfile "'? "))))
+ (delete-file ffile)))))
+
(defun mail-source-callback (callback info)
"Call CALLBACK on the mail file, and then remove the mail file.
Pass INFO on to CALLBACK."
@@ -519,7 +569,7 @@
(funcall callback mail-source-crash-box info)
(when (file-exists-p mail-source-crash-box)
;; Delete or move the incoming mail out of the way.
- (if mail-source-delete-incoming
+ (if (eq mail-source-delete-incoming t)
(delete-file mail-source-crash-box)
(let ((incoming
(mail-source-make-complex-temp-name
@@ -528,8 +578,14 @@
mail-source-directory))))
(unless (file-exists-p (file-name-directory incoming))
(make-directory (file-name-directory incoming) t))
- (rename-file mail-source-crash-box incoming t)))))))
-
+ (rename-file mail-source-crash-box incoming t)
+ ;; remove old incoming files?
+ (when (and (numberp mail-source-delete-incoming)
+ (>= mail-source-delete-incoming 0))
+ (mail-source-delete-old-incoming
+ mail-source-delete-incoming
+ mail-source-delete-old-incoming-confirm))))))))
+
(defun mail-source-movemail (from to)
"Move FROM to TO using movemail."
(if (not (file-writable-p to))
[-- Attachment #3: Type: text/plain, Size: 236 bytes --]
Bye, Reiner.
[1] Extract `(defun mail-source-delete-old-incoming ...)' from the
patch, remove the leading "+"-sign and eval it.
--
,,,
(o o)
---ooO-(_)-Ooo--- PGP key available via WWW http://rsteib.home.pages.de/
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Limiting number of Incomingxxxx mails
2003-02-19 21:12 ` Limiting number of Incomingxxxx mails Reiner Steib
@ 2003-02-22 22:05 ` Lars Magne Ingebrigtsen
2003-02-24 20:25 ` Reiner Steib
0 siblings, 1 reply; 12+ messages in thread
From: Lars Magne Ingebrigtsen @ 2003-02-22 22:05 UTC (permalink / raw)
Reiner Steib <4.uce.03.r.s@nurfuerspam.de> writes:
> I have write `mail-source-delete-old-incoming' but the function *needs
> review* and testing.
I'm not quite sure that such a function is a good idea. The
Incoming* files are created only by pretest Gnusae, so they should
only be produced by versions of Gnus that are dangerous, mail-wise
speaking. Having mechanisms for automatically deleting stuff in such
a situation might be counterproductive.
--
(domestic pets only, the antidote for overdose, milk.)
larsi@gnus.org * Lars Magne Ingebrigtsen
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Limiting number of Incomingxxxx mails
2003-02-22 22:05 ` Lars Magne Ingebrigtsen
@ 2003-02-24 20:25 ` Reiner Steib
2003-03-03 16:00 ` Ted Zlatanov
` (2 more replies)
0 siblings, 3 replies; 12+ messages in thread
From: Reiner Steib @ 2003-02-24 20:25 UTC (permalink / raw)
[-- Attachment #1: Type: text/plain, Size: 1701 bytes --]
On Sat, Feb 22 2003, Lars Magne Ingebrigtsen wrote:
[ `mail-source-delete-old-incoming' ]
> I'm not quite sure that such a function is a good idea. The
> Incoming* files are created only by pretest Gnusae, so they should
> only be produced by versions of Gnus that are dangerous, mail-wise
> speaking. Having mechanisms for automatically deleting stuff in
> such a situation might be counterproductive.
The default value of `mail-source-delete-incoming' should still be
`nil' in pretest Gnusae, i.e. no automatically deleting, no change to
the current behavior.
I don't see any harm if Gnus would offer an option to delete old
files. Note that additionally there's a `confirm' argument in
`mail-source-delete-old-incoming' and a variable
`mail-source-delete-old-incoming-confirm'.
I.e. the user has to change `mail-source-delete-incoming' to a
positive integer (default is nil) *and* change
`mail-source-delete-old-incoming-confirm' to nil (default is t) in
order to get automatic deleting without confirmation for every single
incoming file. I suppose this should be enough protection. :-)
I'll add proper documentation, if this patch will be accepted.
--8<---------------cut here---------------start------------->8---
2003-02-24 Reiner Steib <Reiner.Steib@gmx.de>
* mail-source.el (mail-source-delete-incoming): Allow integer value.
(mail-source-delete-old-incoming-confirm): New variable.
(mail-source-delete-old-incoming): Use it. New function.
(mail-source-callback): Call `mail-source-delete-old-incoming' if
`mail-source-delete-incoming' is a nonnegative integer.
--8<---------------cut here---------------end--------------->8---
Here's a revised version[1] of the patch:
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: mail-source.delete-old-incoming.02.patch --]
[-- Type: text/x-patch, Size: 3367 bytes --]
--- mail-source.el.~6.29.~ Mon Feb 17 11:37:23 2003
+++ mail-source.el Mon Feb 24 21:07:41 2003
@@ -263,7 +263,21 @@
:type 'integer)
(defcustom mail-source-delete-incoming nil
- "*If non-nil, delete incoming files after handling."
+ "*If non-nil, delete incoming files after handling.
+If t, delete immediately, if nil, never delete. If a positive number, delete
+files older than number of days."
+ ;; Note: The removing happens in `mail-source-callback', i.e. no old
+ ;; incoming files will be deleted, unless you receive new mail.
+ ;;
+ ;; You may also set this to `nil' and call `mail-source-delete-old-incoming'
+ ;; from a hook or interactively.
+ :group 'mail-source
+ :type '(choice (const :tag "immediately" t)
+ (const :tag "never" nil)
+ (integer :tag "days")))
+
+(defcustom mail-source-delete-old-incoming-confirm t
+ "*If non-nil, ask for for confirmation before deleting old incoming files."
:group 'mail-source
:type 'boolean)
@@ -506,6 +520,34 @@
(setq newname (make-temp-name newprefix)))
newname))))
+(defun mail-source-delete-old-incoming (&optional age confirm)
+ "Remove incoming files older than AGE days.
+If CONFIRM is non-nil, ask for confirmation before removing a file."
+ (interactive "P")
+ (let* ((high2days (/ 65536.0 60 60 24));; convert high bits to days
+ (low2days (/ 1.0 65536.0)) ;; convert low bits to days
+ (diff (if (natnump age) age 30));; fallback, if no valid AGE given
+ currday files)
+ (setq files (directory-files
+ mail-source-directory t
+ (concat mail-source-incoming-file-prefix "*"))
+ currday (* (car (current-time)) high2days)
+ currday (+ currday (* low2days (nth 1 (current-time)))))
+ (while files
+ (let* ((ffile (car files))
+ (bfile (gnus-replace-in-string
+ ffile "\\`.*/\\([^/]+\\)\\'" "\\1"))
+ (filetime (nth 5 (file-attributes ffile)))
+ (fileday (* (car filetime) high2days))
+ (fileday (+ fileday (* low2days (nth 1 filetime)))))
+ (setq files (cdr files))
+ (when (and (> (- currday fileday) diff)
+ (gnus-message 8 "File `%s' is older than %s day(s)"
+ bfile diff)
+ (or (not confirm)
+ (y-or-n-p (concat "Remove file `" bfile "'? "))))
+ (delete-file ffile))))))
+
(defun mail-source-callback (callback info)
"Call CALLBACK on the mail file, and then remove the mail file.
Pass INFO on to CALLBACK."
@@ -519,7 +561,7 @@
(funcall callback mail-source-crash-box info)
(when (file-exists-p mail-source-crash-box)
;; Delete or move the incoming mail out of the way.
- (if mail-source-delete-incoming
+ (if (eq mail-source-delete-incoming t)
(delete-file mail-source-crash-box)
(let ((incoming
(mail-source-make-complex-temp-name
@@ -528,8 +570,13 @@
mail-source-directory))))
(unless (file-exists-p (file-name-directory incoming))
(make-directory (file-name-directory incoming) t))
- (rename-file mail-source-crash-box incoming t)))))))
-
+ (rename-file mail-source-crash-box incoming t)
+ ;; remove old incoming files?
+ (when (natnump mail-source-delete-incoming)
+ (mail-source-delete-old-incoming
+ mail-source-delete-incoming
+ mail-source-delete-old-incoming-confirm))))))))
+
(defun mail-source-movemail (from to)
"Move FROM to TO using movemail."
(if (not (file-writable-p to))
[-- Attachment #3: Type: text/plain, Size: 232 bytes --]
Bye, Reiner.
[1] Simplified the code (thanks to JPW): Use natnump, set most
variables in a let* form instead of using setq.
--
,,,
(o o)
---ooO-(_)-Ooo--- PGP key available via WWW http://rsteib.home.pages.de/
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Limiting number of Incomingxxxx mails
2003-02-24 20:25 ` Reiner Steib
@ 2003-03-03 16:00 ` Ted Zlatanov
2003-03-03 16:56 ` Kai Großjohann
2003-03-04 5:23 ` Sriram Karra
2003-03-03 17:07 ` Kai Großjohann
2003-03-03 17:14 ` Kai Großjohann
2 siblings, 2 replies; 12+ messages in thread
From: Ted Zlatanov @ 2003-03-03 16:00 UTC (permalink / raw)
On Mon, 24 Feb 2003, 4.uce.03.r.s@nurfuerspam.de wrote:
> 2003-02-24 Reiner Steib <Reiner.Steib@gmx.de>
>
> * mail-source.el (mail-source-delete-incoming): Allow
> integer value. (mail-source-delete-old-incoming-confirm):
> New variable. (mail-source-delete-old-incoming): Use it.
> New function. (mail-source-callback): Call
> `mail-source-delete-old-incoming' if
> `mail-source-delete-incoming' is a nonnegative integer.
Was Reiner's patch ever approved or rejected? I didn't see a message
either way.
I think the behavior it implements makes sense, since it's optional
and sensible.
Thanks
Ted
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Limiting number of Incomingxxxx mails
2003-03-03 16:00 ` Ted Zlatanov
@ 2003-03-03 16:56 ` Kai Großjohann
2003-03-04 5:23 ` Sriram Karra
1 sibling, 0 replies; 12+ messages in thread
From: Kai Großjohann @ 2003-03-03 16:56 UTC (permalink / raw)
Ted Zlatanov <tzz@lifelogs.com> writes:
> Was Reiner's patch ever approved or rejected? I didn't see a message
> either way.
>
> I think the behavior it implements makes sense, since it's optional
> and sensible.
I think there was some kind of discussion about it. But I also think
it makes sense to delete old Incoming files.
Do you want me to dig it out from the archives?
--
A preposition is not a good thing to end a sentence with.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Limiting number of Incomingxxxx mails
2003-02-24 20:25 ` Reiner Steib
2003-03-03 16:00 ` Ted Zlatanov
@ 2003-03-03 17:07 ` Kai Großjohann
2003-03-03 18:30 ` Reiner Steib
2003-03-03 17:14 ` Kai Großjohann
2 siblings, 1 reply; 12+ messages in thread
From: Kai Großjohann @ 2003-03-03 17:07 UTC (permalink / raw)
Reiner Steib <4.uce.03.r.s@nurfuerspam.de> writes:
> + (while files
> + (let* ((ffile (car files))
> [...]
> + (setq files (cdr files))
This can be simplified to (let* ((ffile (pop files)) ...) ...).
(Unless you need the old value of files between the let* line and the
setq line -- I didn't look.)
--
A preposition is not a good thing to end a sentence with.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Limiting number of Incomingxxxx mails
2003-02-24 20:25 ` Reiner Steib
2003-03-03 16:00 ` Ted Zlatanov
2003-03-03 17:07 ` Kai Großjohann
@ 2003-03-03 17:14 ` Kai Großjohann
2 siblings, 0 replies; 12+ messages in thread
From: Kai Großjohann @ 2003-03-03 17:14 UTC (permalink / raw)
Reiner Steib <4.uce.03.r.s@nurfuerspam.de> writes:
> I'll add proper documentation, if this patch will be accepted.
Committed. (I hope that was the right thing to do.)
--
A preposition is not a good thing to end a sentence with.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Limiting number of Incomingxxxx mails
2003-03-03 17:07 ` Kai Großjohann
@ 2003-03-03 18:30 ` Reiner Steib
2003-03-03 20:23 ` Kai Großjohann
` (2 more replies)
0 siblings, 3 replies; 12+ messages in thread
From: Reiner Steib @ 2003-03-03 18:30 UTC (permalink / raw)
On Mon, Mar 03 2003, Kai Großjohann wrote:
> Reiner Steib <4.uce.03.r.s@nurfuerspam.de> writes:
>
>> + (while files
>> + (let* ((ffile (car files))
>> [...]
>> + (setq files (cdr files))
>
> This can be simplified to (let* ((ffile (pop files)) ...) ...).
Thanks for the suggestion, Kai. `C-h f pop RET' says that "pop is a
Lisp macro in `cl'." Doesn't Katsumi Yamaoka's [1] argument about
avoiding `cl' apply here?
BTW: I have committed the documentation to `gnus.texi' and some
doc-fixes.
Bye, Reiner.
[1] <news:yotl65r1rzer.fsf@jpl.org>
--
,,,
(o o)
---ooO-(_)-Ooo--- PGP key available via WWW http://rsteib.home.pages.de/
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Limiting number of Incomingxxxx mails
2003-03-03 18:30 ` Reiner Steib
@ 2003-03-03 20:23 ` Kai Großjohann
2003-03-03 21:46 ` Jesper Harder
2003-03-30 2:07 ` Lars Magne Ingebrigtsen
2 siblings, 0 replies; 12+ messages in thread
From: Kai Großjohann @ 2003-03-03 20:23 UTC (permalink / raw)
Reiner Steib <4.uce.03.r.s@nurfuerspam.de> writes:
> Thanks for the suggestion, Kai. `C-h f pop RET' says that "pop is a
> Lisp macro in `cl'." Doesn't Katsumi Yamaoka's [1] argument about
> avoiding `cl' apply here?
It seems that Richard (grudingly) says it's okay to use macros from
CL. That means that CL is not used at run-time, only at compile-time.
--
A preposition is not a good thing to end a sentence with.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Limiting number of Incomingxxxx mails
2003-03-03 18:30 ` Reiner Steib
2003-03-03 20:23 ` Kai Großjohann
@ 2003-03-03 21:46 ` Jesper Harder
2003-03-30 2:07 ` Lars Magne Ingebrigtsen
2 siblings, 0 replies; 12+ messages in thread
From: Jesper Harder @ 2003-03-03 21:46 UTC (permalink / raw)
Reiner Steib <4.uce.03.r.s@nurfuerspam.de> writes:
> `C-h f pop RET' says that "pop is a Lisp macro in `cl'." Doesn't
> Katsumi Yamaoka's [1] argument about avoiding `cl' apply here?
`pop' is documented in the main elisp manual,
<info://elisp/List+Elements>, so it should be okay.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Limiting number of Incomingxxxx mails
2003-03-03 16:00 ` Ted Zlatanov
2003-03-03 16:56 ` Kai Großjohann
@ 2003-03-04 5:23 ` Sriram Karra
1 sibling, 0 replies; 12+ messages in thread
From: Sriram Karra @ 2003-03-04 5:23 UTC (permalink / raw)
On Mon, 03 Mar 2003, Ted Zlatanov wrote:
> On Mon, 24 Feb 2003, 4.uce.03.r.s@nurfuerspam.de wrote:
> > 2003-02-24 Reiner Steib <Reiner.Steib@gmx.de>
> >
> > * mail-source.el (mail-source-delete-incoming): Allow
> > integer value. (mail-source-delete-old-incoming-confirm):
>
> Was Reiner's patch ever approved or rejected? I didn't see a message
> either way.
>
I remember that Lars had some objections. Do not recall exactly what,
though.
-Sriram.
> I think the behavior it implements makes sense, since it's optional
> and sensible.
>
> Thanks
> Ted
>
--
Ignorance is the Mother of Devotion.
-- Robert Burton
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Limiting number of Incomingxxxx mails
2003-03-03 18:30 ` Reiner Steib
2003-03-03 20:23 ` Kai Großjohann
2003-03-03 21:46 ` Jesper Harder
@ 2003-03-30 2:07 ` Lars Magne Ingebrigtsen
2 siblings, 0 replies; 12+ messages in thread
From: Lars Magne Ingebrigtsen @ 2003-03-30 2:07 UTC (permalink / raw)
Reiner Steib <4.uce.03.r.s@nurfuerspam.de> writes:
> Thanks for the suggestion, Kai. `C-h f pop RET' says that "pop is a
> Lisp macro in `cl'." Doesn't Katsumi Yamaoka's [1] argument about
> avoiding `cl' apply here?
Functions from `cl' should be avoided, but macros from `cl' is ok,
since those get expanded at byte-compile time.
--
(domestic pets only, the antidote for overdose, milk.)
larsi@gnus.org * Lars Magne Ingebrigtsen
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2003-03-30 2:07 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <xeq3r8abqkpm.fsf@desh.cisco.com>
[not found] ` <v91y2b0zkh.fsf@marauder.physik.uni-ulm.de>
[not found] ` <u7kc37yaj.fsf@hschmi22.userfqdn.rz-online.de>
[not found] ` <v9ptpurj9a.fsf@marauder.physik.uni-ulm.de>
[not found] ` <ulm0i27hs.fsf_-_@hschmi22.userfqdn.rz-online.de>
2003-02-19 21:12 ` Limiting number of Incomingxxxx mails Reiner Steib
2003-02-22 22:05 ` Lars Magne Ingebrigtsen
2003-02-24 20:25 ` Reiner Steib
2003-03-03 16:00 ` Ted Zlatanov
2003-03-03 16:56 ` Kai Großjohann
2003-03-04 5:23 ` Sriram Karra
2003-03-03 17:07 ` Kai Großjohann
2003-03-03 18:30 ` Reiner Steib
2003-03-03 20:23 ` Kai Großjohann
2003-03-03 21:46 ` Jesper Harder
2003-03-30 2:07 ` Lars Magne Ingebrigtsen
2003-03-03 17:14 ` Kai Großjohann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).