1 ;;; gnus-move.el --- commands for moving Gnus from one server to another
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2002, 2003, 2004,
4 ;; 2005, 2006 Free Software Foundation, Inc.
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
30 (eval-when-compile (require 'cl
))
38 ;;; Moving by comparing Message-ID's.
42 (defun gnus-change-server (from-server to-server
)
43 "Move from FROM-SERVER to TO-SERVER.
44 Update the .newsrc.eld file to reflect the change of nntp server."
46 (list gnus-select-method
(gnus-read-method "Move to method: ")))
49 (let ((gnus-activate-level 0)
51 (nnmail-spool-file nil
))
55 ;; Go through all groups and translate.
56 (let ((newsrc gnus-newsrc-alist
)
59 (while (setq info
(pop newsrc
))
60 (when (gnus-group-native-p (gnus-info-group info
))
61 (gnus-move-group-to-server info from-server to-server
))))))
63 (defun gnus-move-group-to-server (info from-server to-server
)
64 "Move group INFO from FROM-SERVER to TO-SERVER."
65 (let ((group (gnus-info-group info
))
66 to-active hashtb type mark marks
67 to-article to-reads to-marks article
69 (gnus-message 7 "Translating %s..." group
)
70 (when (gnus-request-group group nil to-server
)
71 (setq to-active
(gnus-parse-active)
72 hashtb
(gnus-make-hashtable 1024)
73 act-articles
(gnus-uncompress-range to-active
))
74 ;; Fetch the headers from the `to-server'.
77 (setq type
(gnus-retrieve-headers
80 ;; Convert HEAD headers. I don't care.
81 (when (eq type
'headers
)
82 (nnvirtual-convert-headers))
83 ;; Create a mapping from Message-ID to article number.
84 (set-buffer nntp-server-buffer
)
85 (goto-char (point-min))
87 "^[0-9]+\t[^\t]*\t[^\t]*\t[^\t]*\t\\([^\t]*\\)\t")
89 (buffer-substring (match-beginning 1) (match-end 1))
90 (read (current-buffer))
93 ;; Then we read the headers from the `from-server'.
94 (when (and (gnus-request-group group nil from-server
)
96 (gnus-uncompress-range
98 (setq type
(gnus-retrieve-headers
99 (gnus-uncompress-range
102 ;; Make it easier to map marks.
103 (let ((mark-lists (gnus-info-marks info
))
106 (setq type
(caar mark-lists
)
107 ms
(gnus-uncompress-range (cdr (pop mark-lists
))))
109 (if (setq m
(assq (car ms
) marks
))
110 (setcdr m
(cons type
(cdr m
)))
111 (push (list (car ms
) type
) marks
))
114 (when (eq type
'headers
)
115 (nnvirtual-convert-headers))
116 ;; Go through the headers and map away.
117 (set-buffer nntp-server-buffer
)
118 (goto-char (point-min))
120 "^[0-9]+\t[^\t]*\t[^\t]*\t[^\t]*\t\\([^\t]*\\)\t")
121 (when (setq to-article
123 (buffer-substring (match-beginning 1) (match-end 1))
125 ;; Add this article to the list of read articles.
126 (push to-article to-reads
)
127 ;; See if there are any marks and then add them.
128 (when (setq mark
(assq (read (current-buffer)) marks
))
129 (setq marks
(delq mark marks
))
130 (setcar mark to-article
)
131 (push mark to-marks
))
133 ;; Now we know what the read articles are and what the
134 ;; article marks are. We transform the information
135 ;; into the Gnus info format.
138 (gnus-compress-sequence
139 (and (setq to-reads
(delq nil to-reads
))
142 (cons 1 (1- (car to-active
)))))
143 (gnus-info-set-read info to-reads
)
144 ;; Do the marks. I'm sure y'all understand what's
145 ;; going on down below, so I won't bother with any
146 ;; further comments. <duck>
147 (let ((mlists gnus-article-mark-lists
)
150 (push (list (cdr (pop mlists
))) lists
))
151 (while (setq ms
(pop marks
))
152 (setq article
(pop ms
))
154 (setcdr (setq a
(assq (pop ms
) lists
))
155 (cons article
(cdr a
)))))
158 (setcdr (car a
) (gnus-compress-sequence
159 (and (cdar a
) (sort (cdar a
) '<))))
161 (gnus-info-set-marks info lists t
)))))
162 (gnus-message 7 "Translating %s...done" group
)))
164 (defun gnus-group-move-group-to-server (info from-server to-server
)
165 "Move the group on the current line from FROM-SERVER to TO-SERVER."
167 (let ((info (gnus-get-info (gnus-group-group-name))))
168 (list info
(gnus-find-method-for-group (gnus-info-group info
))
169 (gnus-read-method (format "Move group %s to method: "
170 (gnus-info-group info
))))))
172 (gnus-move-group-to-server info from-server to-server
)
173 ;; We have to update the group info to point use the right server.
174 (gnus-info-set-method info to-server t
)
175 ;; We also have to change the name of the group and stuff.
176 (let* ((group (gnus-info-group info
))
177 (new-name (gnus-group-prefixed-name
178 (gnus-group-real-name group
) to-server
)))
179 (gnus-info-set-group info new-name
)
180 (gnus-sethash new-name
(gnus-gethash group gnus-newsrc-hashtb
)
182 (gnus-sethash group nil gnus-newsrc-hashtb
))))
186 ;;; arch-tag: 503742b8-7d66-4d79-bb31-4a698070707b
187 ;;; gnus-move.el ends here