Skip to content

Instantly share code, notes, and snippets.

@kch
Created August 26, 2010 08:19
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kch/551055 to your computer and use it in GitHub Desktop.
Save kch/551055 to your computer and use it in GitHub Desktop.
Apple Mail plugin that fixes your sender for mailing lists
Contents/MacOS/main

WTF

This is an Apple Mail plugin that'll select the From: address of your choosing (see step 2) when:

  • you're replying to a message from a mailing list (that has a List-Id header)

  • One of the recipients is a known mailing list address from your configuration. (Again, see step 2.)

GETTING STARTED

  1. Be sure to have the Nu framework on your system: http://github.com/timburks/nu

  2. Compile main:

     cd Contents/MacOS/
     clang main.m -o main -bundle -framework Foundation -framework Nu
    
  3. Edit Contents/Resources/bundle.nu with your own info.

  4. Put this folder (the one containing this README.md file) in ~/Library/Mail/Bundles/ and make sure it ends in a .mailbundle extension. E.g. the final path should look something like ~/Library/Mail/Bundles/MailingListFromFix.mailbundle

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; SET YOUR INFO HERE; TOO LAZY TO MAKE A PREF PANE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Put here the sender you which to use for mailing lists exactly as it appears in the From: popup UI.
(set $my_list_sender "Your Full Name <lists@example.com>")
;; Put here the email addresses for every mailing list that you send email to.
(set $list_addresses (array "macruby-devel@lists.macosforge.org" "programming-nu@googlegroups.com"))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(class ComposeBackEnd
(- (void) updateSenderToUserListSenderAndNotifyHeadersEditor is
(self setSender:$my_list_sender)
(((self delegate) headersEditor) mailAccountsDidChange)))
(class MailDocumentEditor
(- (void) withMailingListAddress_finishLoadingEditor is
(self withMailingListAddress_finishLoadingEditor)
(if (((self settings) "Messages") find:(do (message) ((message headers) headersForKey:"list-id")))
((self backEnd) updateSenderToUserListSenderAndNotifyHeadersEditor))))
(class HeadersEditor
(- (void) withMailingListAddress_recipientsDidChange: (id) sender is
(self withMailingListAddress_recipientsDidChange:sender)
(let (backEnd (@documentEditor backEnd))
(let (recipients ((backEnd allRecipients) componentsJoinedByString:"\n"))
(if ($list_addresses find:(do (addr) (!= (recipients rangeOfString:"<#{addr}>") '(-1 0)) ))
(backEnd updateSenderToUserListSenderAndNotifyHeadersEditor))))))
(MailDocumentEditor exchangeInstanceMethod:"finishLoadingEditor" withMethod:"withMailingListAddress_finishLoadingEditor")
(HeadersEditor exchangeInstanceMethod:"recipientsDidChange:" withMethod:"withMailingListAddress_recipientsDidChange:")
; (load "console")
; (set $console ((NuConsoleWindowController alloc) init))
; ($console toggleConsole:nil)
(NSLog "Loaded plugin SomethingSomethingMailingListsWhatever")
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>main</string>
<key>CFBundleIdentifier</key>
<string>com.caiochassot.mailingListMailPlugin</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>NSPrincipalClass</key>
<string>JustToTrickMailIntoRunningOurInitializeMethodSinceWeCantHaveAMainBecauseItsABundle</string>
<key>SupportedPluginCompatibilityUUIDs</key>
<array>
<string>225E0A48-2CDB-44A6-8D99-A9BB8AF6BA04</string>
<string>B3F3FC72-315D-4323-BE85-7AB76090224D</string>
<string>2610F061-32C6-4C6B-B90A-7A3102F9B9C8</string>
<string>99BB3782-6C16-4C6F-B910-25ED1C1CB38B</string>
<string>2F0CF6F9-35BA-4812-9CB2-155C0FDB9B0F</string>
<string>0CB5F2A0-A173-4809-86E3-9317261F1745</string>
<string>B842F7D0-4D81-4DDF-A672-129CA5B32D57</string>
<string>E71BD599-351A-42C5-9B63-EA5C47F7CE8E</string>
<string>BDD81F4D-6881-4A8D-94A7-E67410089EEB</string>
<string>857A142A-AB81-4D99-BECC-D1B55A86D94E</string>
</array>
</dict>
</plist>
// Hi. Compile me with:
// clang main.m -o main -bundle -framework Foundation -framework Nu
#import <Nu/Nu.h>
@interface JustToTrickMailIntoRunningOurInitializeMethodSinceWeCantHaveAMainBecauseItsABundle : NSObject {}
@end
@implementation JustToTrickMailIntoRunningOurInitializeMethodSinceWeCantHaveAMainBecauseItsABundle
+ (void) initialize
{
static int initialized = 0;
if (initialized) return;
initialized = 1;
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSBundle *bundle = [NSBundle bundleForClass:self];
NSString *main_path = [bundle pathForResource:@"bundle" ofType:@"nu"];
if (main_path) {
NSString *nu_main = [NSString stringWithContentsOfFile:main_path encoding:NSUTF8StringEncoding error:nil];
if (nu_main) {
id parser = [Nu parser];
id script = [parser parse:nu_main];
[parser eval:script];
NSLog(@"loaded Nu, yay.");
}
}
[pool release];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment