/* ZZMbox.java * * Copyright (c) 2000, Ted Nelson, Tuomas Lukka and Vesa Parkkinen * * You may use and distribute under the terms of either the GNU Lesser * General Public License, either version 2 of the license or, * at your choice, any later version. Alternatively, you may use and * distribute under the terms of the XPL. * * See the LICENSE.lgpl and LICENSE.xpl files for the specific terms of * the licenses. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the README * file for more details. * */ /* * Written by Tuomas Lukka and Vesa Parkkinen */ package org.gzigzag.module; import org.gzigzag.*; import java.util.*; import java.text.*; // DateFormat import java.io.*; import java.awt.*; import gnu.regexp.*; /** A mailbox file reader. *

* AAAAAAAARGGGGGGGGGGHHHHH!!!!!! How to do 8-bit cleanliness and * internationalization correctly? It's still just a stream of bytes * that we have underneath. Should probably use encoding when converting * bytescroll stuff to strings. Gnnnh... *

* The way to test this is: *

*

* TODO:

*/ public class ZZMbox { public static final String rcsid = "$Id: ZZMbox.java,v 1.1 2002/10/07 12:37:34 tuukkah Exp $"; public static boolean dbg = false; static final void p(String s) { if(dbg) ZZLogger.log(s); } static final void pa(String s) { ZZLogger.log(s); } static ZZCell byDate; static ZZCell bySender; static ZZCell bySubject; static ZZCell byId; static Hashtable hash = new Hashtable(); static public ZZModule module = new ZZModule() { public void action(String id, ZZCell code, ZZCell target, ZZView v, ZZView cv, String key, Point pt, ZZScene xi) { try { ZZCell viewCell = v.getViewcell(); ZZCell viewCursor = ZZCursorReal.get(viewCell); p("ZZMbox ACTION!"); if(id.equals("CREATEFLOBWINDOW")) { // paths are: // // Date: // handle -> Date: (d.handle) // headcell(d.clone, -1) // d.order +1 // // From: same // Subject: same String[] fields = new String[] { "Subject", "From", "Date", "ARDate" }; ZZCell mli = viewCell.getHomeCell().N("d.2", 1); mli.setText("MailflobDims"); ZZCell dlc = mli.N("d.1", 1); ZZCell odlc = dlc; ZZCell[] flobdims = new ZZCell[fields.length]; for(int i=0; i= scr.curEnd()) { i = (int)(scr.curEnd()-offs-1); } s = scr.getString(offs, i); ind = s.indexOf('\n'); } if(ind<0 && offs != scr.curEnd()) { p("Problem: no newline at end!"); //return null; s = scr.getString(offs, (int)scr.curEnd()); offs = scr.curEnd(); return s; } s = s.substring(0, ind); // nl not included offs += ind+1; return s; } long hlstart; long hlend; String getHdrLine() throws Exception { //p("Gethdrline"); hlstart = offs; long o0 = offs; String s = getLine(); if(s.equals("")) { // Start of body return null; } if(startws==null) startws = new RE("^\\s"); if(startws.getMatch(s, 0, RE.REG_ANCHORINDEX)!=null) { throw new ZZError("ARGH! Invalid header"); } while(true) { o0 = offs; String extra = getLine(); if(startws.getMatch(extra, 0, RE.REG_ANCHORINDEX) == null) break; s += extra; p("Hdrline reloop "+extra); } //p("Hdrline end "+s); offs = o0; hlend = offs-2; return s; } boolean was_empty = false; String getBodyLine() throws Exception { p("Getbody"); long o0 = offs; String s = getLine(); if( s == null ) return null; if(startfrom==null) startfrom = new RE("^From (.+) (... ... .. ..:..:.. ....)(.*)"); if(startfrom.getMatch(s, 0, RE.REG_ANCHORINDEX)!=null && was_empty) { p("GETBODY: END BODY " + s); offs = o0; return null; } p("GETBODYRET: "+s); if ( s.equals("")){ was_empty = true; } else { was_empty = false; } return s; } Span sp(long offs, REMatch m, int i) { return sp(offs, m.getSubStartIndex(i), m.getSubEndIndex(i)); } Span sp(long offs, long i1, long i2) { return sp(i1+offs, i2+offs); } Span sp(long i1, long i2) { return Span.create(Address.scrollOffs(scr, i1), Address.scrollOffs(scr, i2)); } void dohoriz(ZZCell c, long o, REMatch m, int n) { for(int i=1; i