1 ;;; gnus-move.el --- commands for moving Gnus from one server to another
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000
3 ;; Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
29 (eval-when-compile (require 'cl
))
37 ;;; Moving by comparing Message-ID's.
41 (defun gnus-change-server (from-server to-server
)
42 "Move from FROM-SERVER to TO-SERVER.
43 Update the .newsrc.eld file to reflect the change of nntp server."
45 (list gnus-select-method
(gnus-read-method "Move to method: ")))
48 (let ((gnus-activate-level 0)
50 (nnmail-spool-file nil
))
54 ;; Go through all groups and translate.
55 (let ((newsrc gnus-newsrc-alist
)
58 (while (setq info
(pop newsrc
))
59 (when (gnus-group-native-p (gnus-info-group info
))
60 (gnus-move-group-to-server info from-server to-server
))))))
62 (defun gnus-move-group-to-server (info from-server to-server
)
63 "Move group INFO from FROM-SERVER to TO-SERVER."
64 (let ((group (gnus-info-group info
))
65 to-active hashtb type mark marks
66 to-article to-reads to-marks article
68 (gnus-message 7 "Translating %s..." group
)
69 (when (gnus-request-group group nil to-server
)
70 (setq to-active
(gnus-parse-active)
71 hashtb
(gnus-make-hashtable 1024)
72 act-articles
(gnus-uncompress-range to-active
))
73 ;; Fetch the headers from the `to-server'.
76 (setq type
(gnus-retrieve-headers
79 ;; Convert HEAD headers. I don't care.
80 (when (eq type
'headers
)
81 (nnvirtual-convert-headers))
82 ;; Create a mapping from Message-ID to article number.
83 (set-buffer nntp-server-buffer
)
84 (goto-char (point-min))
86 "^[0-9]+\t[^\t]*\t[^\t]*\t[^\t]*\t\\([^\t]*\\)\t")
88 (buffer-substring (match-beginning 1) (match-end 1))
89 (read (current-buffer))
92 ;; Then we read the headers from the `from-server'.
93 (when (and (gnus-request-group group nil from-server
)
95 (gnus-uncompress-range
97 (setq type
(gnus-retrieve-headers
98 (gnus-uncompress-range
101 ;; Make it easier to map marks.
102 (let ((mark-lists (gnus-info-marks info
))
105 (setq type
(caar mark-lists
)
106 ms
(gnus-uncompress-range (cdr (pop mark-lists
))))
108 (if (setq m
(assq (car ms
) marks
))
109 (setcdr m
(cons type
(cdr m
)))
110 (push (list (car ms
) type
) marks
))
113 (when (eq type
'headers
)
114 (nnvirtual-convert-headers))
115 ;; Go through the headers and map away.
116 (set-buffer nntp-server-buffer
)
117 (goto-char (point-min))
119 "^[0-9]+\t[^\t]*\t[^\t]*\t[^\t]*\t\\([^\t]*\\)\t")
120 (when (setq to-article
122 (buffer-substring (match-beginning 1) (match-end 1))
124 ;; Add this article to the list of read articles.
125 (push to-article to-reads
)
126 ;; See if there are any marks and then add them.
127 (when (setq mark
(assq (read (current-buffer)) marks
))
128 (setq marks
(delq mark marks
))
129 (setcar mark to-article
)
130 (push mark to-marks
))
132 ;; Now we know what the read articles are and what the
133 ;; article marks are. We transform the information
134 ;; into the Gnus info format.
137 (gnus-compress-sequence
138 (and (setq to-reads
(delq nil to-reads
))
141 (cons 1 (1- (car to-active
)))))
142 (gnus-info-set-read info to-reads
)
143 ;; Do the marks. I'm sure y'all understand what's
144 ;; going on down below, so I won't bother with any
145 ;; further comments. <duck>
146 (let ((mlists gnus-article-mark-lists
)
149 (push (list (cdr (pop mlists
))) lists
))
150 (while (setq ms
(pop marks
))
151 (setq article
(pop ms
))
153 (setcdr (setq a
(assq (pop ms
) lists
))
154 (cons article
(cdr a
)))))
157 (setcdr (car a
) (gnus-compress-sequence
158 (and (cdar a
) (sort (cdar a
) '<))))
160 (gnus-info-set-marks info lists t
)))))
161 (gnus-message 7 "Translating %s...done" group
)))
163 (defun gnus-group-move-group-to-server (info from-server to-server
)
164 "Move the group on the current line from FROM-SERVER to TO-SERVER."
166 (let ((info (gnus-get-info (gnus-group-group-name))))
167 (list info
(gnus-find-method-for-group (gnus-info-group info
))
168 (gnus-read-method (format "Move group %s to method: "
169 (gnus-info-group info
))))))
171 (gnus-move-group-to-server info from-server to-server
)
172 ;; We have to update the group info to point use the right server.
173 (gnus-info-set-method info to-server t
)
174 ;; We also have to change the name of the group and stuff.
175 (let* ((group (gnus-info-group info
))
176 (new-name (gnus-group-prefixed-name
177 (gnus-group-real-name group
) to-server
)))
178 (gnus-info-set-group info new-name
)
179 (gnus-sethash new-name
(gnus-gethash group gnus-newsrc-hashtb
)
181 (gnus-sethash group nil gnus-newsrc-hashtb
))))
185 ;;; gnus-move.el ends here