<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -19,6 +19,8 @@ Version 1.1.0 (git)
   * The --fast-scan option has been removed.
   * Fixed encoding issues when creating mailboxes and getting mailbox lists.
   * Fixed incorrect case-sensitive treatment of the 'INBOX' folder name.
+  * Fixed a bug in which Larch would try to copy flags that weren't supported on
+    the destination server.
 
 Version 1.0.2 (2009-08-05)
   * Fixed a bug that caused Larch to try to set the read-only \Recent flag on</diff>
      <filename>HISTORY</filename>
    </modified>
    <modified>
      <diff>@@ -2,7 +2,7 @@ module Larch; class IMAP
 
 # Represents an IMAP mailbox.
 class Mailbox
-  attr_reader :attr, :db_mailbox, :delim, :imap, :name, :state, :subscribed
+  attr_reader :attr, :db_mailbox, :delim, :flags, :imap, :name, :perm_flags, :state, :subscribed
 
   # Maximum number of message headers to fetch with a single IMAP command.
   FETCH_BLOCK_SIZE = 1024
@@ -20,6 +20,8 @@ class Mailbox
     @name       = name
     @name_utf7  = Net::IMAP.encode_utf7(@name)
     @delim      = delim
+    @flags      = []
+    @perm_flags = []
     @subscribed = subscribed
     @attr       = attr.flatten
 
@@ -74,10 +76,18 @@ class Mailbox
 
       debug &quot;appending message: #{message.guid}&quot;
 
-      # The \Recent flag is read-only, so we shouldn't try to set it at the
-      # destination.
       flags = message.flags.dup
-      flags.delete(:Recent)
+
+      # Don't set any flags that aren't supported on the destination mailbox.
+      flags.delete_if do |flag|
+        # The \Recent flag is read-only, so we shouldn't try to set it.
+        return true if flag == :Recent
+
+        unless @flags.include?(flag) || @perm_flags.include?(:*) || @perm_flags.include?(flag)
+          debug &quot;flag not supported on destination: #{flag}&quot;
+          true
+        end
+      end
 
       @imap.conn.append(@name_utf7, message.rfc822, flags, message.internaldate) unless @imap.options[:dry_run]
     end
@@ -381,6 +391,7 @@ class Mailbox
 
         debug &quot;examining mailbox&quot;
         @imap.conn.examine(@name_utf7)
+        refresh_flags
 
         @mutex.synchronize { @state = :examined }
 
@@ -408,6 +419,7 @@ class Mailbox
 
         debug &quot;selecting mailbox&quot;
         @imap.conn.select(@name_utf7)
+        refresh_flags
 
         @mutex.synchronize { @state = :selected }
 
@@ -503,6 +515,15 @@ class Mailbox
     return str =~ REGEX_MESSAGE_ID ? $1 : nil
   end
 
+  # Refreshes the list of valid flags for this mailbox.
+  def refresh_flags
+    return unless @imap.conn.responses.has_key?('FLAGS') &amp;&amp;
+        @imap.conn.responses.has_key?('PERMANENTFLAGS')
+
+    @flags      = Array(@imap.conn.responses['FLAGS'].first)
+    @perm_flags = Array(@imap.conn.responses['PERMANENTFLAGS'].first)
+  end
+
 end
 
 end; end</diff>
      <filename>lib/larch/imap/mailbox.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>a7e1c9ccb61e4930c469526467eda67eb2b03ddd</id>
    </parent>
  </parents>
  <author>
    <name>Ryan Grove</name>
    <email>ryan@wonko.com</email>
  </author>
  <url>http://github.com/rgrove/larch/commit/9d2e2835b3eaae4ff24820c636e768fdcf403c09</url>
  <id>9d2e2835b3eaae4ff24820c636e768fdcf403c09</id>
  <committed-date>2009-11-08T15:52:22-08:00</committed-date>
  <authored-date>2009-11-08T15:52:22-08:00</authored-date>
  <message>Don't try to set flags that aren't supported on the destination server. Closes #13</message>
  <tree>f974aabdf0aa7b86d710f3c737db4192bbf0557a</tree>
  <committer>
    <name>Ryan Grove</name>
    <email>ryan@wonko.com</email>
  </committer>
</commit>
