git ssb

0+

cel / ggscrape



Commit f535c2de3e9a5756f6e2adc253c06d4db92981a1

Add fix_message command

Charles Lehner committed on 9/13/2014, 4:29:53 AM
Parent: 85166133f139a08a92d9d4a72ec96b266d9efbd1

Files changed

README.mdchanged
ggscrapechanged
README.mdView
@@ -15,8 +15,12 @@
1515
1616 `ggscrape <group_id> download <dest_dir>`
1717 download emails! :)
1818
19 +`ggscrape fix_message <file>`
20 +remove duplicate headers from a mail file. These sometimes happen if you
21 +manually download an old message from Groups.
22 +
1923 ### Options
2024
2125 `-c, --cookie <cookie>`
2226 Use the given cookie string. Needed to access private groups.
ggscrapeView
@@ -94,8 +94,19 @@
9494 req_fragment "topic/${group_id}/${topic_id}" | sed -n\
9595 's/.*<td class="subject"><a href="[^"]*'$topic_id'\/\([^"]*\)".*/\1/p'
9696 }
9797
98 +fix_message() {
99 + local file="$1"
100 + # Some messages have two duplicate sets of headers, the second set starting
101 + # with some X-Google stuff. Remove the second set of headers if they are
102 + # present.
103 + if sed -n '/^\r$/{ n; /^X-Google-Groups:/q; q 1; }' "$file"; then
104 + debug_print 'Removing duplicate headers'
105 + sed -i~ '/^X-Google-Groups:/,/^\r$/d' "$file" && rm "$file~"
106 + fi
107 +}
108 +
98109 download_message() {
99110 local topic_id="$1"
100111 local msg_id="$2"
101112 debug_print download topic $topic_id message $msg_id
@@ -106,8 +117,9 @@
106117 echo "message ${topic_id}${msg_id} downloading."
107118 temp=$(mktemp)
108119 if req "message/raw?msg=${group_id}/${topic_id}/${msg_id}" -o "$temp"
109120 then
121 + fix_message "$temp"
110122 mv "$temp" "$path"
111123 if [[ -n "$ln_dir" ]]; then
112124 ln "$path" "$ln_dir"
113125 fi
@@ -147,8 +159,9 @@
147159 ggscrape <group_id> test
148160 ggscrape <group_id> topics
149161 ggscrape <group_id> messages <topic_id>
150162 ggscrape <group_id> download <dest_dir>
163 + ggscrape fix_message <file>
151164
152165 Options:
153166 -h, --help Show this screen
154167 --version Show version
@@ -168,8 +181,9 @@
168181 cmd=
169182 topic_id=
170183 topic_begin=
171184 topic_end=
185 +fix_file=
172186
173187 while [[ "$#" -gt 0 ]]; do
174188 case "$1" in
175189 -h|--help) show_help; exit;;
@@ -182,8 +196,9 @@
182196 topics) cmd=topics;;
183197 test) cmd=test;;
184198 messages) cmd=messages; topic_id="$2"; shift;;
185199 download) cmd=download; dest_dir="$2"; shift;;
200 + fix_message) cmd=fix_message; fix_file="$2"; shift;;
186201 *) if [[ -z "$group_id" ]]; then
187202 group_id="$1"
188203 else
189204 unknown_option "$1"
@@ -191,8 +206,17 @@
191206 esac
192207 shift
193208 done
194209
210 +if [[ $cmd==fix_message ]]; then
211 + if [[ -z "$fix_file" ]]; then
212 + show_help
213 + exit 1
214 + fi
215 + fix_message "$fix_file"
216 + exit
217 +fi
218 +
195219 if [[ -z "$group_id" ]]; then
196220 show_help
197221 exit 1
198222 fi

Built with git-ssb-web