/[classpath]/inetlib/source/gnu/inet/imap/IMAPConnection.java
ViewVC logotype

Diff of /inetlib/source/gnu/inet/imap/IMAPConnection.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.29 by dog, Thu Aug 25 12:32:03 2005 UTC revision 1.30 by dog, Sun Sep 4 13:47:30 2005 UTC
# Line 1  Line 1 
1  /*  /*
2   * IMAPConnection.java   * IMAPConnection.java
3   * Copyright (C) 2003,2004 The Free Software Foundation   * Copyright (C) 2003,2004,2005 The Free Software Foundation
4   *   *
5   * This file is part of GNU inetlib, a library.   * This file is part of GNU inetlib, a library.
6   *   *
# Line 1233  public class IMAPConnection Line 1233  public class IMAPConnection
1233    public boolean append(String mailbox, String[] flags, byte[] content)    public boolean append(String mailbox, String[] flags, byte[] content)
1234      throws IOException      throws IOException
1235    {    {
1236        return append(mailbox, flags, content, null);
1237      }
1238      
1239      /**
1240       * Append a message to the specified mailbox.
1241       * This method returns an OutputStream to which the message should be
1242       * written and then closed.
1243       * @param mailbox the mailbox name
1244       * @param flags optional list of flags to specify for the message
1245       * @param content the message body(including headers)
1246       * @param uidplus handler for any APPENDUID information in the response
1247       * @return true if successful, false if error in flags/text
1248       */
1249      public boolean append(String mailbox, String[] flags, byte[] content,
1250                            UIDPlusHandler uidplus)
1251        throws IOException
1252      {
1253      String tag = newTag();      String tag = newTag();
1254      StringBuffer buffer = new StringBuffer(APPEND)      StringBuffer buffer = new StringBuffer(APPEND)
1255        .append(' ')        .append(' ')
# Line 1273  public class IMAPConnection Line 1290  public class IMAPConnection
1290              processAlerts(response);              processAlerts(response);
1291              if (id == OK)              if (id == OK)
1292                {                {
1293                    if (uidplus != null)
1294                      {
1295                        processUIDPlus(response.getResponseCode(), uidplus);
1296                      }
1297                  return true;                  return true;
1298                }                }
1299              else if (id == NO)              else if (id == NO)
# Line 1294  public class IMAPConnection Line 1315  public class IMAPConnection
1315            }            }
1316        }        }
1317    }    }
1318    
1319      void processUIDPlus(List code, UIDPlusHandler uidplus)
1320      {
1321        int len = code.size();
1322        for (int i = 0; i < len; i++)
1323          {
1324            Object item = code.get(i);
1325            if (item instanceof String)
1326              {
1327                if ("APPENDUID".equals(item) && i < len - 2)
1328                  {
1329                    long uidvalidity = Long.parseLong((String) code.get(i + 1));
1330                    long uid = Long.parseLong((String) code.get(i + 2));
1331                    uidplus.appenduid(uidvalidity, uid);
1332                  }
1333                else if ("COPYUID".equals(item) && i < len - 3)
1334                  {
1335                    long uidvalidity =
1336                      Long.parseLong((String) code.get(i + 1));
1337                    MessageSetTokenizer oldUIDs =
1338                      new MessageSetTokenizer((String) code.get(i + 2));
1339                    MessageSetTokenizer newUIDs =
1340                      new MessageSetTokenizer((String) code.get(i + 3));
1341                    while (oldUIDs.hasNext())
1342                      {
1343                        long oldUID = ((Long) oldUIDs.next()).longValue();
1344                        long newUID = ((Long) newUIDs.next()).longValue();
1345                        uidplus.copyuid(uidvalidity, oldUID, newUID);
1346                      }
1347                  }
1348              }
1349            else
1350              {
1351                processUIDPlus((List) item, uidplus);
1352              }
1353          }
1354      }
1355        
1356    /**    /**
1357     * Request a checkpoint of the currently selected mailbox.     * Request a checkpoint of the currently selected mailbox.
# Line 1803  public class IMAPConnection Line 1861  public class IMAPConnection
1861    public boolean copy(int[] messages, String mailbox)    public boolean copy(int[] messages, String mailbox)
1862      throws IOException      throws IOException
1863    {    {
1864        return copy(messages, mailbox, null);
1865      }
1866      
1867      /**
1868       * Copies the specified messages to the end of the destination mailbox.
1869       * @param messages the message numbers
1870       * @param mailbox the destination mailbox
1871       * @param uidplus UIDPLUS callback for COPYUID information
1872       */
1873      public boolean copy(int[] messages, String mailbox, UIDPlusHandler uidplus)
1874        throws IOException
1875      {
1876      if (messages == null || messages.length < 1)      if (messages == null || messages.length < 1)
1877        {        {
1878          return true;          return true;
# Line 1818  public class IMAPConnection Line 1888  public class IMAPConnection
1888          buffer.append(messages[i]);          buffer.append(messages[i]);
1889        }        }
1890      buffer.append(' ').append(quote(UTF7imap.encode(mailbox)));      buffer.append(' ').append(quote(UTF7imap.encode(mailbox)));
1891      return invokeSimpleCommand(buffer.toString());      String tag = newTag();
1892        sendCommand(tag, buffer.toString());
1893        while (true)
1894          {
1895            IMAPResponse response = readResponse();
1896            String id = response.getID();
1897            if (tag.equals(response.getTag()))
1898              {
1899                processAlerts(response);
1900                if (id == OK)
1901                  {
1902                    if (uidplus != null)
1903                      {
1904                        processUIDPlus(response.getResponseCode(), uidplus);
1905                      }
1906                    return true;
1907                  }
1908                else if (id == NO)
1909                  {
1910                    return false;
1911                  }
1912                else
1913                  {
1914                    throw new IMAPException(id, response.getText());
1915                  }
1916              }
1917            else if (response.isUntagged())
1918              {
1919                asyncResponses.add(response);
1920              }
1921            else
1922              {
1923                throw new IMAPException(id, response.getText());
1924              }
1925          }
1926    }    }
1927    
1928    /**    /**
# Line 2331  public class IMAPConnection Line 2435  public class IMAPConnection
2435                }                }
2436            }            }
2437          else          else
2438              {
2439                throw new IMAPException(id, response.getText());
2440              }
2441          }
2442      }
2443    
2444      /**
2445       * Expunges the specified range of messages.
2446       * See RFC 2359 for details.
2447       * @param start the UID of the first message to expunge
2448       * @param end the UID of the last message to expunge
2449       */
2450      public int[] uidExpunge(long start, long end)
2451        throws IOException
2452      {
2453        String tag = newTag();
2454        StringBuffer cmd = new StringBuffer(UID_EXPUNGE);
2455        cmd.append(' ');
2456        cmd.append(start);
2457        cmd.append(':');
2458        cmd.append(end);
2459        sendCommand(tag, cmd.toString());
2460        List numbers = new ArrayList();
2461        while (true)
2462          {
2463            IMAPResponse response = readResponse();
2464            String id = response.getID();
2465            if (response.isUntagged())
2466              {
2467                if (id == EXPUNGE)
2468                  {
2469                    numbers.add(new Integer(response.getCount()));
2470                  }
2471                else
2472                  {
2473                    asyncResponses.add(response);
2474                  }
2475              }
2476            else if (tag.equals(response.getTag()))
2477              {
2478                processAlerts(response);
2479                if (id == OK)
2480                  {
2481                    int len = numbers.size();
2482                    int[] mn = new int[len];
2483                    for (int i = 0; i < len; i++)
2484                      {
2485                        mn[i] = ((Integer) numbers.get(i)).intValue();
2486                      }
2487                    return mn;
2488                  }
2489                else
2490                  {
2491                    throw new IMAPException(id, response.getText());
2492                  }
2493              }
2494            else
2495            {            {
2496              throw new IMAPException(id, response.getText());              throw new IMAPException(id, response.getText());
2497            }            }

Legend:
Removed from v.1.29  
changed lines
  Added in v.1.30

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26