me@jbrains.ca

Permanent link to this article Fixing Mail.app as it pertains to IMAP and gmail

I am in the process of making gmail my One and Only Mail Database. My first tentative steps showed that gmail filters duplicate emails, which is great, because I have multiple copies of several hundred emails, thanks to POP. Naively, I just started dragging emails from my other Inboxes to my gmail/IMAP/personal mail Inbox and letting the messages synchronize on the gmail server. My goal was to make my other Mail.app accounts empty so I could disable them. This worked well for a while, but for most of today, Mail.app has been telling me this:

Mail has undone actions on some messages
so that you can redo the actions while online.
Mail has saved other messages in mailbox “INBOX”
in “On My Mac” so that you can complete the 
actions while online.  

Additional information: The attempt to read data 
from the server “imap.gmail.com” failed.

I read an article or two and figured I’d overburdened my gmail server and it was scolding me by limiting my access for a while. When about eight hours passed without any change, I knew I had a problem, and that problem was the same email over and over again. Something about embroidery of all things. Each time the message popped up in my “On my Mac” INBOX, I moved it to Trash, then erased deleted messages… nothing worked. Finally, out of desperation, I simply pasted the entire message—you can see it’s quite long—into Google.

Seek and ye shall find.

The advice there, however, didn’t impress me. I might not be a Mail.app developer, but I imagine that if I delete my entire offline cache, I’ll lose all the emails I moved into my gmail/IMAP/personal mail inbox. That would be bad, considering it’s about 10000 messages, many of which matter to me. I thought I should investigate, and fortunately, it wasn’t too hard to figure out what to do.

I went to ~/Library/Mail/IMAP-[myemailaddress]/.OfflineCache and saw about 10000 numbered files. I looked at one of them and saw an email. I figured I could grep to find the offending email, delete it, restart Mail.app, then all would be well. So I did, and so far it is.

To be clear, here is what I did:

$ cd ~/Library/Mail/IMAP-****/.OfflineCache
$ ls
1000        1001        1002        1003        1004        1005        1006        1007        1008        1009
1010        1011        1012        1013        1014        1015        1016        1017        1018        1019
1020        1021        1022        1023        1024        1025        1026        1027        1028        1029
....
$ grep -i embroidery *
[...Matched email 854....]
$ rm 854

That worked great. I hope it helps you, too.

Digg! Discuss

June 11, 2008 03:00 mac, just to be clear

Permanent link to this article Just To Be Clear: Rails and customized model relationships

This is the beginning of a new pseudo-column, titled Just To Be Clear. I intend to write about things I learn after either misunderstanding or finding unclear the existing documentation on the subject. In many cases, I simply don’t read carefully enough, but in general, I try to make as few assumptions as possible, and when that happens, sometimes I find gaps in either the literature or in product documentation. When I find those things, I will share them with you, partly as Google bait for the next poor soul who goes down the same path I do.

The first instalment of Just To Be Clear has to do with customizing model relationships in Rails. As you might know, you can easily express a parent-child relationship by adding foreign keys to the underlying database tables, then the appropriate use of :has_one, :has_many and :belongs_to. (While there’s more to it than that, I hope that’s enough explanation for now.) If you follow the naming conventions, you can get away with just doing this, for example:

class Order < ActiveRecord::Base
  belongs_to :person
end

In your database, you’ll have a table named orders with a foreign key named person_id that refers to the people table’s id column. But the person to whom the order belongs isn’t just any old person, but rather the payer. As a result, I’d rather call this person the payer in my code. Consulting Agile Web Development with Rails, I find I can do this:

class LineItem < ActiveRecord::Base
  belongs_to :paid_order,
             :class_name => "Order",
             :foreign_key => "order_id",
             :conditions => "paid_on is not null" 
end

That seems simple enough, but I want to name my foreign key payer_id, so Rails will probably understand that an order’s payer should correspond to the column payer_id. It does everything else magically, so why not? I tried this:

class Order < ActiveRecord::Base
  belongs_to :payer, :class_name => "Person" 
end

Well, it didn’t work. After 15 minutes of playing around in the Rails console, I noticed that my order objects had both a payer_id and a person_id, so while the payer attribute was correctly assigned, the payer’s id was assigned to person_id, and not payer_id. When I tried to save my order, the database would understandably complain about my trying to save a NULL value in the payer_id column.

So, just to be clear, Rails’ magic does not extend to knowing that the relationship :payer corresponds to a foreign key column payer_id; instead, it assumes the foreign key column name follows the model class name convention, which in this case is person_id. If you want the behavior I want, you need to specify the :foreign_key option.

Digg! Discuss

July 01, 2006 20:20 rails, ruby, testing, just to be clear, article

Older entries at diasparsoftware.com