Changeset 7


Ignore:
Timestamp:
09/25/02 13:58:11 (21 years ago)
Author:
piso
Message:

setTunnel(), connect()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/j/src/org/armedbear/j/mail/ImapSession.java

    r2 r7  
    33 *
    44 * Copyright (C) 2000-2002 Peter Graves
    5  * $Id: ImapSession.java,v 1.1.1.1 2002-09-24 16:10:12 piso Exp $
     5 * $Id: ImapSession.java,v 1.2 2002-09-25 13:58:11 piso Exp $
    66 *
    77 * This program is free software; you can redistribute it and/or
     
    5959    private final int port;
    6060
     61    private String tunnelHost;
     62    private int tunnelPort = -1;
    6163    private ImapMailbox mailbox;
    6264    private int state;
     
    140142    }
    141143
     144    public void setTunnel(String tunnel)
     145    {
     146        if (tunnel != null) {
     147            tunnel = tunnel.trim();
     148            int colon = tunnel.indexOf(':');
     149            if (colon > 0) {
     150                tunnelHost = tunnel.substring(0, colon);
     151                try {
     152                    tunnelPort =
     153                        Integer.parseInt(tunnel.substring(colon+1).trim());
     154                }
     155                catch (NumberFormatException e) {
     156                    Log.error(e);
     157                    tunnelHost = null;
     158                    tunnelPort = -1;
     159                }
     160            }
     161        }
     162        Log.debug("setTunnel host = |" + tunnelHost + "| port = " + tunnelPort);
     163    }
     164
    142165    public synchronized final long getLastErrorMillis()
    143166    {
     
    200223        socket = null;
    201224        errorText = null;
    202         SocketConnection sc =
    203             new SocketConnection(host, port, 30000, 200, null);
    204         Log.debug("connecting to " + host + " on port " + port);
     225        final String h; // Host.
     226        final int p; // Port.
     227        if (tunnelHost != null && tunnelPort > 0) {
     228            h = tunnelHost;
     229            p = tunnelPort;
     230            Log.debug("connect using tunnel h = " + h + " p = " + p);
     231        } else {
     232            h = host;
     233            p = port;
     234        }
     235        SocketConnection sc = new SocketConnection(h, p, 30000, 200, null);
     236        Log.debug("connecting to " + h + " on port " + p);
    205237        socket = sc.connect();
    206238        if (socket == null) {
Note: See TracChangeset for help on using the changeset viewer.