1 ;;; gnus-move.el --- commands for moving Gnus from one server to another
2 ;; Copyright (C) 1996 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
34 ;;; Moving by comparing Message-ID's.
38 (defun gnus-change-server (from-server to-server)
39 "Move from FROM-SERVER to TO-SERVER.
40 Update the .newsrc.eld file to reflect the change of nntp server."
42 (list gnus-select-method (gnus-read-method "Move to method: ")))
45 (let ((gnus-activate-level 0)
46 (nnmail-spool-file nil))
50 ;; Go through all groups and translate.
51 (let ((newsrc gnus-newsrc-alist)
54 (while (setq info (pop newsrc))
55 (when (gnus-group-native-p (gnus-info-group info))
56 (gnus-move-group-to-server info from-server to-server))))))
58 (defun gnus-move-group-to-server (info from-server to-server)
59 "Move group INFO from FROM-SERVER to TO-SERVER."
60 (let ((group (gnus-info-group info))
61 to-active hashtb type mark marks
62 to-article to-reads to-marks article)
63 (gnus-message 7 "Translating %s..." group)
64 (when (gnus-request-group group nil to-server)
65 (setq to-active (gnus-parse-active)
66 hashtb (make-vector 1023 0))
67 ;; Fetch the headers from the `to-server'.
68 (when (setq type (gnus-retrieve-headers
69 (car to-active) (cdr to-active)))
70 ;; Convert HEAD headers. I don't care.
71 (when (eq type 'headers)
72 (nnvirtual-convert-headers))
73 ;; Create a mapping from Message-ID to article number.
74 (set-buffer nntp-server-buffer)
75 (goto-char (point-min))
77 "^[0-9]+\t[^\t]*\t[^\t]*\t[^\t]*\t\\([^\t]*\\)\t"
80 (buffer-substring (match-beginning 1) (match-end 1))
81 (read (current-buffer))
84 ;; Then we read the headers from the `from-server'.
85 (when (and (gnus-request-group group nil from-server)
87 (setq type (gnus-retrieve-headers
88 (car (gnus-active group))
89 (cdr (gnus-active group)))))
90 ;; Make it easier to map marks.
91 (let ((mark-lists (gnus-info-marks info))
94 (setq type (caar mark-lists)
95 ms (gnus-uncompress-range (cdr (pop mark-lists))))
97 (if (setq m (assq (car ms) marks))
98 (setcdr m (cons type (cdr m)))
99 (push (list (car ms) type) marks))
102 (when (eq type 'headers)
103 (nnvirtual-convert-headers))
104 ;; Go through the headers and map away.
105 (set-buffer nntp-server-buffer)
106 (goto-char (point-min))
108 "^[0-9]+\t[^\t]*\t[^\t]*\t[^\t]*\t\\([^\t]*\\)\t"
112 (buffer-substring (match-beginning 1) (match-end 1))
114 ;; Add this article to the list of read articles.
115 (push to-article to-reads)
116 ;; See if there are any marks and then add them.
117 (when (setq mark (assq (read (current-buffer)) marks))
118 (setq marks (delq mark marks))
119 (setcar mark to-article)
120 (push mark to-marks))
122 ;; Now we know what the read articles are and what the
123 ;; article marks are. We transform the information
124 ;; into the Gnus info format.
127 (gnus-compress-sequence (sort to-reads '<) t)
128 (cons 1 (1- (car to-active)))))
129 (gnus-info-set-read info to-reads)
130 ;; Do the marks. I'm sure y'all understand what's
131 ;; going on down below, so I won't bother with any
132 ;; further comments. <duck>
133 (let ((mlists gnus-article-mark-lists)
136 (push (list (cdr (pop mlists))) lists))
137 (while (setq ms (pop marks))
138 (setq article (pop ms))
140 (setcdr (setq a (assq (pop ms) lists))
141 (cons article (cdr a)))))
144 (setcdr (car a) (gnus-compress-sequence (sort (cdar a) '<)))
146 (gnus-info-set-marks info lists)))))
147 (gnus-message 7 "Translating %s...done" group)))
149 (defun gnus-group-move-group-to-server (info from-server to-server)
150 "Move the group on the current line from FROM-SERVER to TO-SERVER."
152 (let ((info (gnus-get-info (gnus-group-group-name))))
153 (list info (gnus-find-method-for-group (gnus-info-group info))
154 (gnus-read-method (format "Move group %s to method: "
155 (gnus-info-group info))))))
157 (gnus-move-group-to-server info from-server to-server)
158 ;; We have to update the group info to point use the right server.
159 (gnus-info-set-method info to-server t)
160 ;; We also have to change the name of the group and stuff.
161 (let* ((group (gnus-info-group info))
162 (new-name (gnus-group-prefixed-name
163 (gnus-group-real-name group) to-server)))
164 (gnus-info-set-group info new-name)
165 (gnus-sethash new-name (gnus-gethash group gnus-newsrc-hashtb)
167 (gnus-sethash group nil gnus-newsrc-hashtb))))
171 ;;; gnus-move.el ends here