[REBOL] Re: E-mail header info strip-off
From: ingo:2b1 at: 10-Jun-2001 9:40
Hi Geza,
this here's a little mbox file parser I started hacking lately,
all you'll have left to do is send the email to your personalized
'import-email ;-)
I hope that helps a little ...
REBOL [
Title: "MBox Handling"
Date: 2001-07-05
Author: "Ingo Hohmann"
Email: [ingo--2b1--de]
File: %mbox.r
Home: http://www.h-o-h.org/
Version: 0.0.1
]
mbox: context [
;file: %/home/ingo/Mail/test.mbox
chars: charset [ #"a" - #"z" #"A" - #"Z" ]
email-chars: charset [ #"a" - #"z" #"A" - #"Z" #"0" - #"9" #"." #"-" #"_" #"+" #"%" ]
digit: charset [ #"0" - #"9"]
mail-index: copy []
index: func [
"creates an index of an mbox file"
mbox-file [file!] "mbox file to parse"
/local idx cnt blk
] [
either block? blk: select mail-index mbox-file [
clear blk
] [
append mail-index mbox-file
append/only mail-index blk: make block! 100
]
save-index: func [][]
idx: make block! 500
cnt: 0
email-start: none
mbox-rule: [some email-rule to end email-end:]
address-rule: [ some email-chars "@" some email-chars ] ; could be _much_ better ...
email-rule: [
email-end: ;(if not none? email-start [print [ ">" copy/part email-start find email-start
newline]])
"From " copy frm address-rule " " 3 chars " " 3 chars " " 2 digit " " 2 digit ":" 2 digit
":" 2 digit " " 4 digit newline ;(?? frm)
(
if not none? email-start [
cnt: cnt + 1
header: import-email header
append/only idx reduce [cnt header/from header/subject header/date index? email-start
index? email-end]
append/only blk reduce [index? email-start index? email-end]
]
email-start: email-end
)
copy header [ thru "^/^/" ]
to "^/From " skip
|
to "^/From " skip
]
probe parse/all read mbox-file mbox-rule
; add the last mail
header: import-email header
append/only idx reduce [cnt header/from header/subject header/date index? email-start
index? email-end]
append/only blk reduce [index? email-start index? email-end]
idx
]
get-mail: func [
file [file!] "mail file"
pos [integer!] "position in the file"
] [
if not find mail-index file [
index file
]
idx: pick select mail-index file pos
;idx: pick idx pos
probe idx
f: open/direct/read file
skip f (idx/1 - 1)
mail: copy/part f (idx/2 - idx/1)
close f
mail
]
]