• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How go get mailbox path top down instead of bottom up?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How go get mailbox path top down instead of bottom up?


  • Subject: Re: How go get mailbox path top down instead of bottom up?
  • From: Axel Luttgens <email@hidden>
  • Date: Wed, 21 Dec 2011 14:22:35 +0100

Le 21 déc. 2011 à 05:41, Robert Nicholson a écrit :

> Are there any examples of traversing the Mailboxes top down instead of bottom up?
>
> ie.
>
> you have mailboxes at any level 2011.mbox and you want to create a 2012.mbox under the same parent folder.

Hello Robert,

I'll assume you are considering local mailboxes, the ones appearing under the "On my mac" heading.
Those mailboxes are available thru Mail's "mailboxes" property.

Instead of traversing the mailbox hierarchy, I would be tempted to let Mail do the hard work:

	mailboxes whose name is "2011"

Now comes a small problem (glitch?) with Mail: getting the name of a mailbox provides its "short name", while the creation of a local mailbox requires a "full name", a path-like name.
Hence the helper handler "MboxFullName()"; it is defined as a recursive function, since it shouldn't be called too many times, nor encounter terribly deep hierarchies.


	on MboxFullName(Mbox)
		tell application "Mail"
			if name of container of Mbox is missing value then return name of Mbox
			return my MboxFullName(container of Mbox) & "/" & name of Mbox
		end tell
	end MboxFullName

	on CreatePeerMBoxes(MBoxName, NewMBoxName)
		local Mbox, Ctnr
		tell application "Mail"
			repeat with Mbox in (get mailboxes whose name is MBoxName)
				set Ctnr to container of Mbox
				if not (exists mailbox NewMBoxName of Ctnr) then
					make new mailbox with properties {name:my MboxFullName(Ctnr) & "/" & NewMBoxName}
				end if
			end repeat
		end tell
	end CreateMBoxesAtSameLevel

	CreatePeerMBoxes("2011", "2012")


Probably better to test beforehand, with following statement:

	log (my MboxFullName(Ctnr) & "/" & NewMBoxName)

instead of "make new mailbox with...". ;-)


HTH,
Axel



 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: How go get mailbox path top down instead of bottom up?
      • From: Robert Nicholson <email@hidden>
    • Re: How go get mailbox path top down instead of bottom up?
      • From: Robert Nicholson <email@hidden>
References: 
 >How go get mailbox path top down instead of bottom up? (From: Robert Nicholson <email@hidden>)

  • Prev by Date: Re: How go get mailbox path top down instead of bottom up?
  • Next by Date: Satimage OSAX and Console messages.
  • Previous by thread: Re: How go get mailbox path top down instead of bottom up?
  • Next by thread: Re: How go get mailbox path top down instead of bottom up?
  • Index(es):
    • Date
    • Thread